Reputation: 4152
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?
Upvotes: 3
Views: 1344
Reputation: 1196
This looks like a bug in the go template: https://github.com/OpenAPITools/openapi-generator/blob/4487042f0d4ef1f4686950f0c1ddac6fe6d44f98/modules/openapi-generator/src/main/resources/go/api.mustache#L243-L252
It should be similar to how its done in the Java template: https://github.com/OpenAPITools/openapi-generator/blob/4487042f0d4ef1f4686950f0c1ddac6fe6d44f98/modules/openapi-generator/src/main/resources/Java/api.mustache#L89-L91
Upvotes: 2