Skip to content

Commit

Permalink
Don't ignore collection_endpoint_name in MethodResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeSneyders committed Oct 11, 2023
1 parent e1b0ee9 commit 3a3c63c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
17 changes: 10 additions & 7 deletions connexion/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,6 @@ def __init__(self, *args, class_arguments: _class_arguments_type = None, **kwarg
}
"""
self.class_arguments = class_arguments or {}
if "collection_endpoint_name" in kwargs:
del kwargs["collection_endpoint_name"]
# Dispatch of request is done by Flask
logger.warning(
"collection_endpoint_name is ignored by the MethodViewResolver. "
"Requests to a collection endpoint will be routed to .get()"
)
super(MethodResolverBase, self).__init__(*args, **kwargs)
self.initialized_views: list = []

Expand Down Expand Up @@ -322,6 +315,16 @@ class MethodViewResolver(MethodResolverBase):
It resolves the method by calling as_view on the class.
"""

def __init__(self, *args, **kwargs):
if "collection_endpoint_name" in kwargs:
del kwargs["collection_endpoint_name"]
# Dispatch of request is done by Flask
logger.warning(
"collection_endpoint_name is ignored by the MethodViewResolver. "
"Requests to a collection endpoint will be routed to .get()"
)
super().__init__(*args, **kwargs)

def resolve_method_from_class(self, view_name, meth_name, view_cls):
view = None
for v in self.initialized_views:
Expand Down
19 changes: 15 additions & 4 deletions tests/test_resolver_methodview.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,31 @@ def test_methodview_resolve_with_default_module_name_and_x_router_controller_wil
assert operation.operation_id == "fakeapi.PetsView.search"


def test_methodview_resolve_with_default_module_name_will_resolve_resource_root_as_configured(
method_view_resolver,
):
def test_method_resolve_with_default_module_name_will_resolve_resource_root_as_configured():
operation = OpenAPIOperation(
method="GET",
path="/pets",
path_parameters=[],
operation={},
components=COMPONENTS,
resolver=method_view_resolver("fakeapi", collection_endpoint_name="api_list"),
resolver=MethodResolver("fakeapi", collection_endpoint_name="api_list"),
)
assert operation.operation_id == "fakeapi.PetsView.api_list"


def test_methodview_resolve_with_default_module_name_will_resolve_resource_root_as_configured():
operation = OpenAPIOperation(
method="GET",
path="/pets",
path_parameters=[],
operation={},
components=COMPONENTS,
resolver=MethodViewResolver("fakeapi", collection_endpoint_name="api_list"),
)
# The collection_endpoint_name is ignored
assert operation.operation_id == "fakeapi.PetsView.search"


def test_methodview_resolve_with_default_module_name_will_resolve_resource_root_post_as_post(
method_view_resolver,
):
Expand Down

0 comments on commit 3a3c63c

Please sign in to comment.