Can Swagger / Open API 2.0 declare a common response header?

Is it possible to declare a custom response header that will be present in all answers without copying it in each response structure?

+6
source share
2 answers

In accordance with section 2.3. Header Answers Writing an OpenAPI Tutorial (Swagger) - Part 5 - Advanced I / O Modeling - Answer - No. This is what I understand from specification 2.0.

Vote / comment Structural improvements: improve header processing ยท Issue No. 690 ยท OAI / OpenAPI specification .

+1
source

This has been slightly improved in OpenAPI 3.0 - now you can define common headers in the global components/headers section and then $ref these definitions instead of repeating the built-in definitions. You can also $ref entire answers (e.g. 400) to slightly reduce code duplication. However, there is still no way to set common headers for all paths - you need to explicitly specify headers in each answer.

 openapi: 3.0.1 ... paths: /: get: responses: '200': description: OK headers: X-RateLimit-Limit: $ref: '#/components/headers/X-RateLimit-Limit' X-RateLimit-Remaining: $ref: '#/components/headers/X-RateLimit-Remaining' /something: get: responses: '200': description: OK headers: X-RateLimit-Limit: $ref: '#/components/headers/X-RateLimit-Limit' X-RateLimit-Remaining: $ref: '#/components/headers/X-RateLimit-Remaining' components: headers: X-RateLimit-Limit: description: Request limit per hour schema: type: integer example: 100 X-RateLimit-Remaining: schema: type: integer example: 96 
0
source

Source: https://habr.com/ru/post/1242351/


All Articles