connexion
connexion copied to clipboard
[FIX] replicate swagger-ui problem and hacky solution
Fixes #1890 .
Changes proposed in this pull request:
- revert #1830 and clone using _spec
- ~add external reference to simple app~
- ~try to clone with raw spec, unless there are external references~
- ~I'm unsure what the specific problem was in #1829 so I don't know how to differentiate use cases.~
Thanks @jdkent, but the tests are still failing with your fix.
Note that we do have tests for relative refs, so not sure why this is failing. If there is an issue, I assume it is in the ref resolving, and we should fix it there.
thanks for pointing towards an existing test, for a more minimal example, try cloning the specification in the test:
def test_relative_refs(relative_refs, spec):
spec_path = relative_refs / spec
specification = Specification.load(spec_path)
assert "$ref" not in specification.raw
# clone specification
specification_clone = specification.clone()
assert "$ref" not in specification_clone.raw
The clone step will fail since base_uri is no longer set and clone is being applied to the "raw spec" before dereferencing is done instead of being applied to the "loaded spec" where dereferencing is already done.
I could see a solution where base_uri is an optional argument passed with clone, or some reversion of this pull request (https://github.com/spec-first/connexion/pull/1830), but I do not know what problem that pull request was specifically fixing.
if I change the clone function back to:
def clone(self):
return type(self)(copy.deepcopy(self._spec))
and run this test from test_swagger_ui.py:
def test_simple(swagger_ui_app):
app_client = swagger_ui_app.test_client()
response = app_client.get("/v1.0/spec.json")
assert response.status_code == 200
the tests still pass, so I'm unsure what the minimal example that makes deepcopying self._spec not viable in #1829, but deepcopying self._raw_spec fixes.
coverage: 94.147%. remained the same when pulling 185c88c8d015f4a52cf10a857dc18004a2b229a5 on jdkent:fix/clone into a930303faa9e10603cdd820c497303b2e52d8253 on spec-first:main.
This seems related to my issue. Unsure. #1909