question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reference Response headers Open API v3.0

See original GitHub issue

I’ve been experimenting trying to break my large file into smaller and easier to handle files. I may be completely miss understanding part of the documentation where it says Headers can be a reference object.

But how come this doesn’t validate in the 3.0.

 /Account:
    parameters:
    - $ref: #/components/parameters/userAgent
    - $ref: #/components/parameters/installationID
    get:
      tags:
      - Account
      summary: Gets a list of Accounts
      description: Returns a list containing all Accounts. The list supports paging.
      operationId: listAccounts
      responses:
        200:
          description: A list of AchAccount
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Accounts'
          headers:
            $ref: #/components/responses/DefaultHeaders/headers
        500:
          $ref: #/components/responses/StandardErrorResponse
        default:
          $ref: #/components/responses/TotallyUnexpectedResponse
      parameters:
      - $ref: #/components/parameters/offline_filter
      - $ref: #/components/parameters/limit_filter
      - $ref: #/components/parameters/page_filter

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
hkosovacommented, May 22, 2018

headers is a map of header names to response header definitions (aka Header Objects). The “value” of a header name can be an inline definition, or a $ref to a definition stored elsewhere (either in the current file or an external file). Within the current OpenAPI document, response headers can be stored in the #/components/headers section.

Note that you can only $ref individual headers but not the entire headers section.

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'

components:
  headers:
    X-RateLimit-Limit:
      description: Request limit per hour
      schema:
        type: integer
      example: 100
    X-RateLimit-Remaining:
      schema:
        type: integer
      example: 94

Hope this helps!

4reactions
hkosovacommented, Feb 19, 2019

@bolshoydi you can’t, you can only $ref individual response headers - as shown in the example. However, there are existing feature requests to improve header reuse: Share header with multiple response objects Structural improvements: enhance headers handling

Read more comments on GitHub >

github_iconTop Results From Across the Web

Describing Responses - Swagger
OAS 3 This guide is for OpenAPI 3.0. ... A response is defined by its HTTP status code and the data returned in...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >
OpenAPI 3.0 Domain Example | SwaggerHub Documentation
Below is an example of an OpenAPI 3.0 domain definition ... OpenAPI version identifier - required for OpenAPI 3.0 domains openapi: 3.0.0 ......
Read more >
How to define header parameters in OpenAPI 3.0?
But in Swagger 3.0.0 parameters are replaced by request bodies. This is only true for form and body parameters. Other parameter types (path, ......
Read more >
Working with OpenAPI definitions for HTTP APIs
You can define your HTTP API by using an OpenAPI 3.0 definition file. Then you can import the definition into API Gateway to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found