How to specify examples of GET parameters in Swagger?

I use the Swagger Online Editor to create the Swagger specification for my API.

My API has one GET request endpoint, and I use the following YAML code to describe the input parameters:

paths:
  /fooBar:
    get:
      tags:
        - foobar
      summary: ''
      description: ''
      operationId: foobar
      consumes:
        - application/x-www-form-urlencoded
      produces:
        - application/json
      parameters:
        - name: address
          in: query
          description: Address to be foobared
          required: true
          type: string
          example: 123, FakeStreet
        - name: city
          in: query
          description: City of the Address
          required: true
          type: string
          example: New York

If I put in a tag example, I get an error:

is not exactly one of the <# / definitions / parameters>, <# / definitions / jsonReference>

How to set an example when writing GET parameters to Swagger?

+14
source share
1 answer

Openapi 2.0

OpenAPI/Swagger 2.0 example , . description . , Swagger UI v2, v3. 12+ Dredd, x-example :

      parameters:
        - name: address
          in: query
          description: Address to be foobared. Example: '123, FakeStreet'.  # <-----
          required: true
          type: string
          x-example: 123, FakeStreet   # <-----

OpenAPI 3.0

OpenAPI 3.0:

      parameters:
        - name: address
          in: query
          description: Address to be foobared
          required: true
          schema:
            type: string
            example: 123, FakeStreet   # <----
          example: 456, AnotherStreet  # Overrides schema-level example
+24

Source: https://habr.com/ru/post/1017198/


All Articles