From e5225768d63718075505f5e82832150c364499f6 Mon Sep 17 00:00:00 2001 From: Angel Jimenez Date: Thu, 23 Jul 2020 11:04:14 +0200 Subject: [PATCH 1/2] Show description for arrays of string, number, integer or boolean --- sphinxcontrib/openapi/openapi20.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sphinxcontrib/openapi/openapi20.py b/sphinxcontrib/openapi/openapi20.py index efd3a3d..d5ab755 100644 --- a/sphinxcontrib/openapi/openapi20.py +++ b/sphinxcontrib/openapi/openapi20.py @@ -111,7 +111,15 @@ def _convert(schema, name='', required=False): (prop in required_properties)) elif type_ == 'array': - _convert(schema['items'], name + '[]') + if schema['items'].get('type', 'any') in ['string', 'number', 'integer', 'boolean']: + name = name.lstrip('.') + description = schema.get('description', '') + output.append(( + name, + '{type_} {name}:' + ' {description}'.format(**locals()))) + else: + _convert(schema['items'], name + '[]') else: if name: From 2294de30c37f0876a11d13d003c19a67910af1e0 Mon Sep 17 00:00:00 2001 From: Angel Jimenez Date: Thu, 23 Jul 2020 13:42:23 +0200 Subject: [PATCH 2/2] On array with non-primitive items (e.g. object) generate entry with its description --- sphinxcontrib/openapi/openapi20.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/sphinxcontrib/openapi/openapi20.py b/sphinxcontrib/openapi/openapi20.py index d5ab755..953551d 100644 --- a/sphinxcontrib/openapi/openapi20.py +++ b/sphinxcontrib/openapi/openapi20.py @@ -111,14 +111,13 @@ def _convert(schema, name='', required=False): (prop in required_properties)) elif type_ == 'array': - if schema['items'].get('type', 'any') in ['string', 'number', 'integer', 'boolean']: - name = name.lstrip('.') - description = schema.get('description', '') - output.append(( - name, - '{type_} {name}:' - ' {description}'.format(**locals()))) - else: + name = name.lstrip('.') + description = schema.get('description', '') + output.append(( + name, + '{type_} {name}:' + ' {description}'.format(**locals()))) + if schema['items'].get('type', 'any') not in ['string', 'number', 'integer', 'boolean']: _convert(schema['items'], name + '[]') else: @@ -235,7 +234,7 @@ def openapihttpdomain(spec, **options): if 'group' in options: groups = collections.OrderedDict( [(x['name'], []) for x in spec.get('tags', {})] - ) + ) for endpoint in paths: for method, properties in spec['paths'][endpoint].items(): @@ -247,7 +246,7 @@ def openapihttpdomain(spec, **options): method, properties, utils.get_text_converter(options), - )) + )) for key in groups.keys(): if key: @@ -266,6 +265,6 @@ def openapihttpdomain(spec, **options): method, properties, utils.get_text_converter(options), - )) + )) return iter(itertools.chain(*generators))