Skip to content

Commit

Permalink
Merge pull request #4 from dave-shawley/more-functionality
Browse files Browse the repository at this point in the history
More functionality
  • Loading branch information
dave-shawley authored Mar 2, 2017
2 parents 9fdde22 + 3ceeda1 commit f38e7f0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
7 changes: 6 additions & 1 deletion docs/history.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
Release History
===============

`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
2 changes: 1 addition & 1 deletion sphinxswagger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version_info = (0, 0, 1)
version_info = (0, 0, 2)
__version__ = '.'.join(str(v) for v in version_info)


Expand Down
39 changes: 39 additions & 0 deletions sphinxswagger/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -148,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)
Expand All @@ -174,6 +204,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:
Expand Down

0 comments on commit f38e7f0

Please sign in to comment.