Skip to content

Auto-generated examples for requestBody using oneOf #10765

@roddharris

Description

@roddharris

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)

Image

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions