Forum Discussion

jtfidje's avatar
jtfidje
New Member
5 years ago

Swagger responses - Multiple response codes with the same schema?

Hi!

Is it possible to have multiple codes use the same schema without duplicating the schema-reference?

I.e.:

responses:
    '202':
        description: OK
    '401':
    '403':
    '404':
        $ref: "#/components/responses/HTTPError"
    'default':
        $ref: "#/components/responses/ApplicationError"
 
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    In OpenAPI 3.0 you can use ranges such as "2XX", "3XX", "4XX" instead of individual status codes:

    responses:
        '202':
            description: OK
        '4XX':  # <-------
            $ref: "#/components/responses/HTTPError"
        'default':
            $ref: "#/components/responses/ApplicationError"