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

Drop openapi-spec-validator for custom ref handler #1455

Merged
merged 1 commit into from
Feb 21, 2022

Conversation

RobbeSneyders
Copy link
Member

Fixes #930
Continues on #936

This PR completely removes the dependency on openapi-spec-validator. There's multiple reasons to do this:

@RobbeSneyders RobbeSneyders force-pushed the feature/drop-openapi-spec-validator branch 2 times, most recently from 3310da9 to 38afecc Compare February 7, 2022 22:24
@coveralls
Copy link

coveralls commented Feb 7, 2022

Pull Request Test Coverage Report for Build 1877457959

  • 20 of 31 (64.52%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.3%) to 96.744%

Changes Missing Coverage Covered Lines Changed/Added Lines %
connexion/json_schema.py 20 31 64.52%
Totals Coverage Status
Change from base Build 1877449835: -0.3%
Covered Lines: 2882
Relevant Lines: 2979

💛 - Coveralls

Copy link
Member

@Ruwann Ruwann left a comment

Choose a reason for hiding this comment

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

Thanks, Robbe! Think we just need to adjust the tests for this?


from .utils import deep_get


class ExtendedSafeLoader(yaml.SafeLoader):
"""Extends the yaml SafeLoader to coerce all keys to string so the result is valid json."""
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to do this? Shouldn't the loaded file be json as well if it adheres to OpenAPI? Perhaps I'm simply overlooking something.

Copy link
Member Author

Choose a reason for hiding this comment

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

The loaded file can be a yaml file as well, which allows integer keys. According to the OpenAPI spec, keys should indeed be strings so the yaml is a representation of valid json, and we shouldn't need this. However openapi-spec-validator allowed this, and I tried to provide a drop-in replacement so kept the same behavior.

We could mark this for deprecation in the next major version though.

@@ -42,7 +42,8 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
$ref: "file:///home/robbe/workspace/oss/connexion/examples/openapi3/methodresolver/openapi/test.json#/components/schemas/Pet"
# $ref: "http://0.0.0.0:8000/test.yaml#/components/schemas/Pet"
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a separate test for this and change this back to the original value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Woops, this is leftover from my local testing.
I'll remove this and add a separate test.
Strange that this doesn't fail in the Github pipeline though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so this didn't break because this is an example, not a test 😅

It's unfortunately not straightforward to add a test, sine only absolute paths are supported (#254). So I would propose to merge without unless you have an idea on how to do it?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, I don't see a good way of adding a test for this, so I would merge without it.

@RobbeSneyders RobbeSneyders force-pushed the feature/drop-openapi-spec-validator branch from 38afecc to 20b396c Compare February 18, 2022 19:17
@RobbeSneyders RobbeSneyders force-pushed the feature/drop-openapi-spec-validator branch from 20b396c to b762a9a Compare February 21, 2022 17:09
@RobbeSneyders RobbeSneyders merged commit 67d769d into main Feb 21, 2022
@Ruwann Ruwann deleted the feature/drop-openapi-spec-validator branch March 17, 2022 17:56
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.

Use jsonschema for validation
3 participants