How to reference response components in OpenAPI?

Viewed 838

I am writing an OpenAPI definition for my API. I am using components for responses, but Swagger Editor shows an error when I try to reference these components:

enter image description here

What is the correct way to reference response components?

1 Answers

The correct way to reference response components is:

responses:
  '400':
    $ref: '#/components/responses/400'
  '401':
    $ref: '#/components/responses/401'

That is, responses is a map (not an array/list) where the keys are HTTP status codes and the values are response definitions.

Related