-
-
Notifications
You must be signed in to change notification settings - Fork 134
PathFinder finds all patterns, who looks like my request path, and he return worst case #226
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
Hi @mrkovalchuk thanks for reporting the issue. It should find exactly one path. Please check #220 . Fix #222 is already merged to master. |
@p1c2u Thanks for answer! Problem isn't solved =( Still three patterns. |
To ensure proper logic behind matching current request to OpenAPI operation to use. `openapi-core==0.13.3` version ships with `openapi_core.templating.paths.finders.PathFinder` class, which finds too many paths if OpenAPI schema contains multiple paths with variables. Given commit customize path finder logic to not return first result of `PathFinder._get_servers_iter(...)` call, but to match that current request full URL pattern ends with `Path.name`. After fixing python-openapi/openapi-core#226, this code might be not needed anymore. Also provide docstrings for reason behind providing custom classes for validation, unmarshalling data, etc.
Hi, I ran into similar issue, when upgrading First, I attempted to change OpenAPI Schema files to put paths with variables on the top, but unfortunately it didn't help much, as This leads me to use custom servers_iter: Iterator[PathTuple] = self._get_servers_iter(
request.full_url_pattern, operations_iter_peek
)
for server in servers_iter:
path = server[0]
if request.full_url_pattern.endswith(path.name):
return server While base servers_iter = self._get_servers_iter(
request.full_url_pattern, operations_iter_peek)
try:
return next(servers_iter)
except StopIteration:
raise ServerNotFound(request.full_url_pattern) My OpenAPI schema contains next paths,
And change above allows Hope, this is helpful |
I've seen this same issue, but the above solution doesn't work when validating Django responses. I ended up monkey patching the # ...
from openapi_core.templating import util
# HACK! Workaround for https://github.com/p1c2u/openapi-core/issues/226
def search(path_pattern, full_url_pattern):
p = util.Parser(path_pattern)
p._expression = p._expression + '$'
result = p.search(full_url_pattern)
if not result or any('/' in arg for arg in result.named.values()):
return None
return result
util.search = search
# ... rest of code I suspect this could be done in a far less hacky fashion if our pattern used for lookup included the type information for any parameters, as extracted from the schema. I looked into doing this with |
We've done the necessary work here already so this is a relatively easy switchover. However, we do have to work around an issue whereby the first possible matching route is used rather than the best one [1]. In addition, we have to install from master since there are fixes missing from the latest release, 0.13.3. Hopefully both issues will be resolved in a future release. [1] python-openapi/openapi-core#226 Signed-off-by: Stephen Finucane <[email protected]>
I think that I have same issue like described here (with version Test swagger file:
By making call to the second endpoint:
Request being validated against first path (i.e.
Simple workaround would be to change places of conflicted paths in swagger file, but I think that that will not work always (in above simple example it works). @p1c2u Does #222 solves this? If not, I'm willing to contribute with one PR to solve issue, but not sure are you (or anybody else) already on this? |
@stojan-jovic it should be fixed by #245 . Feel free to test it. |
@p1c2u I can confirm that fix working fine! I verified it pretty much time ago, but totally forgot to respond here. When we can expect new release? Can I somehow help with that? This is really important fix... |
Yeah, I'd also love to see this in a release; one has to do weird gymnastics in the OpenAPI configuration file to work around this bug. |
…egex. openapi-core, the request validator has a bug due to which data type of path parameters is not checked. Hence `/messages/{message_id}` can match with `messages/matches_narrow`. So change the position of of `message/{message_id}` after all such possible matches to avoid errors. See python-openapi/openapi-core#226 for details.
openapi-core, the request validator has a bug due to which data type of path parameters is not checked. Hence `/users/{user_id}` can match with `users/me`. So change the position of`/user/{user_id}` after all such possible matches to avoid errors. See python-openapi/openapi-core#226 for details.
In commit b7f3c3d ("tests: Switch to openapi-core 0.13.x") we added support for 'openapi-core' 0.13.x. However, we needed to use a commit from master since an important fix [1] was not included in the latest release at the time, 0.13.3. 0.13.4 has since been released so let's move on and use that. [1] python-openapi/openapi-core#226 Signed-off-by: Stephen Finucane <[email protected]>
Good day. Please start from comment in code:
dcb7161#r37991936
In my case PathFinder find three path patterns (with all him staff like a response and more...):
path_pattern (from request): api/some/reourse/{key}/this/path/
Matched patterns with important arg:
Ok. Could be worse. We can see, number three - best match. But code from link say: I'll return first of them. Why? Why we use iterators everywhere, but still return one response for validation? Not the most accurate pattern. Just first. Please look like it be in 0.13.2 version. Radical changes. And I don't understand new logic =(
This behaviour produce error in schema validation process. Schema right. I checked it.
Thanks for help.
The text was updated successfully, but these errors were encountered: