OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Go] Free-form query parameters are not serialized correctly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Go client's parameterAddToHeaderOrQuery function and reproduce the free-form query parameter example described in the issue. Compare the requested form serialization with the observed deepObject-style output; done means a map such as {"search":"something"} produces ?search=something, with a focused regression test for the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100