-
Notifications
You must be signed in to change notification settings - Fork 76
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
Improve api path matching #58
Comments
@nicolastrres if you have any brilliant idea in this area, I'm all ears. |
Just to let you know that I'm currently facing this problem. We used to have this path only:
But now I added this other one:
If I place the latter after the former, I get a wrong match, stating that flex.exceptions.ValidationError: 'request':
- 'path':
- 'tuple index out of range' Oh, and btw, I work in the same team as @nicolastrres :) |
Out of town on vacation for two more days. I'll take a look into this when I get back. Feel free to start up a pull request, even if it only creates a test that shows this failure. |
This issue however is not resolved, as the regexes are still too greedy. |
:( Em sex, 27 de mar de 2015 às 11:35, Piper Merriam [email protected]
|
Ah, I see I may have been mis-understood. @alvarocavalcanti you're issue is fixed. I was referencing that the overall issue detailed in this issue about making the regex's more specific is not implemented, so I expect there still may be other bugs found related to this. |
Awesome! Thanks. Em sex, 27 de mar de 2015 11:50, Piper Merriam [email protected]
|
generate path regexes with \d for integers [#58]
just stumbled over this after debugging an error while extending an api, the first is that flex does not recognize the type
therefore the second is the way it selects the "better" match if there are multiple, it just picks the longer path, leading to the strange behaviour that e.g. would it be a solution to just select the first match in the spec? I didn't find a workaround, besides disabling the check for the new paths |
The current api path matching leaves room for improvement in the case where multiple matches are found for a target path. This happens in pretty simple situations like nested resources.
/get/{id}
=>/get/(?P<id>.+)
/get/{id}/nested/{other_id}
=>/get/(?P<id>.+)/nested/(?P<other_id>.+)
Both of these path regexes will match
/get/1234/nested/5678
.The current logic looks at the match with the most matched groups and assumes it is the correct path. I think this is a bit naive and may have false positives, or potentially pick the wrong path in specialized use cases.
I don't know that the correct approach is, but I think a start would be to use other factors in the definition of the parameter to generate stricter regexes. Fox example, path parameters that are of
integer
type could generate/get/(?P<id>\d+)
so that it will only match paths that have numeric values in the location ofid
.Another thing to take into account, is that adding this kind matching based on type will turn what should be a type error in the actual extracted parameter value into an error matching the path. I don't know which is the correct error to raise. Maybe there is a way to do both?
The text was updated successfully, but these errors were encountered: