Ivy Green
Ivy Green

Reputation: 33

Swagger.io / OpenAPI - How to reuse complete code blocks

I have status codes from the server that keep repeating in the documentation:

responses:
    '204':
      $ref: '#/components/responses/204'
    '400':
      $ref: '#/components/responses/400'
    '401':
      $ref: '#/components/responses/401'
    '402':
      $ref: '#/components/responses/402'
    '403':
      $ref: '#/components/responses/403'
    '404': 
      $ref: '#/components/responses/404'
    '426':
      $ref: '#/components/responses/426'
    '429':
      $ref: '#/components/responses/429'

How can I use Swagger.io's OpenAPI to lay a reference so that I only have one short line at a time, example:

responses:
    $ref: '#/components/responses/defaultCodes'

And is it also possible to expand the list with "allOf"?

responses:
    allOf:
    - '200':
      $ref: '#/components/responses/200'
    - $ref: '#/components/responses/defaultCodes'

Thank you very much for your help : )

Upvotes: 3

Views: 436

Answers (1)

Helen
Helen

Reputation: 97677

This is not supported.

Here are the related feature requests in the OpenAPI Specification repository:

Upvotes: 2

Related Questions