swagger-api / swagger-api/swagger-ui
Auto-generated examples for requestBody using oneOf
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: Windows 11
- Browser: Edge
- Version: 145.0.3800.97
- Method of installation: dist
- Swagger-UI version: 5.32.0
- Swagger/OpenAPI version: OpenApi 3.0
Content & configuration
Swagger/OpenAPI definition:
/demo:
post:
summary: Submit, update, signing data or cancel.
requestBody:
required: true
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/OrderSubmitPayload'
- $ref: '#/components/schemas/OrderUpdatePayload'
- $ref: '#/components/schemas/OrderMiscPayload'
- $ref: '#/components/schemas/OrderCancelPayload'
components:
schemas:
BaseOrder:
type: object
properties:
name1:
type: string
name2:
type: string
OrderSubmitPayload:
allOf:
- type: object
properties:
order_func:
type: string
agency_id:
type: string
- $ref: '#/components/schemas/BaseOrder'
OrderUpdatePayload:
allOf:
- type: object
properties:
order_func:
type: string
order_id:
type: string
- $ref: '#/components/schemas/BaseOrder'
OrderMiscPayload:
type: object
properties:
order_func:
type: string
order_id:
type: string
message:
type: string
OrderCancelPayload:
type: object
properties:
order_func:
type: string
order_id:
type: string
Screenshots
By default, it shows only one example (even though schema shows all the available types)
If I add the following in my requestBody
examples:
Submit:
Update:
Misc:
Cancel:
I can get it to show a dropdown of available examples.
How can we help?
The dropdown does nothing at this point -- it still shows the default example based on the first schema.
I want to find a way to provide the dropdown of examples but have the example for each option auto-generated from the schema (like it does initially based on the first schema). Right now, the only way I can get a full example of each schema is to manually create an example that includes every property in the schema.
Does swagger-ui provide a way to do this or would I need to add a feature request?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied OpenAPI 3.0 requestBody with its oneOf and allOf schemas in Swagger UI 5.32.0, then trace request-body example generation and the examples dropdown behavior. Done means each dropdown option displays an automatically generated example for its selected schema rather than the first schema's example, with coverage for the reported configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100