Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
collectionFormat = CollectionFormat.CSV;
}

if (value instanceof Map) {
final Map<String, Object> valuesMap = (Map<String, Object>) value;
for (final Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(entry.getKey(), parameterToString(entry.getValue()));
}
return params;
}

Collection<?> valueCollection = null;
if (value instanceof Collection) {
valueCollection = (Collection<?>) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,14 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
collectionFormat = CollectionFormat.CSV;
}

if (value instanceof Map) {
final Map<String, Object> valuesMap = (Map<String, Object>) value;
for (final Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(entry.getKey(), parameterToString(entry.getValue()));
}
return params;
}

Collection<?> valueCollection = null;
if (value instanceof Collection) {
valueCollection = (Collection<?>) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,4 +1164,62 @@ public void testWebClientWithUseAbstractionForFiles() throws IOException {
"formParams.add(\"file\", file);"
);
}

/**
* See https://github.com/OpenAPITools/openapi-generator/issues/8352
*/
@Test
public void testRestTemplateWithFreeFormInQueryParameters() throws IOException {
final Map<String, Object> properties = new HashMap<>();
properties.put(AbstractJavaCodegen.JAVA8_MODE, true);
properties.put(CodegenConstants.API_PACKAGE, "xyz.abcdef.api");

final File output = Files.createTempDirectory("test")
.toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("java")
.setLibrary(JavaClientCodegen.RESTTEMPLATE)
.setAdditionalProperties(properties)
.setInputSpec("src/test/resources/3_0/issue8352.yaml")
.setOutputDir(output.getAbsolutePath()
.replace("\\", "/"));

final DefaultGenerator generator = new DefaultGenerator();
final List<File> files = generator.opts(configurator.toClientOptInput())
.generate();
files.forEach(File::deleteOnExit);

final Path defaultApi = Paths.get(output + "/src/main/java/xyz/abcdef/ApiClient.java");
TestUtils.assertFileContains(defaultApi, "value instanceof Map");
}

/**
* See https://github.com/OpenAPITools/openapi-generator/issues/8352
*/
@Test
public void testWebClientWithFreeFormInQueryParameters() throws IOException {
final Map<String, Object> properties = new HashMap<>();
properties.put(AbstractJavaCodegen.JAVA8_MODE, true);
properties.put(CodegenConstants.API_PACKAGE, "xyz.abcdef.api");

final File output = Files.createTempDirectory("test")
.toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("java")
.setLibrary(JavaClientCodegen.WEBCLIENT)
.setAdditionalProperties(properties)
.setInputSpec("src/test/resources/3_0/issue8352.yaml")
.setOutputDir(output.getAbsolutePath()
.replace("\\", "/"));

final DefaultGenerator generator = new DefaultGenerator();
final List<File> files = generator.opts(configurator.toClientOptInput())
.generate();
files.forEach(File::deleteOnExit);

final Path defaultApi = Paths.get(output + "/src/main/java/xyz/abcdef/ApiClient.java");
TestUtils.assertFileContains(defaultApi, "value instanceof Map");
}
}
18 changes: 18 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue8352.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
openapi: 3.0.0
info:
title: test handle of free form query parameters
version: 0.0.1
servers:
- url: "http://localhost"
paths:
/some/endpoint:
get:
parameters:
- in: "query"
name: "free-form"
schema:
type: "object"
style: "form"
responses:
200:
description: "test"
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ public MultiValueMap<String, String> parameterToMultiValueMap(CollectionFormat c
collectionFormat = CollectionFormat.CSV;
}

if (value instanceof Map) {
final Map<String, Object> valuesMap = (Map<String, Object>) value;
for (final Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(entry.getKey(), parameterToString(entry.getValue()));
}
return params;
}

Collection<?> valueCollection = null;
if (value instanceof Collection) {
valueCollection = (Collection<?>) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ public MultiValueMap<String, String> parameterToMultiValueMap(CollectionFormat c
collectionFormat = CollectionFormat.CSV;
}

if (value instanceof Map) {
final Map<String, Object> valuesMap = (Map<String, Object>) value;
for (final Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(entry.getKey(), parameterToString(entry.getValue()));
}
return params;
}

Collection<?> valueCollection = null;
if (value instanceof Collection) {
valueCollection = (Collection<?>) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ public MultiValueMap<String, String> parameterToMultiValueMap(CollectionFormat c
collectionFormat = CollectionFormat.CSV;
}

if (value instanceof Map) {
final Map<String, Object> valuesMap = (Map<String, Object>) value;
for (final Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(entry.getKey(), parameterToString(entry.getValue()));
}
return params;
}

Collection<?> valueCollection = null;
if (value instanceof Collection) {
valueCollection = (Collection<?>) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ public MultiValueMap<String, String> parameterToMultiValueMap(CollectionFormat c
collectionFormat = CollectionFormat.CSV;
}

if (value instanceof Map) {
final Map<String, Object> valuesMap = (Map<String, Object>) value;
for (final Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(entry.getKey(), parameterToString(entry.getValue()));
}
return params;
}

Collection<?> valueCollection = null;
if (value instanceof Collection) {
valueCollection = (Collection<?>) value;
Expand Down