Search code examples
syntaxopenapi

Can OpenAPI specify what the endpoint returns right in the paths responses itself?


Per https://swagger.io/docs/specification/describing-responses/,
a typical endpoint responses specification is:

paths:
  /ping:
    get:
      responses:
        '200':
          description: OK
          content:
            text/plain:
              schema:
                type: string
                example: pong

The pong is put into the example section.

Is there any way I can define such fixed response in OpenAPI specification itself?


Solution

  • You can limit your string response to an enum of values

    paths:
      /ping:
        get:
          responses:
            '200':
              description: OK
              content:
                text/plain:
                  schema:
                    type: string
                    enum:
                      - pong
                    example: pong