Forum Discussion

vitorlima1602's avatar
vitorlima1602
New Contributor
5 years ago

Send data via header using OpenApi 3 with method GET

Hello!

Would anyone know how to help me send data via header using the get method in OpenApi 3?

Code that doesn't work:

 

/version:
get:
    tags:
    - "version"
    summary: ""
    description: ""
    parameters:
    - name: "Content-Type"
      in: "header"
      description: ""
      required: true
      content:
          application / xml:
              schema:
                  type: string

 

In version 2 I can do it well.

working code:

 

get:
    tags:
    - "version"
    summary: ""
    description: ""
    produces:
    - "application / xml"
    parameters:
    - name: "Content-Type"
      in: "header"
      description: ""
      required: true
      type: "string"
    responses:
        "200":
            description: "successful operation"
        "400":
            description: "Invalid status value"

3 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi vitorlima1602,

    Can you please clarify why you need the Content-Type header in a GET request? Content-Type is used in requests that have a request body, such as POST, PUT, or PATCH. GET requests are not supposed to have a body, this is explicitly disallowed in OpenAPI 3.0.

    • vitorlima1602's avatar
      vitorlima1602
      New Contributor

      Hi.

      It is that in the company where I work, they adopted a standard of trafficking data through the header, including several GET methods are working like this, people test via postman and it works normally.

      Now they want to use the swagger accessing the routes in the same way and I don't know how to do that.

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        You can have header parameters, just not the ones named Content-Type or Accept - these headers are derived from request and response media types. Check out the Describing Parameters guide, it has some examples.