Skip to content

Conversation

jdkent
Copy link
Contributor

@jdkent jdkent commented Feb 21, 2024

Fixes #1890 .

Changes proposed in this pull request:

@RobbeSneyders
Copy link
Member

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.

@jdkent
Copy link
Contributor Author

jdkent commented Mar 21, 2024

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 (#1830), but I do not know what problem that pull request was specifically fixing.

@jdkent
Copy link
Contributor Author

jdkent commented Mar 21, 2024

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.

@coveralls
Copy link

coveralls commented Mar 21, 2024

Coverage Status

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

@eharvey71
Copy link

This seems related to my issue. Unsure. #1909

@chrisinmtown
Copy link
Contributor

chrisinmtown commented Nov 28, 2024

Hacky or not, I see that PR #2002 made exactly this change to the spec.py file's clone method, and I confirmed that a split spec works again. This change has not yet been released in a version at PyPI.

However, PR #2002 did /not/ add a new test, and this PR does. I think adding a test is valuable. If you rebase this PR and squash your 3 commits down to just one, maybe it will show just the added test case and you'll get approval & merge? Please consider.

@RobbeSneyders
Copy link
Member

Closing, replaced by #2089

RobbeSneyders added a commit that referenced this pull request Oct 13, 2025
This PR fixes an issue introduced in #2002, and the original issue #2002
was trying to address.

The original issue was that a cloned spec did not have properly resolved
references. #2002 fixed this incorrectly by cloning the resolved spec,
while the `Spec` initializer expects a raw spec.

This PR fixes this by cloning the raw spec, and passing the `base_uri`
required to resolve it along to the initializer of the new `Spec`
instance.

The swagger ui was also updated to use the resolved spec instead of the
raw spec.

Supersedes:
#1889
#2080

Fixes:
#1890
#1909
#2028 
#2029
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

Successfully merging this pull request may close these issues.

swagger-ui not resolving external references

5 participants