How to reference headers in response
See original GitHub issueI am trying to figure out a way to reuse headers in response. The documentation and google isn’t helping much. I am wondering if this is even possible to include headers inside response using $ref.
My response is defined as below. In the successful response my Api returns pagination information in headers. This pagination headers are used in many places, I want to reuse them so that i don’t duplicate lot of YAML code.
Following is my attempt at trying this without any luck.
responses:
'200':
description: Successful Request
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
headers:
- $ref: '#/components/headers/X-Total-Items'
- $ref: '#/components/headers/X-Total-Pages'
components
headers:
X-Total-Items
schema:
type: integer
description: test
X-Total-Pages
schema:
type: integer
description: test
Is this the right way?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
HTTP headers - MDN Web Docs - Mozilla
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its ......
Read more >HTTP Response reference | WebStorm Documentation
The response object holds the information about a received HTTP Response (response content, headers, status, and so on) and provides access ...
Read more >Request headers and responses - App Engine - Google Cloud
Use this reference page for details about what HTTP headers are supported as well as the request and response limits in App Engine....
Read more >Common Response Headers - Amazon Simple Storage Service
Common Response Headers ; Content-Length. The length in bytes of the body in the response. Type: String. Default: None ; Content-Type. The MIME...
Read more >List of HTTP header fields - Wikipedia
HTTP header fields are a list of strings sent and received by both the client program and server on every HTTP request and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @john1452 the thing to spot is that the
headers
field of the Response Object is a Map (of Header objects or References), not an array.Your example should look something like:
I have modified the names of the reusable header components to indicate clearly which is used as the actual header name, though they can of course be the same.
Sorry, didn’t spot that. The header object has a description field of its own. Try moving the descriptions out of the schema objects (i.e. one level up).