Skip to content

example in requestBody.content.<media-type> can't override which defined in schema.  #4225

@liu946

Description

@liu946
Q A
Bug or feature request? bug
Which Swagger/OpenAPI version? 3.0.0
Which Swagger-UI version?
How did you install Swagger-UI? use the online version on app.swaggerhub.com
Which browser & version? chrome
Which operating system? osx

Demonstration API definition

I test the online hub https://app.swaggerhub.com use the yaml code following, but I get the unexpected generation at right side of the page (like the following screenshot). I think it will generated like the document (https://swagger.io/docs/specification/describing-request-body/) as the example in requestBody.content. will override which defined in schema but it seems like the example I defined makes no sense.
2018-02-15 11 42 24

https://app.swaggerhub.com/apis/liu946/ssp/1.0.0

paths:
  /users:
    post:
      summary: Adds a new user
      requestBody:
        content:
          application/json:    # Media type
            schema:            # Request body contents
              $ref: '#/components/schemas/User'   # Reference to an object
            example:           # Child of media type because we use $ref above
              # Properties of a referenced object
              id: 10
              name: Jessica Smith
      responses:
        '200':
          description: OK
components:
  schemas:
    # basic data structure
    User:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string

Expected Behavior

generate example object like { id: 10, name: Jessica Smith}

Current Behavior

generate a {id: 0, name: "string"} object

Waiting for your help, please.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions