[BUG] [Java] Client resttemplate and webclient. Form Params are badly added when they are lists
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
Plugin will generate DefaultApi.java
and when the element to be inserted to formParams is a list ... instead of an formParams.addAll
it makes an formParams.add
openapi-generator version
4.1.3, 4.2.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: My Api
version: 0.0.1
paths:
/api/v1/article/id/exist:
post:
description: my endpoint
operationId: checkArticle
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
articleIds:
description: article ids
type: array
items:
type: integer
format: int32
responses:
200:
description: successful operation
content:
application/json:
schema:
type: integer
Command line used for generation
java -jar openapi-generator-cli.jar generate -g java -i openapi-rest.yml -o openapi --library resttemplate
Steps to reproduce
Run the above command.
Actual
/**
*
* my endpoint
* <p><b>200</b> - successful operation
* @param articleIds article ids (optional)
* @return ResponseEntity<Integer>
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public ResponseEntity<Integer> checkArticleWithHttpInfo(List<Integer> articleIds) throws RestClientException {
//...
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
if (articleIds != null)
formParams.add("articleIds", articleIds);
//...
}
Expected:
/**
*
* my endpoint
* <p><b>200</b> - successful operation
* @param articleIds article ids (optional)
* @return ResponseEntity<Integer>
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public ResponseEntity<Integer> checkArticleWithHttpInfo(List<Integer> articleIds) throws RestClientException {
//...
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
if (articleIds != null)
formParams.addAll("articleIds", articleIds);
//...
}