From 4c4f161c60500963a4db0fbfbe979c1129d1ce57 Mon Sep 17 00:00:00 2001 From: Atli Thorbjornsson Date: Mon, 9 Mar 2015 08:15:58 +0000 Subject: [PATCH] fixes #2 and added example for variable parentheses in flask routes --- examples/example.py | 6 +++--- flask_swagger.py | 16 ++++++++++++---- setup.py | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/example.py b/examples/example.py index ae2cc3b..87b008f 100644 --- a/examples/example.py +++ b/examples/example.py @@ -6,7 +6,7 @@ class UserAPI(MethodView): - def get(self): + def get(self, team_id): """ Get a list of users First line is the summary @@ -20,7 +20,7 @@ def get(self): """ return [] - def post(self): + def post(self, team_id): """ Create a new user --- @@ -58,7 +58,7 @@ def after_request(response): response.headers.add('Access-Control-Max-Age', 60 * 60 * 24 * 20) return response -app.add_url_rule('/users/', view_func=UserAPI.as_view('users')) +app.add_url_rule('/users/', view_func=UserAPI.as_view('users')) @app.route("/hacky") def bla(): diff --git a/flask_swagger.py b/flask_swagger.py index 0184c35..72160d3 100644 --- a/flask_swagger.py +++ b/flask_swagger.py @@ -80,6 +80,9 @@ def spec(): paths = output['paths'] definitions = output['definitions'] ignore_verbs = {"HEAD", "OPTIONS"} + # technically only responses is non-optional + optional_fields = ['tags', 'consumes', 'produces', 'schemes', 'security', + 'deprecated', 'operationId', 'externalDocs'] for rule in app.url_map.iter_rules(): endpoint = app.view_functions[rule.endpoint] @@ -104,13 +107,18 @@ def spec(): def_id = definition.get('id') if def_id is not None: definitions[def_id] = definition - operations[verb] = dict( + operation = dict( summary=summary, description=description, - responses=responses, - tags=swag.get('tags', []), - parameters=params + parameters=params, + responses=responses ) + # optionals + for key in optional_fields: + if key in swag: + operation[key] = swag.get(key) + operations[verb] = operation + if len(operations): rule = str(rule) for arg in re.findall('(<(.*?\:)?(.*?)>)', rule): diff --git a/setup.py b/setup.py index 66a2e24..40445ff 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = file.read() setup(name='flask-swagger', - version='0.2.0', + version='0.2.1', url='https://github.com/gangverk/flask-swagger', description='Extract swagger specs from your flast-restful project', author='Atli Thorbjornsson',