diff --git a/sphinxcontrib/openapi/openapi30.py b/sphinxcontrib/openapi/openapi30.py index 3b47277..6ef3ce9e 100644 --- a/sphinxcontrib/openapi/openapi30.py +++ b/sphinxcontrib/openapi/openapi30.py @@ -304,8 +304,14 @@ def _httpresource(endpoint, method, properties, convert, render_examples, request_content = properties.get('requestBody', {}).get('content', {}) if request_content and 'application/json' in request_content: schema = request_content['application/json']['schema'] - req_properties = json.dumps(schema['properties'], indent=2, - separators=(',', ':')) + if schema['type'] == 'object': + # if it's an object, focus on the properties of that object + req_properties = json.dumps(schema['properties'], indent=2, + separators=(',', ':')) + else: + # if it's another type, dump the whole thing + req_properties = json.dumps(schema, indent=2, + separators=(',', ':')) yield '{indent}**Request body:**'.format(**locals()) yield '' yield '{indent}.. sourcecode:: json'.format(**locals()) diff --git a/tests/test_openapi.py b/tests/test_openapi.py index d254572..d8fdfe4 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -1693,6 +1693,33 @@ def test_method_option(self): ok ''').lstrip() + def test_request_body_non_object(self): + renderer = renderers.HttpdomainOldRenderer(None, {'request': True}) + text = '\n'.join(renderer.render_restructuredtext_markup({ + 'openapi': '3.0.0', + 'paths': { + '/things': { + 'post': { + 'summary': 'Create Thing', + 'requestBody': { + 'content': { + 'application/json': { + 'schema': {'type': 'string'}, + }, + }, + }, + 'responses': { + '200': { + 'description': 'A thing created.', + }, + }, + }, + }, + }, + })) + assert ' **Request body:**' in text + assert '"type":"string"' in text + class TestResolveRefs(object):