Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] replicate swagger-ui problem and hacky solution #1889

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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.

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