pyramid_openapi3 icon indicating copy to clipboard operation
pyramid_openapi3 copied to clipboard

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

Open mmerickel opened this issue 3 years ago • 2 comments

Due to issues like https://github.com/Pylons/pyramid_openapi3/issues/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.

mmerickel avatar Sep 20 '22 17:09 mmerickel

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.

zupo avatar Sep 21 '22 13:09 zupo

@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

goodwillcoding avatar May 05 '24 08:05 goodwillcoding