swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.67k stars 8.97k forks source link

OpenAPI 3.1.0 support: Open API 3.1.0: `examples` from `schema` of parameters not shown in Swagger UI #9045

Open mattibo opened 1 year ago

mattibo commented 1 year ago

The list of examples from schema of parameters is not shown in Swagger UI:

Example: OpenApi: 3.1.0, SwaggerUI 5.1.3

openapi: 3.1.0
info:
  title: Test-API
  version: 1.0.0
paths:
  /api/v1/example/{name}/{version}/:
    get:
      parameters:
        - name: name
          required: true
          in: path
          description: Parameter with string as example
          schema:
            title: Name
            type: string
            examples:
              - Test Name
        - name: version
          required: true
          in: path
          description: Parameter with list as example
          schema:
            title: Version
            type: string
            examples:
              - value: stable
                summary: Stable version
              - value: latest
                summary: Latest version
      responses:
        '200':
          description: Successful Response

In the rendered SwaggerUI no examples are shown:

image

Example: OpenApi: 3.0.2, SwaggerUI 5.1.3

With version 3.0.2 of OpenApi the examples are shown correctly in the Swagger UI:

openapi: 3.0.2
info:
  title: Test-API
  version: 1.0.0
paths:
  /api/v1/example/{name}/{version}/:
    get:
      parameters:
        - name: name
          required: true
          in: path
          description: Parameter with string as example
          schema:
            title: Name
            type: string
          example: Test Name
        - name: version
          required: true
          in: path
          description: Parameter with list as example
          schema:
            title: Version
            type: string
          examples:
            Stable:
              summary: Stable version
              value: stable
            Latest:
              summary: Latest version
              value: latest
      responses:
        '200':
          description: Successful Response

image

Is this a bug in the current version of the Swagger UI or will the examples of the Schema not displayed in the UI?

austinorr commented 1 year ago

@mattibo what happens if you pass the old spec ‘as-is’ into the new version of swagger-ui? Your two schemas are not the same, in the old one, the ‘examples’ mapping is correctly placed, but in the new one it’s within the schema. Were these built by pre v0.100 and post v0.100 versions of fastapi?