cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger responses - Multiple response codes with the same schema?

Highlighted
New Member

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"
 
1 REPLY 1
Highlighted
Moderator

Re: Swagger responses - Multiple response codes with the same schema?

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"

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors