Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define a set/list of responses for reusage in open api? [duplicate]

Currently I have something like this:

paths: 
    /home
...
      responses:
        200:
          description: Successful operation
        401:
          $ref: '#/components/responses/401UnauthorizedDefault'
        404:
          $ref: '#/components/responses/404NotFound'
        502:
          $ref: '#/components/responses/502BadGatewayDefault'
    /sign_up
...
      responses:
        201:
          description: Created
        401:
          $ref: '#/components/responses/401UnauthorizedDefault'
        404:
          $ref: '#/components/responses/404NotFound'
        502:
          $ref: '#/components/responses/502BadGatewayDefault'

Is it possible to combine all three error responses and reference them with a $ref?

paths:
    /home
...
      responses:
        200:
          description: Successful operation
        $ref: '#/components/responses/AllCommonErrorResponses’
    /sign_up
...
      responses:
        201:
          description: Created
        $ref: '#/components/responses/AllCommonErrorResponses’

Currently I dont know all the error responses we will use. But there will be a set of shared. If we will extend them later, I dont want to go to every endpoint and adjust the responses.

like image 465
sg_rs Avatar asked Oct 17 '25 17:10

sg_rs


1 Answers

OpenAPI v3 does not allow to reference a list of multiple responses.

You can use specific (e.g., "200") response codes or default for others.

There is no option to import a standard list of responses and reuse it.

like image 175
KarelHusa Avatar answered Oct 21 '25 12:10

KarelHusa