fix(json-schema-2020-12-samples): generate samples for prefixItems#10868
Open
yogeshwaran-c wants to merge 1 commit into
Open
fix(json-schema-2020-12-samples): generate samples for prefixItems#10868yogeshwaran-c wants to merge 1 commit into
yogeshwaran-c wants to merge 1 commit into
Conversation
The 2020-12 sample generator skipped JSON Schema 2020-12 prefixItems, emitting an empty array for tuple-typed schemas. Walk prefixItems first and append each entry's generated sample (preserving existing items behaviour for trailing entries), so OpenAPI 3.1 specs that use tuples render meaningful examples in the request body preview. Refs: swagger-api#10400
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The 2020-12 sample generator (
src/core/plugins/json-schema-2020-12-samples/fn/main.js) does not handle JSON Schema 2020-12prefixItems, which OpenAPI 3.1 uses to describe tuples. With a schema like:```yaml
type: array
prefixItems:
minItems: 2
maxItems: 2
```
…the request body preview rendered as an empty array. This PR walks
prefixItemsfirst and appends each generated sample to the array output, so tuple-typed properties produce meaningful examples ([0, "string"]for the schema above). The existingitemspath is preserved for trailing entries.Motivation and Context
Refs: #10400
OpenAPI 3.1 adopted JSON Schema 2020-12, which deprecated tuple validation via
items: [...]in favour ofprefixItems. Without this fix, any 3.1 spec using tuples shows an empty preview, hiding type information from API consumers and making "Try it out" useless for those operations.How Has This Been Tested?
test/unit/core/plugins/json-schema-2020-12-samples/fn.jscover three paths: prefixItems alone, prefixItems with object schemas, and prefixItems combined withitems. All three pass locally:```
PASS test/unit/core/plugins/json-schema-2020-12-samples/fn.js
Tests: 148 skipped, 3 passed, 151 total
```
test/e2e-cypress/e2e/bugs/10400.cy.js(with fixturestatic/documents/bugs/10400.yaml) loads an OpenAPI 3.1 spec with a tuple-typed property and asserts the preview contains\"tupleField\": [ 0, \"string\" ].Checklist