You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the DispatcherMiddleware from Werkzeug to nest my application under /api/v1. In my spec, I have http://localhost:3991/api/v1 listed under servers. When I make a request to http://localhost:3991/api/v1/accounts I get the following error:
openapi_core.templating.paths.exceptions.ServerNotFound: Server not found for http://localhost:3991/accounts
Notice that the library interprets the url incorrectly, it just appends the /accounts endpoint from my spec to the hostname rather than to the full base url. There are two things that need changed for this to be fixed:
In lines 37 and 39 of openapi_core/templating/paths/finders.py urls are joined with urljoin, which removes everything after the hostname. E.g. https://test.com/test1 joined to /test2 would yield https://test.com/test2. A different function would have to be used
The requests from the library expect a host_url when it should probably be a base url. There would need to be a way to find this base url in the flask response transformer, but I'm sure it could be done.
An easier solution that would work for now would be to add an option to disable server validation. I'd be glad to submit a PR to do that or to fix the above issue, I just want to get confirmation before I work on the PR.
The text was updated successfully, but these errors were encountered:
A workaround I found is to subclass the request transformer as well as append the base path to all spec routes:
spec= {
# your spec
}
BASE_PATH='/api/v1'classMyFlaskOpenApiRequest(FlaskOpenAPIRequest):
@propertydefpath_pattern(self):
returnf'{BASE_PATH}{super().path_pattern}'spec_for_validators= {
**spec,
'paths': {f'{BASE_PATH}{k}': vfork, vinspec['paths'].items()},
}
# also need to set server to relative root to make this workspec_for_validators['servers'] = [{'url':'/'}]
You can still use the original spec with the original paths for serving docs etc.
FYI above code isn't tested, as my implementation is slightly different.
I am not using an openapi decorator, I'm validating responses and requests in functions in the public_api app using flask's before_request and after_request decorators.
I'm using the DispatcherMiddleware from Werkzeug to nest my application under
/api/v1
. In my spec, I havehttp://localhost:3991/api/v1
listed underservers
. When I make a request tohttp://localhost:3991/api/v1/accounts
I get the following error:Notice that the library interprets the url incorrectly, it just appends the
/accounts
endpoint from my spec to the hostname rather than to the full base url. There are two things that need changed for this to be fixed:https://test.com/test1
joined to/test2
would yieldhttps://test.com/test2
. A different function would have to be usedAn easier solution that would work for now would be to add an option to disable server validation. I'd be glad to submit a PR to do that or to fix the above issue, I just want to get confirmation before I work on the PR.
The text was updated successfully, but these errors were encountered: