[BUG] [Java]: Client resttemplate and webclient: array parameters of type integer in path badly generated
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
Java-client resttemplate and webclient generator generates code that does not compile when yaml contains array parameters of type integer in the path.
openapi-generator version
4.1.3,4.2.0
OpenAPI declaration file content or url
.openapi-rest.yml
openapi: 3.0.2
info:
title: My-api
version: 0.1.0
paths:
/articles/{ids}:
get:
summary: Find articles by article ids
description: Retrieve articles from their ids.
operationId: articles
parameters:
- name: ids
description: article ids separated by commas
in: path
required: true
schema:
type: array
items:
type: integer
responses:
'200':
description: OK
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.
Generated code does not compile because apiClient.collectionPathParameterToString
wait Collection<? extends CharSequence>
and ids
is a list of integers.
Output: .DefaultApi.java
/**
* Find articles by article ids
* Retrieve articles from their ids.
* <p><b>200</b> - OK
* @param ids article ids separated by commas
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public void getArticles(List<Integer> ids) throws RestClientException {
//...
// create path and map variables
final Map<String, Object> uriVariables = new HashMap<String, Object>();
uriVariables.put("ids", apiClient.collectionPathParameterToString(ApiClient.CollectionFormat.valueOf("csv".toUpperCase()), ids));
//...
}
.ApiClient.java
/**
* Formats the specified collection path parameter to a string value.
*
* @param collectionFormat The collection format of the parameter.
* @param values The values of the parameter.
* @return String representation of the parameter
*/
public String collectionPathParameterToString(CollectionFormat collectionFormat, Collection<? extends CharSequence> values) {
//...
}