From f7fe63e236bd6546ce18225c17eb8ce8a4a619be Mon Sep 17 00:00:00 2001 From: Vladimir Volkov Date: Wed, 26 May 2021 08:30:24 +0300 Subject: [PATCH] feat: openapi spec v3 responses --- setup.py | 2 +- star_resty/apidocs/operation.py | 2 +- star_resty/apidocs/response.py | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index f75c3c6..c28416b 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ def get_packages(package): 'apispec<4', 'python-multipart' ], - version='0.0.18', + version='0.0.19', url='https://github.com/slv0/start_resty', license='BSD', description='The web framework', diff --git a/star_resty/apidocs/operation.py b/star_resty/apidocs/operation.py index 7664a18..d681336 100644 --- a/star_resty/apidocs/operation.py +++ b/star_resty/apidocs/operation.py @@ -23,7 +23,7 @@ def setup_operation(endpoint: Method, version=2): 'summary': options.summary, 'produces': [endpoint.serializer.media_type], 'parameters': resolve_parameters(endpoint), - 'responses': resolve_responses(endpoint), + 'responses': resolve_responses(endpoint, version), } if options.security is not None: diff --git a/star_resty/apidocs/response.py b/star_resty/apidocs/response.py index fea014e..92f257a 100644 --- a/star_resty/apidocs/response.py +++ b/star_resty/apidocs/response.py @@ -6,10 +6,19 @@ __all__ = ('resolve_responses',) -def resolve_responses(endpoint: Method): +def resolve_responses(endpoint: Method, version: int): responses = {} if endpoint.response_schema: - responses[str(endpoint.status_code)] = { + if version == 3: + responses[str(endpoint.status_code)] = { + 'content': { + endpoint.serializer.media_type: { + 'schema': endpoint.response_schema + } + } + } + else: + responses[str(endpoint.status_code)] = { 'schema': endpoint.response_schema }