Skip to content

Commit 103c671

Browse files
authored
Fix for route validation when used with pyramid route_prefix_context (#101)
Only replace the path once
1 parent ea6707f commit 103c671

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

pyramid_openapi3/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def check_all_routes(event: ApplicationCreated):
325325
prefixes.append(path)
326326

327327
def remove_prefixes(path):
328+
path = f"/{path}" if not path.startswith("/") else path
328329
for prefix in prefixes:
329330
path = path.replace(prefix, "")
330331
return path

pyramid_openapi3/tests/test_app_construction.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ def test_prefixed_routes(app_config: Configurator) -> None:
103103
app_config.make_wsgi_app()
104104

105105

106+
def test_pyramid_prefixed_context_routes(app_config: Configurator) -> None:
107+
"""Test case for prefixed routes using pyramid route_prefix_context."""
108+
with app_config.route_prefix_context("/api/v1"):
109+
app_config.add_route(name="foo", pattern="/foo")
110+
app_config.add_route(name="bar", pattern="/bar")
111+
app_config.add_view(
112+
foo_view, route_name="foo", renderer="string", request_method="OPTIONS"
113+
)
114+
app_config.add_view(
115+
bar_view, route_name="bar", renderer="string", request_method="GET"
116+
)
117+
118+
app_config.make_wsgi_app()
119+
120+
106121
def test_missing_routes(app_config: Configurator) -> None:
107122
"""Test case showing app creation fails, when defined routes are missing."""
108123
with pytest.raises(MissingEndpointsError) as ex:

0 commit comments

Comments
 (0)