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

Don't let openapi_spec_validator tamper raw spec #762

Merged
merged 2 commits into from
Nov 13, 2018

Conversation

cziebuhr
Copy link
Contributor

@cziebuhr cziebuhr commented Nov 8, 2018

openapi_spec_validator adds x-scope to schemas with $ref, which then also get served in swagger.json.

"$ref" : "#/definitions/Container",
"x-scope" : [
   "",
   "#/definitions/InstanceStats"
]

In my case, bravado (which internally uses swagger_spec_validator) fails using the spec:

jsonschema.exceptions.RefResolutionError: unknown url type: ''

@dtkav
Copy link
Collaborator

dtkav commented Nov 8, 2018

What about using the spec that's passed in, and moving validation before resolving refs?
That would avoid another deepcopy.

     def __init__(self, raw_spec):
         self._raw_spec = copy.deepcopy(raw_spec)
         spec = self._set_defaults(raw_spec)
         spec = self._validate_spec(spec)
         self._spec = resolve_refs(spec)

@cziebuhr
Copy link
Contributor Author

cziebuhr commented Nov 8, 2018

That's also possible, if it's ok that the passed dict will get changed.

@dtkav
Copy link
Collaborator

dtkav commented Nov 8, 2018 via email

Copy link
Collaborator

@dtkav dtkav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@dtkav dtkav requested a review from jmcs November 12, 2018 17:07
@jmcs
Copy link
Contributor

jmcs commented Nov 13, 2018

👍

@jmcs jmcs merged commit 94686c0 into spec-first:master Nov 13, 2018
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.

3 participants