-
Notifications
You must be signed in to change notification settings - Fork 74
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
Undocumented routes #110
Comments
I understand the feature but I'm not sure it is worth the added API surface. It should be easy to achieve in user code. Something like class MyBlueprint(Blueprint):
def route(self, rule, *, parameters=None, document=True, **options):
if document:
return super().route(rule, parameters=parameters, document=document, **options)
# Copy else case from Flask Blueprint
else:
def decorator(f):
endpoint = options.pop("endpoint", f.__name__)
self.add_url_rule(rule, endpoint, f, **options)
return f
return decorator Would this work for you? I'm not definitively and strongly opposed to the feature. Just unsure. |
This certainly works for me. |
I would love to see this feature integrated. Edit: Here is an updated version! # encoding: utf-8
"""
Blueprint adapter
-----------------
Flask-Smorest is not supporting hidden endpoints.
This class follows the following suggestion: https://github.com/marshmallow-code/flask-smorest/issues/110
"""
from flask_smorest import Blueprint
from flask.views import MethodViewType
class EnhancedBlueprint(Blueprint):
def route(self, rule, *, parameters=None, render=True, **options):
if render: return super().route(rule, parameters=parameters, **options)
else: # Hide documentation and swagger UI elements
def decorator(func):
# By default, endpoint name is function name
endpoint = options.pop('endpoint', func.__name__)
# Prevent registering several times the same endpoint
# by silently renaming the endpoint in case of collision
if endpoint in self._endpoints:
endpoint = '{}_{}'.format(endpoint, len(self._endpoints))
self._endpoints.append(endpoint)
if isinstance(func, MethodViewType):
view_func = func.as_view(endpoint)
else:
view_func = func
# Add URL rule in Flask and store endpoint documentation
self.add_url_rule(rule, endpoint, view_func, **options)
# self._store_endpoint_docs(endpoint, func, parameters, **options)
return func
return decorator Edit 2: I created a Pull Request |
This solutions no longer works due to internal updates in flask-smorest. |
I have a use-case where I want to have an undocumented internal route, while still using the arguments and response parsing.
Perhaps something like
@blp.route('/hidden-api', document=False)
The text was updated successfully, but these errors were encountered: