Skip to content

Commit

Permalink
Fix swagger UI for split specs
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeSneyders committed Nov 23, 2024
1 parent cef665c commit 8e3f053
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions connexion/middleware/swagger_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def _base_path_for_prefix(self, request: StarletteRequest) -> str:
"route_root_path", request.scope.get("root_path", "")
).rstrip("/")

def _spec_for_prefix(self, request):
def _spec_for_prefix(self, request) -> dict:
"""
returns a spec with a modified basePath / servers block
which corresponds to the incoming request path.
This is needed when behind a path-altering reverse proxy.
"""
base_path = self._base_path_for_prefix(request)
return self.specification.with_base_path(base_path).raw
return self.specification.with_base_path(base_path)

def add_openapi_json(self):
"""
Expand Down
9 changes: 3 additions & 6 deletions connexion/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ def enforce_string_keys(obj):
return Swagger2Specification(spec, base_uri=base_uri)
return OpenAPISpecification(spec, base_uri=base_uri)

def clone(self):
return type(self)(copy.deepcopy(self._raw_spec))

@classmethod
def load(cls, spec, *, arguments=None):
if isinstance(spec, str) and (
Expand All @@ -217,9 +214,9 @@ def load(cls, spec, *, arguments=None):
return cls.from_file(spec, arguments=arguments, base_uri=base_uri)
return cls.from_dict(spec)

def with_base_path(self, base_path):
new_spec = self.clone()
new_spec.base_path = base_path
def with_base_path(self, base_path) -> dict:
new_spec = copy.deepcopy(self._spec)
new_spec["base_path"] = base_path
return new_spec

@property
Expand Down

0 comments on commit 8e3f053

Please sign in to comment.