OpenApi Generator Golang - Adding header to request ending in query parameters how to fix?

王林
Release: 2024-02-10 08:42:21
forward
1165 people have browsed it

OpenApi Generator Golang - 添加标头以在查询参数中结束的请求如何修复?

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!

Question content

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
Copy after login

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
Copy after login

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, "")
Copy after login

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

Workaround

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!