-
Notifications
You must be signed in to change notification settings - Fork 38
Lack of support for nested routes of the same resource #57
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
Comments
Good spot! I agree that this is a genuine bug, and that the bug is in that matching logic. The desired behaviour from that logic: Current behaviour of that logic: Very happy to take a PR on this as I’m short on time at the moment. Otherwise I will see when I can fix it |
I've created a branch with new tests that expose this bug, see the diff https://github.com/RuntimeTools/chai-openapi-response-validator/compare/57-match-path-without-params-over-path-with-params?expand=1 Are we agreed that the new tests capture the bug? If so, feel free to PR a fix that satisfies those tests :) |
@rwalle61 ,
you'll get correct results:
but in order to achieve that, you need to change the route every time you iterate over the paths array, ie Another approach I see to tackle this problem is to |
Thanks for looking into this. I prefer the second approach (filter) because it makes nice conceptual sense: find all matching paths, and if there are multiple matches then choose the path that matches directly over the path that matches using a path parameter. I think filter would work for that. Do we have to consider efficiency? If so, instead of iterating over all paths (as filter would do) we could stop iterating once we’ve found a path that matches directly. So instead of
I don’t know if that would actually be faster. It probably wouldn’t make a significant difference unless the OpenAPI spec were enormous. Anyway, I don’t have strong opinions about this. I think your approach is spot on and I’m happy to see what you come up with! |
To confirm, this is a genuine bug according to OpenAPI 3 spec:
|
Quite a lot of code has changed since I initially recreated the failure in a branch. So here's a new branch recreating the failure https://github.com/RuntimeTools/OpenAPIValidators/compare/master...rwalle61:57-match-non-templated-path-instead-of-templated-path?expand=1 |
I don't have time to fix this immediately, so am happy if anyone wants to take over :) |
published in 0.9.4 (#111), please close this when you've verified it now works for you :) |
@rwalle61 could you please check this fix with a path like: |
OpenAPI version
3
Describe the bug
Lack of support for routes like:
To Reproduce
Prepare spec for ie:
and try to
satisfyApiSpec
against/resource/new
route.Current behavior
For
/resource/new
route it matches/resource/:id
and spec fails.Expected behavior
If
/resource/new
is being tested, it matches/resource/new
in the spec.If
/resource/:id
is being tested, it matches/resource/:id
in the spec.Additional context
EDIT: It seems that this is more like a convention in some environments rather than a standard itself (ie. route
/resource/new
).OpenApi3Spec.js
:satisfySchemaInApiSpec("...");
The text was updated successfully, but these errors were encountered: