Home >Backend Development >Golang >OpenApi Generator Golang - Adding header to request ending in query parameters how to fix?
php Editor Banana encountered a problem when using OpenApi Generator Golang: when ending the request in query parameters, how to add headers to fix this problem. In this article, we will explore the solution to this problem and provide some practical tips and steps to help readers solve similar problems. Whether you are a beginner or an experienced developer, this article will provide you with valuable information and guidance. Let’s take a look at how to fix this problem!
I'm trying to generate a go client, but the generator doesn't recognize the header and won't let me pass it to the server as a header - instead, it's as a query parameter send.
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
This is the generator I'm 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 that it generates this line, which adds the header value I passed to the query parameter:
parameterAddToQuery(localVarQueryParams, "X-Request-ID", r.xRequestID, "")
Is this a bug? What can I do about this?
This looks like a bug in go templates: https://www.php.cn/link/88d25099b103efd638163ecb40a55589
It should be similar to how it is done in Java templates: https://www.php.cn/link/227bd2473d68947040e511b7f29ce553
The above is the detailed content of OpenApi Generator Golang - Adding header to request ending in query parameters how to fix?. For more information, please follow other related articles on the PHP Chinese website!