0

In a openapi 3.0.0 yaml file, is it possible to reference a list of common request headers that are used in each call rather than specifying them again and again on each call?

/some-path:
  get:
    summary: "sample1"
    operationId: doWork
    description: 'description of do work'
    parameters:
      ...
      - in: header
        name: Authorization
        schema: 
          type: string
        required: true
      - in: header
        name: Consumer-Key
        schema: 
          type: string
        required: true
      - in: header
        name: Correlation-Id
        schema:
          type: string
          format: uuid
        required: true

/some-other-path:
  get:
    summary: "sample2"
    operationId: doOtherWork
    description: 'description of do other work'
    parameters:
      ...
      - in: header
        name: Authorization
        schema: 
          type: string
        required: true
      - in: header
        name: Consumer-Key
        schema: 
          type: string
        required: true
      - in: header
        name: Correlation-Id
        schema:
          type: string
          format: uuid
        required: true


i tried duplicating it.......and it works......but it is ugly as hell.

  • 1
    Define the headers at the `components` section once and reference it using `$ref` notation. – Christoph Dahlen Nov 14 '22 at 20:28
  • Note that the `Authorization` header MUST be defined as a security scheme instead of a parameter, as explained in the [linked Q&A](https://stackoverflow.com/a/44249613/113116). – Helen Nov 14 '22 at 21:11

1 Answers1

0

This may not be the answer you want. With version 3.0.3, we do something like the following:

openapi: 3.0.3

paths:
  /some-path:
    get:
      summary: "sample1"
      operationId: doWork
      description: 'description of do work'
      parameters:
        ...
        - in: header
          name: Authorization
          schema: 
            type: string
          required: true
        - in: header
          name: Consumer-Key
          schema: 
            type: string
          required: true
        - $ref: '#/components/parameters/__common__correlationId_header'

components:
  parameters:
    __common__correlationId_header:
      in: header
      name: Correlation-Id
      description: common correlation id.
      required: true
      schema:
        type: string
        format: uuid
DwB
  • 37,124
  • 11
  • 56
  • 82
  • thank you. i was looking for a single line for the collection but ill take this route any day. works well! thanks so much! – Shawzymoto Nov 15 '22 at 16:14