-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Enforce common responses #22
Comments
A common pitfall when using this package is the following: you define an endpoint that can result in 400 Bad Request, but you forget to list 400 in the `responses` section of your endpoint in openapi.yaml. This package then instead returns 500 Internal Server error, because it keeps the promise that only defined responses will be allowed (unless you set `enable_request_validation` to `False`, that is). With this commit, all endpoints, by default need to have 200, 400 and 500 on the list of `responses` in openapi.yaml, otherwise the app won't start. Additionally, all endpoints that accept a parameter, also need to have 404 on the list of `responses`. You can skip this check by setting `enable_endpoint_validation` to `False`. Refs #22 Refs #49 (comment) Refs #36
I've drafted how I want the configuration for this functionality to look & feel: #103 Instead of requiring the config.endpoint_validation_overrides =
{
"/user/logout": {"post": [202, 400, 500]},
"/stores/{storeId}/backups/{backupId}/download:": {"post": [202, 400, 500]},
} It's not ideal to not be able to support Would love to hear feedback and ideas on how to improve the UX of this new check/feature! |
A common pitfall when using this package is the following: you define an endpoint that can result in 400 Bad Request, but you forget to list 400 in the `responses` section of your endpoint in openapi.yaml. This package then instead returns 500 Internal Server error, because it keeps the promise that only defined responses will be allowed (unless you set `enable_request_validation` to `False`, that is). With this commit, all endpoints, by default need to have 200, 400 and 500 on the list of `responses` in openapi.yaml, otherwise the app won't start. Additionally, all endpoints that accept a parameter, also need to have 404 on the list of `responses`. You can skip this check by setting `enable_endpoint_validation` to `False`. Refs #22 Refs #49 (comment) Refs #36
There are 2 cases covered by the OpenApi specification that I just wanted to bring to light here (and maybe discuss how / if they should be handled, or just documented as edge cases in the readme / upcoming docs):
The first point ( The second point ( |
One option would be to test it ourself. Another possibility may be to leverage openapi-core for it: If you call the This way it would solve both points from the previous comment without relying on specialized code inside this library |
Fantastic insights, thanks! |
Use case: I want to make sure that all of my endpoints define at least some responses. For example, I want all endpoints to define
200
,404
,403
and500
. If not, fail app startup.We have a similar thing already built for https://app.woocart.com/api/v1/, but it's a script that we run in CI. And I guess other people probably have a similar use case. I'm pasting the files below, as a starting point.
openapi_responses.yaml
:check_openapi_responses.py
The text was updated successfully, but these errors were encountered: