Nickydonna
Nickydonna

Reputation: 802

Swagger: Use an specific value in the response object

I'm creating API docs with swagger and I can't find the way to represent an specific value in a response.

For example when there is a 404 error in the API, the response is like this:

{
    "code": 404,
    "result": "payment.notfound"
}

The value will always be 404, how can this be expressed in swagger.

Thanks!!

Upvotes: 3

Views: 1424

Answers (1)

fehguy
fehguy

Reputation: 6824

You can like this:

/paths:
  /foo:
    /get:
      parameters: []
      responses:
        200:
          description: it worked
        404:
          description: "it didn't work"
          schema:
            type: object
            properties:
              code:
                type: integer
                format: int32
              result:
                type: string

If you really want to say that result can only, ever be the string payment.notfound, you can simply set an enum:

result:
  type: string
  enum:
    - "payment.notfound"

which means, "it's a string but can only be this value, ever".

Upvotes: 4

Related Questions