3

When I add examples into my swagger doc and test it on the swagger editor, then it never shows anywhere. Could someone give me an example of where multiple examples are actually showing anywhere?

Here is an example of how multiple examples are added: enter image description here

it is from: https://swagger.io/docs/specification/adding-examples/

Here is an example of yaml that does not display any examples on the online swagger editor:

openapi: 3.0.0
info:
  title: Some API
  version: 1.0.0
paths:
  /logon:
    get:
      summary: Login user
      tags:
        - '/logon'
      parameters:
        - name: Client
          in: query
          required: true
          examples:
            zero:
              value: '0'
              summary: A sample limit value
            max:
              value: '50'
              summary: A sample limit value
          schema:
            type: string
      responses:
        '200':
          description: Success response
Helen
  • 87,344
  • 17
  • 243
  • 314
Freddy Bonda
  • 1,189
  • 6
  • 15
  • 33
  • Related: [Swagger/OpenAPI 3.0 issue with example on responses](https://stackoverflow.com/q/48551855/113116) – Helen Oct 01 '18 at 17:12

1 Answers1

9

Multiple examples are displayed in Swagger UI 3.23.0+ and Swagger Editor 3.6.21+:

Swagger UI displays multiple examples using a drop-down list


In older versions, you can use a single example as a workaround:

      parameters:
        - name: Client
          in: query
          required: true
          example: '50'  # <-----
          schema:
            type: string
Helen
  • 87,344
  • 17
  • 243
  • 314
  • 4
    Oh wow ok. Makes you wonder why they put it in the documentation when it doesn't show. Really very disappointed with Swagger. I wish they weren't the industry standard. I constantly battle to get stuff to work without good documentation....sorry for the rant. Thanks for the answer though! – Freddy Bonda Oct 01 '18 at 17:24
  • @FreddyBonda rendering of multiple `examples` is now available in the latest version of Swagger UI. – Helen Jul 01 '19 at 08:22
  • ...but it still does not seem to work on their [editor.swagger.io](https://editor.swagger.io/) webpage. Seems to be using version 3.0.20. – user9645 May 19 '20 at 11:05
  • @user9645 https://editor.swagger.io uses Swagger Editor v. 3.8.3 which does support multiple `examples`. If something does not work for you, [ask a new question](/questions/ask) and post an API definition (YAML or JSON) to reproduce the issue. – Helen May 19 '20 at 16:39
  • @Helen - I generated the nodejs-server download and found a file in there called VERSION which had "3.0.20" in it - I assumed that was the version... anyway - I [asked a new question](https://stackoverflow.com/q/62088926/1571426). – user9645 May 29 '20 at 15:03
  • Anyone facing issue in seeing example in the HTML generated file? Can anyone help me? I can see the example in Swagger editor, but not in HTML file. – Sach Mar 18 '22 at 07:51