From 08c49f3efd75d4710175132cb6c071a730e0c8cd Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Thu, 2 Mar 2017 07:04:28 -0500 Subject: [PATCH 1/3] Add support for JSON response objects. --- docs/history.rst | 4 ++++ sphinxswagger/writer.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/docs/history.rst b/docs/history.rst index d1ac153..a8b0c29 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -1,6 +1,10 @@ Release History =============== +`Next Release`_ +--------------- +- Added support for JSON responses. + `0.0.1`_ (2016 Jun 06) ---------------------- - Initial release with simple Sphinx writer+builder. diff --git a/sphinxswagger/writer.py b/sphinxswagger/writer.py index 8be5e09..9f1c7cb 100644 --- a/sphinxswagger/writer.py +++ b/sphinxswagger/writer.py @@ -114,6 +114,33 @@ def depart_desc(self, node): responses.setdefault(default, {}) responses[default].update(rsp) + elif name.astext() == 'Response JSON Array of Objects': + obj_def = _render_response_information(field[1]) + if obj_def is not None: + responses.setdefault(default, {}) + responses[default].update({ + 'description': obj_def['description'], + 'schema': { + 'type': 'array', + 'items': obj_def['schema'], + } + }) + + elif name.astext() == 'Request JSON Object': + properties = {} + for name, spec in _generate_parameters(field[1]): + properties[name] = { + 'type': spec['type'], + 'description': spec['description'] + } + parameters.append({'name': 'request-body', + 'in': 'body', + 'required': True, + 'schema': { + 'type': 'object', + 'properties': properties, + }}) + elif name.astext() == 'Status Codes': for code, _, desc in _generate_status_codes(field[1]): if default == 'default' and 200 <= int(code) < 300: @@ -174,6 +201,15 @@ def _render_paragraph(paragraph): return '\n\n'.join(lines) +def _render_request_document(body): + """ + :param nodes.field_body body: + :rtype: dict|NoneType + """ + if len(body.children) > 1 or not isinstance(body[0], nodes.bullet_list): + return None + + def _render_response_information(body): """ :param nodes.field_body body: From 4525b39c4269e8809c348cafb4f4c5b5cfb0c760 Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Thu, 2 Mar 2017 07:29:40 -0500 Subject: [PATCH 2/3] Remove empty responses. --- sphinxswagger/writer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sphinxswagger/writer.py b/sphinxswagger/writer.py index 9f1c7cb..a042306 100644 --- a/sphinxswagger/writer.py +++ b/sphinxswagger/writer.py @@ -175,6 +175,9 @@ def depart_desc(self, node): spec['in'] = 'query' parameters.append(spec) + for k in tuple(responses.keys()): + if not responses[k]: + del responses[k] self._swagger_doc.add_path_info( desc_signature['method'], url_template, description, parameters, responses) From 3ceeda13398e928e92c728261b8a42f594a2c4a5 Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Thu, 2 Mar 2017 07:31:45 -0500 Subject: [PATCH 3/3] Metadata bumps for 0.0.2 --- docs/history.rst | 7 ++++--- sphinxswagger/__init__.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/history.rst b/docs/history.rst index a8b0c29..1809524 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -1,13 +1,14 @@ Release History =============== -`Next Release`_ ---------------- +`0.0.2`_ (2017 Mar 2) +--------------------- - Added support for JSON responses. `0.0.1`_ (2016 Jun 06) ---------------------- - Initial release with simple Sphinx writer+builder. -.. _Next Release: https://github.com/dave-shawley/sphinx-swagger/compare/0.0.1...HEAD +.. _Next Release: https://github.com/dave-shawley/sphinx-swagger/compare/0.0.2...HEAD +.. _0.0.2: https://github.com/dave-shawley/sphinx-swagger/compare/0.0.1...0.0.2 .. _0.0.1: https://github.com/dave-shawley/sphinx-swagger/compare/0.0.0...0.0.1 diff --git a/sphinxswagger/__init__.py b/sphinxswagger/__init__.py index e7c3760..85ea1c0 100644 --- a/sphinxswagger/__init__.py +++ b/sphinxswagger/__init__.py @@ -1,4 +1,4 @@ -version_info = (0, 0, 1) +version_info = (0, 0, 2) __version__ = '.'.join(str(v) for v in version_info)