Skip to content

Error ServerNotFound when nesting Flask application with Werkzeug application dispatcher #436

@SethThoburn

Description

@SethThoburn

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions