diff --git a/README.md b/README.md index b8dfe9c6..06d7d4a8 100644 --- a/README.md +++ b/README.md @@ -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/', '/api/']) + + +@swag_from(specs_dict, rule='/api/') +def get(current_user): + pass +``` # Use the same data to validate your API POST body. diff --git a/flasgger/utils.py b/flasgger/utils.py index d0f43f9a..5649be43 100644 --- a/flasgger/utils.py +++ b/flasgger/utils.py @@ -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, @@ -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. @@ -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