Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions sphinxcontrib/openapi/openapi30.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
27 changes: 27 additions & 0 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down