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

provide a way to load the openapi.yaml that doesn't server it at an endpoint #174

Open
mmerickel opened this issue Sep 20, 2022 · 2 comments

Comments

@mmerickel
Copy link
Member

Due to issues like #104 I cannot define a yaml that fully matches the deployment environment so I'd prefer to just not serve the yaml if I can help it. I'd just like it to be used to validate paths, as the yaml defines everything relative to the app's subpath so works across deployments so long as pyramid_openapi3 is using request.application_url as the base path.

@zupo
Copy link
Collaborator

zupo commented Sep 21, 2022

Makes sense and also seems like it won't complicate the codebase much, so I'd likely be +1 on a PR that introduces this.

@goodwillcoding
Copy link
Member

goodwillcoding commented May 5, 2024

@zupo (cc: @mmerickel) ... ran into similar issue, using rutter WSGI compositor. Found solution of using request.script_name for PyramidOpenAPIRequest.path_pattern did the trick for relative absolute server urls without any additional variables. Below is the fix I propose. Tests should be easy enough to modify as well.

Let me know if you are ok with the fix, I'll do a PR.

    @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 = (
            relative_matched_route_pattern
            if self.request.matched_route
            else self.request.path
        )

        return path_pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants