Skip to content

[BUG] [GO] api.mustache template builds a client that does not correctly set header params #14578

@sokolikp

Description

@sokolikp

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Go's api.mustache template builds a Go client that adds header params as query params. The bug was introduced in this PR and still exists on the latest main branch.

openapi-generator version

This issue doesn't yet appear to be included in a release (the PR was merged on Nov 19, 2022, and the latest release was on Nov 1, 2022 [v6.2.1]).

That being said, the latest main branch includes this code. I'm using the openapi-generator-cli and docker without specifying a version and seem to be pulling in the changes from main.

OpenAPI declaration file content or url

Example yaml file with headers included:

swagger: "2.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  description: >
    A sample API that uses a petstore as an example
    to demonstrate features in the swagger-2.0 specification
consumes:
  - application/json
produces:
  - application/json
paths:
  /pets:
    get:
      description: Returns all pets from the petstore
      parameters:
        - name: X-Region
          in: header
          type: string
          required: true
      responses:
        "200":
          description: pet response
          schema:
            type: array
            items:
              $ref: "#/definitions/pet"
        default:
          description: unexpected error
          schema:
            $ref: "#/definitions/errorModel"
definitions:
  pet:
    $ref: sample/pet.yaml
  pet-owner:
    $ref: sample/pet-owner.yaml
  errorModel:
    $ref: sample/error.json
Generation Details

I'm using the openapi-generator-cli and docker to generate my Go client.

Steps to reproduce
  1. Run openapi-generator-cli with docker on an OpenAPI spec yaml file that includes headers. Pull generated client code into a Go repo.
  2. Build requests using the above generated Golang client. Requests will not set header params at all (and instead it appears they will be added to query params).
Related issues/PRs
Suggest a fix

The fix should be minor - the api.mustache template needs a few lines updated to set headers instead of query params.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions