Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #14089
Closed
Open
Issue created Nov 22, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Go] Latest Go client generator incorrectly handles explode keyword for query parameters

Created by: phynes-sensiblecode

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

In v6.2.1 exploded and unexploded query parameter lists are handled correctly by the Go client generator. This is an example of a URL that has been created by an example client. explode is a query parameter with explode=true. noexplode is a query parameter with explode=false:

/v1/dummy?explode=e1&explode=e2&noexplode=n1%2Cn2

The same code generates this URL with the latest Docker image. The unexploded parameter list is exploded, whilst the exploded parameter list has reflect.Value value for each supplied value:

/v1/dummy?explode=reflect.Value+value&explode=reflect.Value+value&noexplode=n1&noexplode=n2
openapi-generator version

Works as expected in v6.2.1. Bug observed with latest Docker image (uploaded to DockerHub on Nov 20, 2022 at 9:15 am).

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Explode demo
  version: 1.0.0
servers:
  - url: http://api.example.com/v1
paths:
  /dummy:
    get:
      summary: Dummy endpoint.
      description: Dummy endpoint to highlight explode.
      parameters:
        - name: explode
          in: query
          description: Parameters that should be exploded.
          explode: true
          schema:
            type: array
            items:
              type: string
        - name: noexplode
          in: query
          description: Parameters that should not be exploded
          explode: false
          schema:
            type: array
            items:
              type: string
      responses:
        '200':    # status code
          description: Dummy response
Generation Details

Generated client using Docker image:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate -i /local/explode.yaml -g go -o /local/out/go
Steps to reproduce

I used a main.go based on an auto-generated example in out/go/docs/DefaultApi.md. configuration.Debug is set to true to enable printing of URLs:

package main

import (
	"context"
	"fmt"
	"os"

	openapiclient "example.com/autogen/openapi"
)

func main() {
	explode := []string{"e1", "e2"}   // []string | Parameters that should be exploded. (optional)
	noexplode := []string{"n1", "n2"} // []string | Parameters that should not be exploded (optional)

	configuration := openapiclient.NewConfiguration()
	configuration.Debug = true

	apiClient := openapiclient.NewAPIClient(configuration)
	r, err := apiClient.DefaultApi.DummyGet(context.Background()).Explode(explode).Noexplode(noexplode).Execute()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `DefaultApi.DummyGet``: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}
}

I used the replace keyword in the go.mod file to point to the autogenerated client library:

replace example.com/autogen/openapi => ./out/go

Building and running main.go shows the malformed URL. The actual query fails due to using a dummy host.

$ go run main.go 
2022/11/22 11:33:27 
GET /v1/dummy?explode=reflect.Value+value&explode=reflect.Value+value&noexplode=n1&noexplode=n2 HTTP/1.1
...

Rebuilding the client with latest-release version of Docker image results in correct URL:

$ go run main.go 
2022/11/22 11:29:33 
GET /v1/dummy?explode=e1&explode=e2&noexplode=n1%2Cn2 HTTP/1.1
...
Related issues/PRs

Can't find any.

Suggest a fix
Assignee
Assign to
Time tracking