Skip to content

fix: use examples set next to a schema $ref in generated samples - #2875

Closed
ybai08 wants to merge 1 commit into
Redocly:mainfrom
ybai08:fix/ref-sibling-examples
Closed

ybai08 wants to merge 1 commit into
Redocly:mainfrom
ybai08:fix/ref-sibling-examples

Conversation

@ybai08

@ybai08 ybai08 commented Oct 18, 2026

Copy link
Copy Markdown

What/Why/How?

Since OpenAPI 3.1 a Schema Object $ref can have sibling keywords, and Redoc's schema view already shows them. Generated samples did not: openapi-sampler follows the $ref and drops its siblings, so for

Min:
  $ref: '#/components/schemas/ExampleNumber'
  example: 10
Max:
  $ref: '#/components/schemas/ExampleNumber'
  examples: [55]

the sample was { "Min": 0, "Max": 0 } instead of { "Min": 10, "Max": 55 }.

applyActiveVariantsToSchema already prepares the schema store for the sampler. When a $ref node has an example or examples sibling, it now replaces the node with its siblings, plus the target's type, xml, readOnly and writeOnly. The sampler then uses the sibling value. The XML element name and read-only/write-only filtering stay the same as when it follows the $ref. Siblings take precedence, as in the schema view. A $ref without an example sibling is left as it is.

Reference

Fixes #2609

Tests

  • New cases in src/jotai/__tests__/examples.test.ts: example/examples siblings on properties (JSON and XML samples), and an example next to a $ref at the schema root. Without the change to discriminator.ts, all three fail ({ min: 0, max: 0, step: 0 }, <min>0</min>, 0).
  • The suite was run on Node 22: npx vitest run gives 290 files passed, 1 skipped (3289 tests passed). npm run lint and npm run ts:check pass.
  • Not run: npm run e2e (Playwright) and npm run build.

Screenshots (optional)

Check yourself

  • Code is linted
  • Tested
  • All new/updated code is covered with tests

@ybai08
ybai08 requested a review from a team as a code owner October 18, 2026 08:06
@AlexVarchuk

Copy link
Copy Markdown
Collaborator

Hi @ybai08, we'll fix it in openapi-sampler instead of adding additional complexity to the Redoc logic.

@ybai08

ybai08 commented Oct 19, 2026

Copy link
Copy Markdown
Author

Makes sense, thanks. Closing this in favour of a fix in openapi-sampler; happy to send that PR there if it would help.

@ybai08 ybai08 closed this Oct 19, 2026
@AlexVarchuk

Copy link
Copy Markdown
Collaborator

here is a fix in openapi-sampler Redocly/openapi-sampler#224

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.

Examples set as siblings of a schema ref are not displayed

2 participants