Skip to content

fix(json-schema-2020-12-samples): generate samples for prefixItems#10868

Open
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/issue-10400-prefix-items-sample
Open

fix(json-schema-2020-12-samples): generate samples for prefixItems#10868
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/issue-10400-prefix-items-sample

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

Description

The 2020-12 sample generator (src/core/plugins/json-schema-2020-12-samples/fn/main.js) does not handle JSON Schema 2020-12 prefixItems, which OpenAPI 3.1 uses to describe tuples. With a schema like:

```yaml
type: array
prefixItems:

  • type: integer
  • type: string
    minItems: 2
    maxItems: 2
    ```

…the request body preview rendered as an empty array. This PR walks prefixItems first and appends each generated sample to the array output, so tuple-typed properties produce meaningful examples ([0, "string"] for the schema above). The existing items path 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 of prefixItems. 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?

  • New Jest cases in test/unit/core/plugins/json-schema-2020-12-samples/fn.js cover three paths: prefixItems alone, prefixItems with object schemas, and prefixItems combined with items. All three pass locally:
    ```
    PASS test/unit/core/plugins/json-schema-2020-12-samples/fn.js
    Tests: 148 skipped, 3 passed, 151 total
    ```
  • New Cypress e2e spec test/e2e-cypress/e2e/bugs/10400.cy.js (with fixture static/documents/bugs/10400.yaml) loads an OpenAPI 3.1 spec with a tuple-typed property and asserts the preview contains \"tupleField\": [ 0, \"string\" ].

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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
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.

1 participant