swaggest / openapi-go

OpenAPI structures for Go
https://pkg.go.dev/github.com/swaggest/openapi-go/openapi3
MIT License
248 stars 23 forks source link

pathItem has a wrong key when using regexes. #49

Closed Fifi31 closed 1 year ago

Fifi31 commented 1 year ago

Hi, Following this issue, there is a problem when using regexes on path.

Let's say I have 2 routes : GET /users/{userID:[^/]+} and POST /users/{userID:[^/]+}.

In helper.go, in Spec.SetupOperation(), we get the pathItem (l.40) from s.Paths.MapOfPathItemValues by using the path as key (so in this case, /users/{userID:[^/]+}). But at the end of the method, we set the new pathItem under the key /users/{userID} (the path without the regex). When we setup the operation for the next method, we get the pathItem under the key /users/{userID:[^/]+}, which is empty, so the first routes is overridden completely by the second one.

I think getting the pathItem after the regex substitution should solve the issue (so after l. 51, maybe at l.54 because the first use of pathItem is at line 55).

vearutop commented 1 year ago

Thank you for spotting this bug and investigating the code. 👍 You're right with the suggested solution. 💪