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

Commit

Permalink
fixes #2 and added example for variable parentheses in flask routes
Browse files Browse the repository at this point in the history
  • Loading branch information
atlithorn committed Mar 9, 2015
1 parent b79402f commit 4c4f161
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +20,7 @@ def get(self):
"""
return []

def post(self):
def post(self, team_id):
"""
Create a new user
---
Expand Down Expand Up @@ -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/<int:team_id>', view_func=UserAPI.as_view('users'))

@app.route("/hacky")
def bla():
Expand Down
16 changes: 12 additions & 4 deletions flask_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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):
Expand Down
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.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',
Expand Down

0 comments on commit 4c4f161

Please sign in to comment.