diff --git a/examples/example.py b/examples/example.py index c8c5d94..e4409a5 100644 --- a/examples/example.py +++ b/examples/example.py @@ -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']) diff --git a/flask_swagger.py b/flask_swagger.py index 98060d8..ee06a11 100644 --- a/flask_swagger.py +++ b/flask_swagger.py @@ -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. @@ -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") @@ -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): @@ -94,7 +94,11 @@ 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: @@ -102,10 +106,10 @@ def spec(): 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 \ No newline at end of file + return output diff --git a/setup.py b/setup.py index 63de240..ee951d8 100644 --- a/setup.py +++ b/setup.py @@ -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',