Swagger 2.0 Examples

Swagger 2.0 Examples

Last updated:

Here are some examples on common use cases for Swagger.

You need to define attribute "enum" for the parameter in question, for example:

{
...
        "parameters": [
          {
            "in": "path",
            "name": "username",
            "type": "string",
            "default": "foo",
            "enum":["foo","bar","baz"],
            "required": true
          }
        ],
...
}

Note that if the "default" option is one of the possible values for the "enum", that option will be the default selected value in the dropdown list (on Swagger UI)

Response schema

The way your response body will look like

If you have an operation whose response is just an object with an id attribute, something like this:

{
  "id": "1c279189-f365-4e7d-b766-74c48eede894"
}

This is how you define it:

{
...
        "responses": {
          "201": {
            "description": "Created",
            "schema":{
              "type": "object",
              "properties":{
                "id" :{
                  "type":"string"
                }
              }
            }
          },
          "400":{
            "description" :"Bad request"
          },
          "403":{
            "description": "Forbidden"
          }
        }
...
}

References