Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new feature to support multiple routes when using python dict #554

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ def fromfile_decorated(username=None):
And the same can be achieved with multiple methods in a `MethodView` or `SwaggerView` by
registering the `url_rule` many times. Take a look at `examples/example_app`

When using python dictionaries as raw spec, exception rules can be added when rendering swagger routes

```python
api.add_resource(Username, *['/api/<string:username>', '/api/'])


@swag_from(specs_dict, rule='/api/')
def get(current_user):
pass
```

# Use the same data to validate your API POST body.

Expand Down
8 changes: 7 additions & 1 deletion flasgger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def get_specs(rules, ignore_verbs, optional_fields, sanitizer,
swagged = False

if getattr(method, 'specs_dict', None):
swag_dict_rule = getattr(method, 'swag_dict_rule', None)
if swag_dict_rule is not None:
if rule.rule not in swag_dict_rule:
continue

definition = {}
merge_specs(
swag,
Expand Down Expand Up @@ -207,7 +212,7 @@ def get_specs(rules, ignore_verbs, optional_fields, sanitizer,
def swag_from(
specs=None, filetype=None, endpoint=None, methods=None,
validation=False, schema_id=None, data=None, definition=None,
validation_function=None, validation_error_handler=None):
validation_function=None, validation_error_handler=None, rule=None):
"""
Takes a filename.yml, a dictionary or object and loads swagger specs.

Expand Down Expand Up @@ -265,6 +270,7 @@ def set_from_filepath(function):

def set_from_specs_dict(function):
function.specs_dict = specs
function.swag_dict_rule = rule

def is_path(specs):
""" Returns True if specs is a string or pathlib.Path
Expand Down