Skip to content

Commit 9ba34b2

Browse files
authored
[Java] parameterize formParams (#5784)
* parameterize formParams fixes #5782 * sync generated code * update to latest version of spring, replace MultiValueMap#put with #addAll, remove unused imports * restore java.util.HashMap import * update spring version in pom/gradle templates * re-generate resttemplate samples * fix test * fix test * parameterize an additional usage of LinkedMultiValueMap * re-generate resttemplate samples * re-generate webclient samples * manually edit FILES to replace \ with /
1 parent a1484da commit 9ba34b2

File tree

128 files changed

+738
-787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+738
-787
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/api.mustache

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {{invokerPackage}}.ApiClient;
55
{{#imports}}import {{import}};
66
{{/imports}}
77

8-
{{^fullJavaUtil}}import java.util.ArrayList;
9-
import java.util.Collections;
8+
{{^fullJavaUtil}}import java.util.Collections;
109
import java.util.HashMap;
1110
import java.util.List;
1211
import java.util.Locale;
@@ -19,7 +18,6 @@ import org.springframework.util.LinkedMultiValueMap;
1918
import org.springframework.util.MultiValueMap;
2019
import org.springframework.web.client.RestClientException;
2120
import org.springframework.web.client.HttpClientErrorException;
22-
import org.springframework.web.util.UriComponentsBuilder;
2321
import org.springframework.core.ParameterizedTypeReference;
2422
import org.springframework.core.io.FileSystemResource;
2523
import org.springframework.http.HttpHeaders;
@@ -117,7 +115,7 @@ public class {{classname}} {
117115
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
118116
final HttpHeaders headerParams = new HttpHeaders();
119117
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
120-
final MultiValueMap formParams = new LinkedMultiValueMap();{{#hasQueryParams}}
118+
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();{{#hasQueryParams}}
121119

122120
{{#queryParams}}queryParams.putAll(apiClient.parameterToMultiValueMap({{#collectionFormat}}ApiClient.CollectionFormat.valueOf("{{{collectionFormat}}}".toUpperCase(Locale.ROOT)){{/collectionFormat}}{{^collectionFormat}}null{{/collectionFormat}}, "{{baseName}}", {{paramName}}));{{#hasMore}}
123121
{{/hasMore}}{{/queryParams}}{{/hasQueryParams}}{{#hasHeaderParams}}
@@ -131,7 +129,7 @@ public class {{classname}} {
131129
{{/hasMore}}{{/cookieParams}}{{/hasCookieParams}}{{#hasFormParams}}
132130

133131
{{#formParams}}if ({{paramName}} != null)
134-
formParams.{{^collectionFormat}}add{{/collectionFormat}}{{#collectionFormat}}put{{/collectionFormat}}("{{baseName}}", {{#isFile}}{{^collectionFormat}}{{#useAbstractionForFiles}}{{paramName}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}new FileSystemResource({{paramName}}){{/useAbstractionForFiles}}{{/collectionFormat}}{{/isFile}}{{#isFile}}{{#collectionFormat}}{{paramName}}.stream(){{^useAbstractionForFiles}}.map(FileSystemResource::new){{/useAbstractionForFiles}}.collect(Collectors.toList()){{/collectionFormat}}{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}});{{#hasMore}}
132+
formParams.{{^collectionFormat}}add{{/collectionFormat}}{{#collectionFormat}}addAll{{/collectionFormat}}("{{baseName}}", {{#isFile}}{{^collectionFormat}}{{#useAbstractionForFiles}}{{paramName}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}new FileSystemResource({{paramName}}){{/useAbstractionForFiles}}{{/collectionFormat}}{{/isFile}}{{#isFile}}{{#collectionFormat}}{{paramName}}.stream(){{^useAbstractionForFiles}}.map(FileSystemResource::new){{/useAbstractionForFiles}}.collect(Collectors.toList()){{/collectionFormat}}{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}});{{#hasMore}}
135133
{{/hasMore}}{{/formParams}}{{/hasFormParams}}
136134

137135
final String[] localVarAccepts = { {{#hasProduces}}

modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/build.gradle.mustache

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if(hasProperty('target') && target == 'android') {
2424
2525
apply plugin: 'com.android.library'
2626
apply plugin: 'com.github.dcendents.android-maven'
27-
27+
2828
android {
2929
compileSdkVersion 23
3030
buildToolsVersion '23.0.2'
@@ -48,7 +48,7 @@ if(hasProperty('target') && target == 'android') {
4848
{{/java8}}
4949
{{/supportJava6}}
5050
}
51-
51+
5252
// Rename the aar correctly
5353
libraryVariants.all { variant ->
5454
variant.outputs.each { output ->
@@ -64,7 +64,7 @@ if(hasProperty('target') && target == 'android') {
6464
provided 'javax.annotation:jsr250-api:1.0'
6565
}
6666
}
67-
67+
6868
afterEvaluate {
6969
android.libraryVariants.all { variant ->
7070
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
@@ -76,12 +76,12 @@ if(hasProperty('target') && target == 'android') {
7676
artifacts.add('archives', task);
7777
}
7878
}
79-
79+
8080
task sourcesJar(type: Jar) {
8181
from android.sourceSets.main.java.srcDirs
8282
classifier = 'sources'
8383
}
84-
84+
8585
artifacts {
8686
archives sourcesJar
8787
}
@@ -111,7 +111,7 @@ if(hasProperty('target') && target == 'android') {
111111
pom.artifactId = '{{artifactId}}'
112112
}
113113
}
114-
114+
115115
task execute(type:JavaExec) {
116116
main = System.getProperty('mainClass')
117117
classpath = sourceSets.main.runtimeClasspath
@@ -123,7 +123,7 @@ ext {
123123
jackson_version = "2.10.4"
124124
jackson_databind_version = "2.10.4"
125125
jackson_databind_nullable_version = "0.2.1"
126-
spring_web_version = "4.3.9.RELEASE"
126+
spring_web_version = "5.2.5.RELEASE"
127127
jodatime_version = "2.9.9"
128128
junit_version = "4.13"
129129
{{#threetenbp}}
@@ -135,6 +135,7 @@ dependencies {
135135
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
136136
compile "com.google.code.findbugs:jsr305:3.0.2"
137137
compile "org.springframework:spring-web:$spring_web_version"
138+
compile "org.springframework:spring-context:$spring_web_version"
138139
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
139140
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
140141
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"

modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pom.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
<artifactId>swagger-annotations</artifactId>
223223
<version>${swagger-annotations-version}</version>
224224
</dependency>
225-
225+
226226
<!-- @Nullable annotation -->
227227
<dependency>
228228
<groupId>com.google.code.findbugs</groupId>
@@ -236,6 +236,11 @@
236236
<artifactId>spring-web</artifactId>
237237
<version>${spring-web-version}</version>
238238
</dependency>
239+
<dependency>
240+
<groupId>org.springframework</groupId>
241+
<artifactId>spring-context</artifactId>
242+
<version>${spring-web-version}</version>
243+
</dependency>
239244

240245
<!-- JSON processing: jackson -->
241246
<dependency>
@@ -317,7 +322,7 @@
317322
<properties>
318323
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
319324
<swagger-annotations-version>1.5.22</swagger-annotations-version>
320-
<spring-web-version>4.3.9.RELEASE</spring-web-version>
325+
<spring-web-version>5.2.5.RELEASE</spring-web-version>
321326
<jackson-version>2.10.4</jackson-version>
322327
<jackson-databind-version>2.10.4</jackson-databind-version>
323328
<jackson-databind-nullable-version>0.2.1</jackson-databind-nullable-version>

modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public class ApiClient {
492492
*/
493493
protected BodyInserter<?, ? super ClientHttpRequest> selectBody(Object obj, MultiValueMap<String, Object> formParams, MediaType contentType) {
494494
if(MediaType.APPLICATION_FORM_URLENCODED.equals(contentType)) {
495-
MultiValueMap<String, String> map = new LinkedMultiValueMap();
495+
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
496496
497497
formParams
498498
.toSingleValueMap()

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ public void testRestTemplateFormMultipart() throws IOException {
872872
TestUtils.assertFileContains(defaultApi,
873873
//multiple files
874874
"multipartArrayWithHttpInfo(List<File> files)",
875-
"formParams.put(\"files\", files.stream().map(FileSystemResource::new).collect(Collectors.toList()));",
875+
"formParams.addAll(\"files\", files.stream().map(FileSystemResource::new).collect(Collectors.toList()));",
876876

877877
//mixed
878878
"multipartMixedWithHttpInfo(File file, MultipartMixedMarker marker)",
@@ -960,7 +960,7 @@ public void testRestTemplateWithUseAbstractionForFiles() throws IOException {
960960
//multiple files
961961
"multipartArray(java.util.Collection<org.springframework.core.io.Resource> files)",
962962
"multipartArrayWithHttpInfo(java.util.Collection<org.springframework.core.io.Resource> files)",
963-
"formParams.put(\"files\", files.stream().collect(Collectors.toList()));",
963+
"formParams.addAll(\"files\", files.stream().collect(Collectors.toList()));",
964964

965965
//mixed
966966
"multipartMixed(org.springframework.core.io.Resource file, MultipartMixedMarker marker)",

samples/client/petstore/java/resttemplate-withXml/build.gradle

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if(hasProperty('target') && target == 'android') {
2424

2525
apply plugin: 'com.android.library'
2626
apply plugin: 'com.github.dcendents.android-maven'
27-
27+
2828
android {
2929
compileSdkVersion 23
3030
buildToolsVersion '23.0.2'
@@ -36,7 +36,7 @@ if(hasProperty('target') && target == 'android') {
3636
sourceCompatibility JavaVersion.VERSION_1_7
3737
targetCompatibility JavaVersion.VERSION_1_7
3838
}
39-
39+
4040
// Rename the aar correctly
4141
libraryVariants.all { variant ->
4242
variant.outputs.each { output ->
@@ -52,7 +52,7 @@ if(hasProperty('target') && target == 'android') {
5252
provided 'javax.annotation:jsr250-api:1.0'
5353
}
5454
}
55-
55+
5656
afterEvaluate {
5757
android.libraryVariants.all { variant ->
5858
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
@@ -64,12 +64,12 @@ if(hasProperty('target') && target == 'android') {
6464
artifacts.add('archives', task);
6565
}
6666
}
67-
67+
6868
task sourcesJar(type: Jar) {
6969
from android.sourceSets.main.java.srcDirs
7070
classifier = 'sources'
7171
}
72-
72+
7373
artifacts {
7474
archives sourcesJar
7575
}
@@ -87,7 +87,7 @@ if(hasProperty('target') && target == 'android') {
8787
pom.artifactId = 'petstore-resttemplate-withxml'
8888
}
8989
}
90-
90+
9191
task execute(type:JavaExec) {
9292
main = System.getProperty('mainClass')
9393
classpath = sourceSets.main.runtimeClasspath
@@ -99,7 +99,7 @@ ext {
9999
jackson_version = "2.10.4"
100100
jackson_databind_version = "2.10.4"
101101
jackson_databind_nullable_version = "0.2.1"
102-
spring_web_version = "4.3.9.RELEASE"
102+
spring_web_version = "5.2.5.RELEASE"
103103
jodatime_version = "2.9.9"
104104
junit_version = "4.13"
105105
jackson_threeten_version = "2.9.10"
@@ -109,6 +109,7 @@ dependencies {
109109
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
110110
compile "com.google.code.findbugs:jsr305:3.0.2"
111111
compile "org.springframework:spring-web:$spring_web_version"
112+
compile "org.springframework:spring-context:$spring_web_version"
112113
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
113114
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
114115
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"

samples/client/petstore/java/resttemplate-withXml/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
<artifactId>swagger-annotations</artifactId>
204204
<version>${swagger-annotations-version}</version>
205205
</dependency>
206-
206+
207207
<!-- @Nullable annotation -->
208208
<dependency>
209209
<groupId>com.google.code.findbugs</groupId>
@@ -217,6 +217,11 @@
217217
<artifactId>spring-web</artifactId>
218218
<version>${spring-web-version}</version>
219219
</dependency>
220+
<dependency>
221+
<groupId>org.springframework</groupId>
222+
<artifactId>spring-context</artifactId>
223+
<version>${spring-web-version}</version>
224+
</dependency>
220225

221226
<!-- JSON processing: jackson -->
222227
<dependency>
@@ -275,7 +280,7 @@
275280
<properties>
276281
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
277282
<swagger-annotations-version>1.5.22</swagger-annotations-version>
278-
<spring-web-version>4.3.9.RELEASE</spring-web-version>
283+
<spring-web-version>5.2.5.RELEASE</spring-web-version>
279284
<jackson-version>2.10.4</jackson-version>
280285
<jackson-databind-version>2.10.4</jackson-databind-version>
281286
<jackson-databind-nullable-version>0.2.1</jackson-databind-nullable-version>

samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/api/AnotherFakeApi.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import org.openapitools.client.model.Client;
66

7-
import java.util.ArrayList;
87
import java.util.Collections;
98
import java.util.HashMap;
109
import java.util.List;
@@ -18,7 +17,6 @@
1817
import org.springframework.util.MultiValueMap;
1918
import org.springframework.web.client.RestClientException;
2019
import org.springframework.web.client.HttpClientErrorException;
21-
import org.springframework.web.util.UriComponentsBuilder;
2220
import org.springframework.core.ParameterizedTypeReference;
2321
import org.springframework.core.io.FileSystemResource;
2422
import org.springframework.http.HttpHeaders;
@@ -82,7 +80,7 @@ public ResponseEntity<Client> call123testSpecialTagsWithHttpInfo(Client body) th
8280
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
8381
final HttpHeaders headerParams = new HttpHeaders();
8482
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
85-
final MultiValueMap formParams = new LinkedMultiValueMap();
83+
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
8684

8785
final String[] localVarAccepts = {
8886
"application/json"

0 commit comments

Comments
 (0)