How to define an operation with both body and header parameters in OpenAPI 2.0?

Viewed 392

How can a OpenAPI 2.0 (Swagger 2.0) definition have a body and a header parameter in the same operation? I tried the following:

  /image-correction:
    post:
      operationId: image-correction_create
      tags:
        - image-corrections
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: requestBody
          description: imageCorrection
          schema:
            $ref: '#/definitions/ImageCorrection'
        - in: header
          name: X-Request-ID
          schema:
            type: string
            format: uuid
          required: true

but Swagger Editor shows an error:

should NOT have additional properties additionalProperty: schema

1 Answers

In OpenAPI 2.0, header, query, and path parameters do not use schema, they use type directly. Change your header parameter as follows:

    - in: header
      name: X-Request-ID
      type: string     # <----
      format: uuid     # <----
      required: true

This was changed in OpenAPI 3.0 (openapi: 3.0.0) where all parameter types use schema.

Related