Skip to content

Commit

Permalink
Added new parameter in Route decorator 'hidden_from_api_spec'; Added …
Browse files Browse the repository at this point in the history
…related unittest; Added missing required libraries for unittests in dev-requirements.txt; Updated AUTHORS.rst
  • Loading branch information
0x78f1935 committed Sep 16, 2021
1 parent f8cdb5e commit e59fde5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Contributors (chronological)
- Stephen Rosen `@sirosen <https://github.com/sirosen>`_
- Grey Li `@greyli <https://github.com/greyli>`_
- Tim Diekmann `@TimDiekmann <https://github.com/TimDiekmann>`_
- 0x78f1935 `@0x78f1935 <https://github.com/0x78f1935>`_
Binary file modified dev-requirements.txt
Binary file not shown.
22 changes: 18 additions & 4 deletions flask_smorest/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def add_url_rule(
*,
parameters=None,
tags=None,
hidden_from_api_spec=False,
**options,
):
"""Register url rule in application
Expand All @@ -116,6 +117,9 @@ def add_url_rule(
in this path, only used to document the resource.
:param list tags: List of tags for the resource.
If None, ``Blueprint`` name is used.
:param boolean hidden_from_api_spec: Don't document resource in API
spec file.
Default False.
:param options: Options to be forwarded to the underlying
:class:`werkzeug.routing.Rule <Rule>` object.
"""
Expand All @@ -139,10 +143,19 @@ def add_url_rule(

# Add URL rule in Flask and store endpoint documentation
super().add_url_rule(rule, endpoint, func, **options)
self._store_endpoint_docs(
endpoint, view_func, parameters, tags, **options)

def route(self, rule, *, parameters=None, tags=None, **options):
if not hidden_from_api_spec:
self._store_endpoint_docs(
endpoint, view_func, parameters, tags, **options)

def route(
self,
rule,
*,
parameters=None,
tags=None,
hidden_from_api_spec=False,
**options
):
"""Decorator to register view function in application and documentation
Calls :meth:`add_url_rule <Blueprint.add_url_rule>`.
Expand All @@ -155,6 +168,7 @@ def decorator(func):
func,
parameters=parameters,
tags=tags,
hidden_from_api_spec=hidden_from_api_spec,
**options
)
return func
Expand Down
18 changes: 18 additions & 0 deletions tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,24 @@ def test_2():
)
assert spec["paths"]["/test/test_2/"]["get"]["tags"] == ["test", ]

def test_blueprint_route_hidden_from_api_spec(self, app):
"""Check passing hidden_from_api_spec to route"""
blp = Blueprint('test', __name__, url_prefix='/test')

@blp.route('/test_1/', hidden_from_api_spec=True)
def test_1():
pass

@blp.route('/test_2/')
def test_2():
pass

api = Api(app)
api.register_blueprint(blp)
spec = api.spec.to_dict()
assert "/test/test_1/" not in spec["paths"]
assert "/test/test_2/" in spec["paths"]

@pytest.mark.parametrize('openapi_version', ['2.0', '3.0.2'])
def test_blueprint_response_schema(self, app, openapi_version, schemas):
"""Check response schema is correctly documented.
Expand Down

0 comments on commit e59fde5

Please sign in to comment.