Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong path template matching #7

Closed
vanta opened this issue Jun 12, 2018 · 3 comments · Fixed by #28
Closed

Wrong path template matching #7

vanta opened this issue Jun 12, 2018 · 3 comments · Fixed by #28

Comments

@vanta
Copy link

vanta commented Jun 12, 2018

According to OpenAPI spec (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#pathsObject) there is a possibility to have two endpoints like below:

- /pets/{petId}
- /pets/mine

and one without template (/mine) should match when requesting /pets/mine. Currently in OAF it is not the case.

@kiebzak
Copy link
Contributor

kiebzak commented Jul 3, 2018

@vanta , openapi-first does not have it's own routing mechanisms. It depends solely on the web app framework used in the application, which in your case probably is express. In express, the order of the routes applied to the app/router is important because it follows 'first come, first served' rule. openapi-first iterates over your OAS 3.0 specification and for each operation (in order they appear in spec) it applies all declared openapi middlewares to the web app framework instance you use, using express-like route methods (i.e. router.get, router.post, router.put etc.).

So, in your case, it won't work if you specify operation in following order:

- /pets/{petId}
- /pets/mine

but it will work for this order:

- /pets/mine
- /pets/{petId}

Please let me know if this explanation resolves your issue.

@kiebzak
Copy link
Contributor

kiebzak commented Jul 17, 2019

@vanta I think I finally understood what the problem is. I did not realise it before because I was focused on controllers in which when you terminate the express middleware stack by sending response to the client this issue does not appear (provided you have correct, express friendly order of routes in your OAS 3 API specification). But indeed, it was a problem if openapi-middleware was calling next callback and paths are inclusive (like /pets/mine falls into /pets/{id}) but PR references above should fix it. Feel free to review it and thanks for spotting this!

@vanta
Copy link
Author

vanta commented Jul 17, 2019

Wow, @kiebzak thanks for the update :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants