python-openapi / openapi-core

Openapi-core is a Python library that adds client-side and server-side support for the OpenAPI v3.0 and OpenAPI v3.1 specification.
BSD 3-Clause "New" or "Revised" License
287 stars 131 forks source link

Improve error messages from error handlers #787

Open p1c2u opened 4 months ago

p1c2u commented 4 months ago

Discussed in https://github.com/python-openapi/openapi-core/discussions/757

Originally posted by **jtherrmann** January 11, 2024 All of the API endpoints for the test deployment of our Flask app, which is deployed via Amazon API Gateway, are currently returning a response like the one below: ``` { "detail": "Server not found for https://vd2gh6uqw3.execute-api.us-west-2.amazonaws.com/api/user", "status": 400, "title": "Bad Request", "type": "about:blank" } ``` We depend on the latest pre-release of `openapi-core`, . The error message leads me to believe that `openapi-core` is raising a [`ServerNotFound`](https://github.com/python-openapi/openapi-core/blob/0.19.0a1/openapi_core/templating/paths/exceptions.py#L40) exception from `BasePathFinder.find` ([here](https://github.com/python-openapi/openapi-core/blob/0.19.0a1/openapi_core/templating/paths/finders.py#L51)), which is called from `BaseAPICallValidator._find_path` ([here](https://github.com/python-openapi/openapi-core/blob/0.19.0a1/openapi_core/validation/validators.py#L277)). I have a couple of questions: * Is `BaseAPICallValidator` for validating requests, responses, or both? * Why does the validator need to validate the server URL? What exactly does [`APICallPathFinder._get_servers_iter`](https://github.com/python-openapi/openapi-core/blob/0.19.0a1/openapi_core/templating/paths/finders.py#L97) do? What is the fundamental meaning of a `ServerNotFound` exception?