Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 of 6 tasks
phynes-sensiblecode opened this issue Nov 22, 2022 · 4 comments

Comments

@phynes-sensiblecode
Copy link

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
@wing328
Copy link
Member

wing328 commented Dec 1, 2022

@phynes-sensiblecode thanks for reporting the issue. Here are PRs related to the Go client generator in v6.3.0 (latest master)

https://github.com/OpenAPITools/openapi-generator/pulls?q=is%3Apr+is%3Aclosed+label%3A%22Client%3A+Go%22+sort%3Aupdated-desc+milestone%3A6.3.0

I think it may be related to #13909

@phynes-sensiblecode can you please take a look to see if it's a regression? Thanks.

@phynes-sensiblecode
Copy link
Author

phynes-sensiblecode commented Dec 1, 2022

@wing328 The issue is a regression that was introduced with the changes for #13909.

The issue is present with commit 4487042f0d4ef1f4686950f0c1ddac6fe6d44f98, but things work fine on the previous commit 95b566a3a9eca70c5e7b6d48ed6bd769ff3a1669.

commit 4487042f0d4ef1f4686950f0c1ddac6fe6d44f98 (HEAD)
Author: Vittorio Parrella <[email protected]>
Date:   Sun Nov 20 02:09:33 2022 -0500

    Issue 11401 - report correctly the parameters with the deep object specification (#13909)
    
    * issue #11401 - Go client generator doesn't support deepObject in query
    
    * samples generation
    
    * fix generation
    
    * fix generation
    
    * generated samples
    
    # Conflicts:
    #       samples/client/petstore/go/go-petstore/model_200_response.go
    #       samples/client/petstore/go/go-petstore/model_additional_properties_any_type.go
    #       samples/client/petstore/go/go-petstore/model_client.go
    
    * Fixed unit tests
    
    * revert to http connection for tests
    
    * fix model_simple generation
    
    * Fix parameter encoding issue
    
    * simplified routine
    
    * fix test url
    
    * adapted for latest master, necessary generation
    
    * samples generation
    
    * sync with new master, regenerate samples
    
    * added api client test

commit 95b566a3a9eca70c5e7b6d48ed6bd769ff3a1669
Author: Oleh Kurpiak <[email protected]>
Date:   Sun Nov 20 06:44:47 2022 +0200

    [Java] fix additional annotations for oneOf interfaces (#13958)

@phynes-sensiblecode
Copy link
Author

I tried out my test case with openapitools/openapi-generator-cli:latest which has #14447.

I can see that that query parameters are no longer exploded when they shouldn't be. However, the values associated with exploded parameters are still given as reflect.Value+value:

$ go run main.go 
2023/02/02 12:43:48 
GET /v1/dummy?explode=reflect.Value+value&explode=reflect.Value+value&noexplode=n1%2Cn2 HTTP/1.1

@cooltea713705
Copy link

However, the values associated with exploded parameters are still given as reflect.Value+value:

I confirm this is still observed in version 6.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants