OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.23k stars 6.43k forks source link

[BUG] [Go] Free-form query parameters are not serialized correctly #15946

Open ctreatma opened 1 year ago

ctreatma commented 1 year ago

Bug Report Checklist

Description

The OpenAPI 3.x schema describes a way to specify arbitrary query parameters using "free-form query parameters" (the linked page doesn't have good anchors so you'll have to search for the quoted text on that page to see the example in situ).

Given the following example from the page linked above:

in: query
name: freeForm
schema:
  type: object
  additionalProperties:
    type: string
style: form

If I generate a Go client and use that client to send a request with freeForm := map[string]string{"search":"something"}, the client should send a request to the API that looks roughly like this:

https://example.com/api/endpoint?search=something

but instead the client sends a request that looks like this:

https://example.com/api/endpoint?freeForm[search]=something.

Based on the OpenAPI specification for serializing query parameters it appears that generated Go clients use deepObject-style serialization for query parameters that are objects, even if a different serialization (in this case, form) is specified.

openapi-generator version

v6.6.0

OpenAPI declaration file content or url

TODO: Working on filling in the remaining fields but wanted to get the issue filed sooner rather than later.

Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

TODO but I think this would be localized to the generated parameterAddToHeaderOrQuery function

ctreatma commented 1 year ago

Updated external documentation links. Previous links went to 3.1 docs; updated links show the relevant parts of the 3.0.x specification.

xwangbolt commented 1 year ago

+1