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
![image](https://private-user-images.githubusercontent.com/11576729/253817970-05b794c1-2441-4e57-a77a-fa2335885865.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTkzODUsIm5iZiI6MTczOTAxOTA4NSwicGF0aCI6Ii8xMTU3NjcyOS8yNTM4MTc5NzAtMDViNzk0YzEtMjQ0MS00ZTU3LWE3N2EtZmEyMzM1ODg1ODY1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDEyNTEyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA4ZDQ1ZTU3N2RkOGYzMTNmMGQyMTcwNGY4MzdlNmJiZmM2Y2IwMmUxYWNhZmQ4OGRiYTdkMjZiOTc0MTZhOTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.hBBMpRETxfo5WNfDbA26v0GKncMbWCtjm6fOIyWvQgM)
On this branch
![image](https://private-user-images.githubusercontent.com/11576729/253820321-80038872-55f4-4759-a1bc-5932f74c0ecc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTkzODUsIm5iZiI6MTczOTAxOTA4NSwicGF0aCI6Ii8xMTU3NjcyOS8yNTM4MjAzMjEtODAwMzg4NzItNTVmNC00NzU5LWExYmMtNTkzMmY3NGMwZWNjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDEyNTEyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc0MjgwOGY3YjZkMjZiZjI4OTM0MTliMWFiNmE4NTA5YTNhZWIzOWNhMWZlYTY1YWFiMjAyMmRkODEwMjBiYjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.IXmljWTJOBNJy-xbY_k6O_Rsyh33g0IaBGiN6d87SZo)
Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests