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(json-schema-2020-12): Fix OAS 3.1 additionalProperties false samples #9023

Conversation

adavis444
Copy link
Contributor

@adavis444 adavis444 commented Jul 16, 2023

Description

swagger-ui incorrectly adds "additionalProp1": {} to samples for schemas where additionalProperties is false in OpenAPI 3.1.0, even though this was previously correct in OpenAPI 3.0.x.

This fixes a change in #8910 that did not handle the case that additionalProperties is false, which broadened the condition additionalProperties === true to isBooleanJSONSchema(additionalProperties) with the same handling, treating an additionalProperties value of false identically to a value of true.

This can be remedied by changing isBooleanJSONSchema(additionalProperties) to isBooleanJSONSchema(additionalProperties) && additionalProperties === true.

This restores some parity between src/core/plugins/json-schema-2020-12/samples-extensions/fn/main.js and src/core/plugins/samples/fn/index.js.

Motivation and Context

No additional properties should be added to samples for schemas where additionalProperties is false, maintaining consistency with the behavior in OpenAPI 3.0.x.

Fixes #9022

Refs #8577

How Has This Been Tested?

Following the steps in "To reproduce..." in #9022 using that openapi.json example, on master we have a sample body for a POST / request of

{
  "bar": "string",
  "additionalProp1": {}
}

On this branch, it is

{
  "bar": "string"
}

I've added identical tests to test/unit/core/plugins/samples/fn/index.js and to test/unit/core/plugins/json-schema-2020-12/samples-extensions/fn.js.

However, as seen in the unit test results when tests are added without code changes, on master it is expected that the tests for test/unit/core/plugins/samples/fn/index.js will pass whereas the tests for test/unit/core/plugins/json-schema-2020-12/samples-extensions/fn.js will fail.

Screenshots (if appropriate):

On master
image

On this branch
image

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

@char0n char0n self-assigned this Jul 17, 2023
@char0n char0n self-requested a review July 17, 2023 12:06
@char0n
Copy link
Member

char0n commented Jul 18, 2023

Hi @adavis444,

Thanks for the PR! We'll get to this PR probably during Thursday Friday this week.

Copy link
Member

@char0n char0n left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for contributing! I'll make some additional nitpick changes to this PR before the merge.

@char0n char0n merged commit d9375db into swagger-api:master Jul 24, 2023
@adavis444 adavis444 deleted the bug/9022-fix-OAS-3.1-additionalProperties-false-samples branch July 24, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenAPI 3.1.0 support: additionalProperties: false adds additionalProp1 to samples
2 participants