Skip to content
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

Fix for #104, adding support for mounted apps #244

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyramid_openapi3/tests/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_relative_app_request() -> None:
)
assert openapi_request.host_url == "http://example.com"
assert openapi_request.path == "/subpath/foo"
assert openapi_request.path_pattern == "/foo"
assert openapi_request.path_pattern == "/subpath/foo"
assert openapi_request.method == "get"
assert openapi_request.body == b""
assert openapi_request.mimetype == "text/html"
Expand Down
19 changes: 14 additions & 5 deletions pyramid_openapi3/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ def path(self) -> str:
@property
def path_pattern(self) -> str:
"""The matched url with path pattern.""" # noqa D401
path_pattern = (
self.request.matched_route.pattern
if self.request.matched_route
else self.request.path_info
)

# since application might be mounted on virtual location we need
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# since application might be mounted on virtual location we need
# Since application might be mounted on virtual location we need

# to prepend it to the route pattern, or request's response validation
# will fail. one example of this is using WSGI compositors like
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# will fail. one example of this is using WSGI compositors like
# will fail. One example of this is using WSGI compositors like

# rutter (https://rutter.rtfd.io)
# see: https://wsgi.readthedocs.io/en/latest/definitions.html#envvar-SCRIPT_NAME
if self.request.matched_route:
path_pattern = "%s%s" % (
self.request.script_name,
self.request.matched_route.pattern,
)
Comment on lines +46 to +49
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path_pattern = "%s%s" % (
self.request.script_name,
self.request.matched_route.pattern,
)
path_pattern = f"{self.request.script_name}{self.request.matched_route.pattern}"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also fix the pyupgrade warning.

else:
path_pattern = self.request.path

return path_pattern

@property
Expand Down
Loading