Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
added support for schema in responses
Browse files Browse the repository at this point in the history
  • Loading branch information
atlithorn committed Mar 2, 2015
1 parent 6cd967d commit 9363373
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
10 changes: 8 additions & 2 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ def bla():
tags:
- hacks
responses:
200:
description: Hacked some hacks
200:
description: Hacked some hacks
schema:
name: Hack
properties:
hack:
type: string
description: it's a hack
"""
return jsonify(['hacky'])

Expand Down
18 changes: 11 additions & 7 deletions flask_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _parse_docstring(obj):
return first_line, other_lines, swag


def _extract_definitions(parameter_list):
def _extract_definitions(alist):
"""
Since we couldn't be bothered to register models elsewhere
our definitions need to be extracted from the parameters.
Expand All @@ -41,8 +41,8 @@ def _extract_definitions(parameter_list):
"""

defs = list()
if parameter_list is not None:
for params in parameter_list:
if alist is not None:
for params in alist:
schema = params.get("schema")
if schema is not None:
schema_name = schema.get("name")
Expand All @@ -51,7 +51,7 @@ def _extract_definitions(parameter_list):
params['schema'] = {
"$ref": "#/definitions/{}".format(schema_name)
}
return parameter_list, defs
return defs


def swagger(app):
Expand Down Expand Up @@ -94,18 +94,22 @@ def spec():
for verb, method in methods.iteritems():
summary, description, swag = _parse_docstring(method)
if swag is not None: # we only add endpoints with swagger data in the docstrings
params, defs = _extract_definitions(swag.get('parameters', []))
params = swag.get('parameters', [])
defs = _extract_definitions(params)
responses = swag.get('responses', {})
if responses is not None:
defs = defs + _extract_definitions(responses.values())
for definition in defs:
name = definition.get('name')
if name is not None:
definitions[name] = definition
operations[verb] = dict(
summary=summary,
description=description,
responses=swag.get('responses', {}),
responses=responses,
tags=swag.get('tags', []),
parameters=params
)
if len(operations):
paths[str(rule)] = operations
return output
return output
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = file.read()

setup(name='flask-swagger',
version='0.1.0',
version='0.1.1',
url='https://github.com/gangverk/flask-swagger',
description='Extract swagger specs from your flast-restful project',
author='Atli Thorbjornsson',
Expand Down

0 comments on commit 9363373

Please sign in to comment.