Skip to content
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

[Swagger] Support multiple status codes in Swagger documentation #98

Merged
merged 1 commit into from
May 4, 2021

Conversation

mjreiss
Copy link
Contributor

@mjreiss mjreiss commented Feb 16, 2021

This change adds support for providing multiple status code responses in the generated Swagger docs. Currently, any response provided in the @responds decorator will completely override any additional documentation. It would be nice if any existing docs were respected and persisted. This is helpful when documenting any known errors that a route may raise, such as 404 and 401, which might not require a schema or any additional information. If desired, these responses may be added to the Swagger docs using a decorator such as @api.doc(responses={401: "Not Authorized", 404: "Not Found"}).

This is partially related to issue #17, however it only adds support for multiple status code responses in the Swagger docs, it does not provide any additional support for the actual response. I might look into a fix for the given issue, which would actually support multiple responses and schemas.

@@ -367,7 +367,14 @@ def _model_from_parser(model_name: str, parser: reqparse.RequestParser) -> Model


def merge(first: dict, second: dict) -> dict:
return {**first, **second}
for key, value in first.items():
Copy link
Contributor Author

@mjreiss mjreiss Feb 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perform a deep merge, which will also merge the response. This method is only called on line 370, where the given response model will be combined with any existing __apidoc__ responses.

@mjreiss mjreiss marked this pull request as ready for review February 16, 2021 20:59
@apryor6
Copy link
Owner

apryor6 commented May 4, 2021

Sorry for the delay, thanks so much!

@apryor6 apryor6 merged commit a126c2c into apryor6:master May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants