Search code examples
swaggerswagger-editor

How do I add a list of possible values to a swagger doc?


Suppose I have the following route:

paths:
  /data:
    get:
      summary: Get list of securities based on filter
      parameters:
        - name: market
          in: query
          description: Filter securities by market id, default ```all```
          type: string
          default: all

How can I add to this, a list of values that can be used?

Is this even supported? I see an enum field but I keep getting errors when adding to any param.


Solution

  • enum is the way to go. You can specify a list of values under enum for parameter and property. Following is a an example:

    ---
    swagger: '2.0'
    info:
      version: 0.0.0
      title: Simple API
    paths:
      /data:
        get:
          summary: Get list of securities based on filter
          parameters:
            - name: market
              in: query
              description: Filter securities by market id, default ```all```
              type: string
              default: all
              enum:
              - all
              - market1
              - market2
          responses:
            200:
              description: OK
    

    You can copy and paste above to swagger-editor to see the output.