Skip to content

feat(parser): Detect OpenAPI documents of incorrect versions (closes #281) #302

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

Merged
merged 1 commit into from
Jan 19, 2021

Conversation

dbanty
Copy link
Collaborator

@dbanty dbanty commented Jan 16, 2021

  1. Adds semver validation to the openapi field and removes the default (it's a required field)
  2. Separate and re-export the vendored code so it retains its own license but our modifications can fall under our license
  3. Enforce that the major semver component of the openapi field is 3
  4. If schema validation fails, check for the swagger attribute at the top level and provide a hint to the user that they might be using an older, unsupported version.

@dbanty dbanty requested a review from emann January 16, 2021 21:28
@codecov
Copy link

codecov bot commented Jan 16, 2021

Codecov Report

Merging #302 (0a0cb88) into main (aede9be) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #302   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           46        47    +1     
  Lines         1348      1380   +32     
=========================================
+ Hits          1348      1380   +32     
Impacted Files Coverage Δ
...lient/schema/openapi_schema_pydantic/components.py 100.00% <ø> (ø)
...n_client/schema/openapi_schema_pydantic/contact.py 100.00% <ø> (ø)
...nt/schema/openapi_schema_pydantic/discriminator.py 100.00% <ø> (ø)
..._client/schema/openapi_schema_pydantic/encoding.py 100.00% <ø> (ø)
...n_client/schema/openapi_schema_pydantic/example.py 100.00% <ø> (ø)
.../openapi_schema_pydantic/external_documentation.py 100.00% <ø> (ø)
...on_client/schema/openapi_schema_pydantic/header.py 100.00% <ø> (ø)
...thon_client/schema/openapi_schema_pydantic/info.py 100.00% <ø> (ø)
...n_client/schema/openapi_schema_pydantic/license.py 100.00% <ø> (ø)
...thon_client/schema/openapi_schema_pydantic/link.py 100.00% <ø> (ø)
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aede9be...0a0cb88. Read the comment docs.

@dbanty dbanty force-pushed the feature/enforce-openapi-version branch from 47fc9f7 to 0a0cb88 Compare January 16, 2021 21:32
@dbanty dbanty linked an issue Jan 16, 2021 that may be closed by this pull request
@dbanty dbanty added this to the 0.8.0 milestone Jan 16, 2021
Copy link
Collaborator

@emann emann left a comment

Choose a reason for hiding this comment

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

One question but other that that LGTM

Comment on lines +269 to +272
if "swagger" in d:
detail = (
"You may be trying to use a Swagger document; this is not supported by this project.\n\n" + detail
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just check for this or the openapi field before attempting to parse the dict?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. I don't think it's illegal to have extra fields (e.g. swagger) so I don't want to disallow that if the spec is otherwise valid
  2. Validating the format of openapi seems like a task for Pydantic since the semver requirement is part of the OpenAPI spec.

@dbanty dbanty merged commit 8331aad into main Jan 19, 2021
@dbanty dbanty deleted the feature/enforce-openapi-version branch January 19, 2021 15:08
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.

Validate Document Version
2 participants