Skip to content

Commit

Permalink
fix for mounted apps
Browse files Browse the repository at this point in the history
Interpolate request.script_name for openapi path_pattern to accomodate
  • Loading branch information
goodwillcoding authored May 5, 2024
1 parent f88d2c4 commit c4c5e19
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pyramid_openapi3/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ def path(self) -> str:
@property
def path_pattern(self) -> str:
"""The matched url with path pattern.""" # noqa D401

# 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
# rutter (https://rutter.rtfd.io)
# see: https://wsgi.readthedocs.io/en/latest/definitions.html#envvar-SCRIPT_NAME
relative_matched_route_pattern = "%s%s" % \
(self.request.script_name, self.request.matched_route.pattern)

path_pattern = (
self.request.matched_route.pattern
relative_matched_route_pattern
if self.request.matched_route
else self.request.path_info
else self.request.path
)
return path_pattern

Expand Down

0 comments on commit c4c5e19

Please sign in to comment.