OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][webclient] query param of type array handled as non explode
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
Wrapping query params in a containing object so that the generated client method only has one param instead of X params, but when the query param is an array, the generated code always builds a CSV with the contents of the array, instead of handling it as "multi".
openapi-generator version
It's not a regression. Wrapping object were supported after 7.2.0 thanks to this PR but it is not working correctly when having array properties.
OpenAPI declaration file content or url
paths:
/api/search:
get:
operationId: Search
parameters:
- name: object-param
in: query
required: true
schema:
type: object
properties:
someArray:
type: array
items:
type: string
- The example is an adaptation from
modules/openapi-generator/src/test/resources/3_0/java/explode-query-parameter.yaml
Generation Details
Java language, WebClient library, but also with RestTemplate.
Steps to reproduce
By adapting the upper mentioned file, execute the following test
JavaClientCodegenTest.shouldProperlyExplodeWebClientQueryParameters
adding
.bodyContainsLines("queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf(\"multi\".toUpperCase(Locale.ROOT)), \"someArray\"," + " objectParam.getSomeArray()));");
Expected would be to handle the array query param as "multi" since explode defaults to true.
Actual: it's treated as csv because the collectionFormat param is null.
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/17441
Suggest a fix
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 modules/openapi-generator/src/test/resources/3_0/java/explode-query-parameter.yaml and run JavaClientCodegenTest.shouldProperlyExplodeWebClientQueryParameters for the WebClient and RestTemplate cases. Update the handling so the someArray query parameter uses multi when explode defaults to true, then verify the generated output contains the expected parameterToMultiValueMap call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100