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: Remove all OpenAPI examples from spec before validating #1040

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

Conversation

max-at-silverflow
Copy link

@max-at-silverflow max-at-silverflow commented Jan 13, 2025

This PR was made to resolve issue #931. It introduces the following changes:

Commit 189d624:

  • Add a stripExamples function that takes an OpenAPIV3.DocumentV3 or OpenAPIV3.DocumentV3_1, removing all example and examples properties. (Note: This only affects examples provided as part of the spec, not user-defined properties called example or examples).
  • Call stripExamples in the spec loader to ensure examples are always discarded and do not affect validation in any way.
  • Add minimal test setup that verifies this works. (Note: If you remove the stripExamples call, this test fails).

These changes are necessary to avoid the validator from erroring out when providing specs that include multiple examples with the same value for a property id. This is explained in more detail in issue #931, though the proposed solution does not cover all cases. This PR expands on the suggestions and strips all examples, instead of just the component examples.

Note:
Originally, this PR also ran prettier -c -w ./ to improve the code style of the repository (49ffda6). But I realized that were way too many changes, so I reverted them in 8dfdb94. Sorry for the back-and-forth.

Closes #931

@max-at-silverflow
Copy link
Author

max-at-silverflow commented Jan 13, 2025

Originally, this PR also ran prettier -c -w ./, but that was a huge amount of changes. I decided to revert that change, in favor of making this PR more maintainable.

If you want, I can create a separate PR to fix prettier!

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.

Exclude OpenAPI Examples from Response Validation
1 participant