connexion icon indicating copy to clipboard operation
connexion copied to clipboard

[FIX] replicate swagger-ui problem and hacky solution

Open jdkent opened this issue 1 year ago • 6 comments

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.~

jdkent avatar Feb 21 '24 02:02 jdkent

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.

RobbeSneyders avatar Mar 20 '24 21:03 RobbeSneyders

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.

jdkent avatar Mar 21 '24 17:03 jdkent

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.

jdkent avatar Mar 21 '24 18:03 jdkent

Coverage Status

coverage: 94.147%. remained the same when pulling 185c88c8d015f4a52cf10a857dc18004a2b229a5 on jdkent:fix/clone into a930303faa9e10603cdd820c497303b2e52d8253 on spec-first:main.

coveralls avatar Mar 21 '24 18:03 coveralls

This seems related to my issue. Unsure. #1909

eharvey71 avatar Apr 09 '24 13:04 eharvey71