go – OpenApi Generator Golang – Adding headers to request ending up in query params how to fix?

I’m trying to generate a go client but the generator won’t recognise a header and won’t let me pass it to the server as a header – instead it’s sent as a query param.

info:
  title: API
  version: "1.2"
servers:
  - url: https://example.com
paths:
  /ping:
    get:
      summary: Checks if the server is alive
      parameters:
        - in: header
          name: X-Request-ID
          schema:
            type: string
            format: uuid
          required: true
      responses:
        '200':
          description: Request has been successful
          content:
            application/json:
              schema:
                type: object
                properties:
                  returned_url:
                    type: string

And here is the generator I am using:

# https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/go.md
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
  -i /local/spec.yaml \
  -g go \
  -o /local/internal/infrastructure/sdk \
  -p enumClassPrefix=true \
  -p generateInterfaces=true \
  -p isGoSubmodule=true \
  -p packageName=sdk

You’ll notice it generates this line which adds the value of the header I pass to the query params:

parameterAddToQuery(localVarQueryParams, "X-Request-ID", r.xRequestID, "")

Is this a bug? What can I do about this?

Read more here: Source link