diff --git a/sphinxcontrib/openapi/openapi30.py b/sphinxcontrib/openapi/openapi30.py index 3b47277..25579b1 100644 --- a/sphinxcontrib/openapi/openapi30.py +++ b/sphinxcontrib/openapi/openapi30.py @@ -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: diff --git a/sphinxcontrib/openapi/openapi31.py b/sphinxcontrib/openapi/openapi31.py index 0e8cba7..f24b61e 100644 --- a/sphinxcontrib/openapi/openapi31.py +++ b/sphinxcontrib/openapi/openapi31.py @@ -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: diff --git a/tests/test_openapi.py b/tests/test_openapi.py index d254572..e2c2b83 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -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() @@ -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):