Skip to content

fix: 🐛 Shortcuts can silently collide and overwrite end-points. #616

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions flask_restx/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
from flask.views import http_method_funcs

from ._http import HTTPStatus
from .errors import abort
from .errors import abort, ValidationError
from .marshalling import marshal, marshal_with
from .model import Model, OrderedModel, SchemaModel
from .reqparse import RequestParser
from .utils import merge

# Container for each route applied to a Resource using @ns.route decorator
ResourceRoute = namedtuple("ResourceRoute", "resource urls route_doc kwargs")

DOC_IDS = [] # List all document ids used.

class Namespace(object):
"""
Expand Down Expand Up @@ -129,6 +129,9 @@ def _build_doc(self, cls, doc):
def doc(self, shortcut=None, **kwargs):
"""A decorator to add some api documentation to the decorated object"""
if isinstance(shortcut, str):
if shortcut in DOC_IDS:
raise ValidationError("Doc description already in use by another method!")
DOC_IDS.append(shortcut)
kwargs["id"] = shortcut
show = shortcut if isinstance(shortcut, bool) else True

Expand Down