fix(json-schema-2020-12): Fix OAS 3.1 additionalProperties false #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Local mirror of swagger-api#9023)
Description
swagger-ui incorrectly adds
"additionalProp1": {}
to samples for schemas whereadditionalProperties
isfalse
in OpenAPI 3.1.0, even though this was previously correct in OpenAPI 3.0.x.This fixes a change in swagger-api#8910 that did not handle the case that
additionalProperties
isfalse
, which broadened the conditionadditionalProperties === true
toisBooleanJSONSchema(additionalProperties)
with the same handling, treating anadditionalProperties
value offalse
identically to a value oftrue
.This can be remedied by changing
isBooleanJSONSchema(additionalProperties)
toisBooleanJSONSchema(additionalProperties) && additionalProperties === true
.This restores some parity between
src/core/plugins/json-schema-2020-12/samples-extensions/fn/main.js
andsrc/core/plugins/samples/fn/index.js
.Motivation and Context
No additional properties should be added to samples for schemas where
additionalProperties
isfalse
, maintaining consistency with the behavior in OpenAPI 3.0.x.Fixes swagger-api#9022
Refs swagger-api#8577
How Has This Been Tested?
Following the steps in "To reproduce..." in swagger-api#9022 using that
openapi.json
example, on master we have a sample body for aPOST /
request ofOn this branch, it is
I've added identical tests to
test/unit/core/plugins/samples/fn/index.js
and totest/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 fortest/unit/core/plugins/json-schema-2020-12/samples-extensions/fn.js
will fail.Screenshots (if appropriate):
On master
On this branch
Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests