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
2 changes: 1 addition & 1 deletion sphinxcontrib/openapi/openapi30.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _httpresource(endpoint, method, properties, convert, render_examples,
for line in req_properties.splitlines():
# yield indent + line
yield '{indent}{indent}{line}'.format(**locals())
# yield ''
yield ''

# print request example
if render_examples:
Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/openapi/openapi31.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _get_type_from_schema(schema):
for line in req_properties.splitlines():
# yield indent + line
yield "{indent}{indent}{line}".format(**locals())
# yield ''
yield ""

# print request example
if render_examples:
Expand Down
101 changes: 101 additions & 0 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,55 @@ def test_basic(self):
Last known resource ETag.
''').lstrip()

def test_request_body(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': 'object',
'properties': {
'name': {'type': 'string'},
},
},
},
},
},
'responses': {
'200': {
'description': 'A thing created.',
},
},
},
},
},
}))
assert text == textwrap.dedent('''
.. http:post:: /things
:synopsis: Create Thing

**Create Thing**

**Request body:**

.. sourcecode:: json

{
"name":{
"type":"string"
}
}

:status 200:
A thing created.
''').lstrip()

def test_rfc7807(self):
# Fix order to have a reliable test
pb_example = collections.OrderedDict()
Expand Down Expand Up @@ -1694,6 +1743,58 @@ def test_method_option(self):
''').lstrip()


class TestOpenApi31HttpDomain(object):

def test_request_body(self):
renderer = renderers.HttpdomainOldRenderer(None, {'request': True})
text = '\n'.join(renderer.render_restructuredtext_markup({
'openapi': '3.1.0',
'paths': {
'/things': {
'post': {
'summary': 'Create Thing',
'requestBody': {
'content': {
'application/json': {
'schema': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
},
},
},
},
},
'responses': {
'200': {
'description': 'A thing created.',
},
},
},
},
},
}))
assert text == textwrap.dedent('''
.. http:post:: /things
:synopsis: Create Thing

**Create Thing**

**Request body:**

.. sourcecode:: json

{
"name":{
"type":"string"
}
}

:status 200:
A thing created.
''').lstrip()


class TestResolveRefs(object):

def test_ref_resolving(self):
Expand Down