fix(oas3): auto-generate per-variant examples for oneOf/anyOf request bodies (#10765) - #11054
Open
adrianodpdiaz wants to merge 3 commits into
Open
adrianodpdiaz wants to merge 3 commits into
adrianodpdiaz wants to merge 3 commits into
Conversation
oneOf/anyOf request bodiesoneOf/anyOf request bodies (#10765)
oneOf/anyOf request bodies (#10765)oneOf/anyOf request bodies (https://github.com/swagger-api/swagger-ui/issues/10765)
oneOf/anyOf request bodies (https://github.com/swagger-api/swagger-ui/issues/10765)oneOf/anyOf request bodies (#10765)
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
When a
requestBodyschema usesoneOforanyOfand has no explicitexamplesobject, Swagger UI now generates one example per variant and lets you switch between them from the existing Examples dropdown — for both JSON and XML.getOneOfExamples()(src/core/plugins/oas3/components/request-body.jsx):builds one example per
oneOf/anyOfvariant, merging shared parent schema keywords into each variant so nothing is lost. Each entry is labeled from the variant'stitle,x-summary, or$refname (falling back tooneOf[n]/anyOf[n]). Returnsnull(no-op) when the media type already declares its ownexamples, so hand-written examples are never overridden.RequestBodyas the source for the Examples dropdown whenever no explicitexamplesexist.<notagname>instead of the actual element name for the first variant. The body now reads directly from the generated example, so the correct root element name shows immediately.Motivation and Context
Fixes #10765
Reported issue: with a
oneOfrequestBody schema, Swagger UI only ever generated an example from the first variant, even though every variant is a valid payload. The only workaround was a hand-writtenexamplesobject, which has to be kept in sync with the schema manually.How Has This Been Tested?
Manually tested locally (
npm run dev) with a spec covering bothoneOfandanyOf, each with JSON and XML media types:<notagname>).examplesobject are unaffected.Example
Screenshots:
Checklist
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests