Skip to content

Commit 34f0d02

Browse files
authored
ISSUE-4222: Prevent conflicts with accept(s) local variables in generated Java RestTemplate ApiClient (#7101)
* ISSUE-4222: Change accept(s) to localVarAccept(s) in Java/resttemplate/api.mustache * ISSUE-4222: Regenerate samples
1 parent 7a846a1 commit 34f0d02

File tree

13 files changed

+335
-335
lines changed

13 files changed

+335
-335
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ public class {{classname}} {
134134
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}}
135135
{{/hasMore}}{{/formParams}}{{/hasFormParams}}
136136

137-
final String[] accepts = { {{#hasProduces}}
137+
final String[] localVarAccepts = { {{#hasProduces}}
138138
{{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
139-
{{/hasProduces}}};
140-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
139+
{{/hasProduces}} };
140+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
141141
final String[] contentTypes = { {{#hasConsumes}}
142142
{{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
143-
{{/hasConsumes}}};
143+
{{/hasConsumes}} };
144144
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
145145

146146
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
147147

148148
{{#returnType}}ParameterizedTypeReference<{{{returnType}}}> returnType = new ParameterizedTypeReference<{{{returnType}}}>() {};{{/returnType}}{{^returnType}}ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};{{/returnType}}
149-
return apiClient.invokeAPI(path, HttpMethod.{{httpMethod}}, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
149+
return apiClient.invokeAPI(path, HttpMethod.{{httpMethod}}, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
150150
}
151151
{{/operation}}
152152
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ public ResponseEntity<Client> call123testSpecialTagsWithHttpInfo(Client body) th
8484
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
8585
final MultiValueMap formParams = new LinkedMultiValueMap();
8686

87-
final String[] accepts = {
87+
final String[] localVarAccepts = {
8888
"application/json"
89-
};
90-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
89+
};
90+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
9191
final String[] contentTypes = {
9292
"application/json"
93-
};
93+
};
9494
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
9595

9696
String[] authNames = new String[] { };
9797

9898
ParameterizedTypeReference<Client> returnType = new ParameterizedTypeReference<Client>() {};
99-
return apiClient.invokeAPI(path, HttpMethod.PATCH, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
99+
return apiClient.invokeAPI(path, HttpMethod.PATCH, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
100100
}
101101
}

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

Lines changed: 61 additions & 61 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ public ResponseEntity<Client> testClassnameWithHttpInfo(Client body) throws Rest
8484
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
8585
final MultiValueMap formParams = new LinkedMultiValueMap();
8686

87-
final String[] accepts = {
87+
final String[] localVarAccepts = {
8888
"application/json"
89-
};
90-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
89+
};
90+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
9191
final String[] contentTypes = {
9292
"application/json"
93-
};
93+
};
9494
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
9595

9696
String[] authNames = new String[] { "api_key_query" };
9797

9898
ParameterizedTypeReference<Client> returnType = new ParameterizedTypeReference<Client>() {};
99-
return apiClient.invokeAPI(path, HttpMethod.PATCH, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
99+
return apiClient.invokeAPI(path, HttpMethod.PATCH, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
100100
}
101101
}

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,17 @@ public ResponseEntity<Void> addPetWithHttpInfo(Pet body) throws RestClientExcept
8888
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
8989
final MultiValueMap formParams = new LinkedMultiValueMap();
9090

91-
final String[] accepts = { };
92-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
91+
final String[] localVarAccepts = { };
92+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
9393
final String[] contentTypes = {
9494
"application/json", "application/xml"
95-
};
95+
};
9696
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
9797

9898
String[] authNames = new String[] { "petstore_auth" };
9999

100100
ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
101-
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
101+
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
102102
}
103103
/**
104104
* Deletes a pet
@@ -144,15 +144,15 @@ public ResponseEntity<Void> deletePetWithHttpInfo(Long petId, String apiKey) thr
144144
if (apiKey != null)
145145
headerParams.add("api_key", apiClient.parameterToString(apiKey));
146146

147-
final String[] accepts = { };
148-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
149-
final String[] contentTypes = { };
147+
final String[] localVarAccepts = { };
148+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
149+
final String[] contentTypes = { };
150150
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
151151

152152
String[] authNames = new String[] { "petstore_auth" };
153153

154154
ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
155-
return apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
155+
return apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
156156
}
157157
/**
158158
* Finds Pets by status
@@ -193,17 +193,17 @@ public ResponseEntity<List<Pet>> findPetsByStatusWithHttpInfo(List<String> statu
193193

194194
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "status", status));
195195

196-
final String[] accepts = {
196+
final String[] localVarAccepts = {
197197
"application/xml", "application/json"
198-
};
199-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
200-
final String[] contentTypes = { };
198+
};
199+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
200+
final String[] contentTypes = { };
201201
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
202202

203203
String[] authNames = new String[] { "petstore_auth" };
204204

205205
ParameterizedTypeReference<List<Pet>> returnType = new ParameterizedTypeReference<List<Pet>>() {};
206-
return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
206+
return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
207207
}
208208
/**
209209
* Finds Pets by tags
@@ -246,17 +246,17 @@ public ResponseEntity<Set<Pet>> findPetsByTagsWithHttpInfo(Set<String> tags) thr
246246

247247
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "tags", tags));
248248

249-
final String[] accepts = {
249+
final String[] localVarAccepts = {
250250
"application/xml", "application/json"
251-
};
252-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
253-
final String[] contentTypes = { };
251+
};
252+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
253+
final String[] contentTypes = { };
254254
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
255255

256256
String[] authNames = new String[] { "petstore_auth" };
257257

258258
ParameterizedTypeReference<Set<Pet>> returnType = new ParameterizedTypeReference<Set<Pet>>() {};
259-
return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
259+
return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
260260
}
261261
/**
262262
* Find pet by ID
@@ -300,17 +300,17 @@ public ResponseEntity<Pet> getPetByIdWithHttpInfo(Long petId) throws RestClientE
300300
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
301301
final MultiValueMap formParams = new LinkedMultiValueMap();
302302

303-
final String[] accepts = {
303+
final String[] localVarAccepts = {
304304
"application/xml", "application/json"
305-
};
306-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
307-
final String[] contentTypes = { };
305+
};
306+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
307+
final String[] contentTypes = { };
308308
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
309309

310310
String[] authNames = new String[] { "api_key" };
311311

312312
ParameterizedTypeReference<Pet> returnType = new ParameterizedTypeReference<Pet>() {};
313-
return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
313+
return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
314314
}
315315
/**
316316
* Update an existing pet
@@ -352,17 +352,17 @@ public ResponseEntity<Void> updatePetWithHttpInfo(Pet body) throws RestClientExc
352352
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
353353
final MultiValueMap formParams = new LinkedMultiValueMap();
354354

355-
final String[] accepts = { };
356-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
355+
final String[] localVarAccepts = { };
356+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
357357
final String[] contentTypes = {
358358
"application/json", "application/xml"
359-
};
359+
};
360360
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
361361

362362
String[] authNames = new String[] { "petstore_auth" };
363363

364364
ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
365-
return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
365+
return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
366366
}
367367
/**
368368
* Updates a pet in the store with form data
@@ -410,17 +410,17 @@ public ResponseEntity<Void> updatePetWithFormWithHttpInfo(Long petId, String nam
410410
if (status != null)
411411
formParams.add("status", status);
412412

413-
final String[] accepts = { };
414-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
413+
final String[] localVarAccepts = { };
414+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
415415
final String[] contentTypes = {
416416
"application/x-www-form-urlencoded"
417-
};
417+
};
418418
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
419419

420420
String[] authNames = new String[] { "petstore_auth" };
421421

422422
ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
423-
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
423+
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
424424
}
425425
/**
426426
* uploads an image
@@ -469,19 +469,19 @@ public ResponseEntity<ModelApiResponse> uploadFileWithHttpInfo(Long petId, Strin
469469
if (file != null)
470470
formParams.add("file", new FileSystemResource(file));
471471

472-
final String[] accepts = {
472+
final String[] localVarAccepts = {
473473
"application/json"
474-
};
475-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
474+
};
475+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
476476
final String[] contentTypes = {
477477
"multipart/form-data"
478-
};
478+
};
479479
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
480480

481481
String[] authNames = new String[] { "petstore_auth" };
482482

483483
ParameterizedTypeReference<ModelApiResponse> returnType = new ParameterizedTypeReference<ModelApiResponse>() {};
484-
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
484+
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
485485
}
486486
/**
487487
* uploads an image (required)
@@ -535,18 +535,18 @@ public ResponseEntity<ModelApiResponse> uploadFileWithRequiredFileWithHttpInfo(L
535535
if (requiredFile != null)
536536
formParams.add("requiredFile", new FileSystemResource(requiredFile));
537537

538-
final String[] accepts = {
538+
final String[] localVarAccepts = {
539539
"application/json"
540-
};
541-
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
540+
};
541+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
542542
final String[] contentTypes = {
543543
"multipart/form-data"
544-
};
544+
};
545545
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
546546

547547
String[] authNames = new String[] { "petstore_auth" };
548548

549549
ParameterizedTypeReference<ModelApiResponse> returnType = new ParameterizedTypeReference<ModelApiResponse>() {};
550-
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
550+
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, contentType, authNames, returnType);
551551
}
552552
}

0 commit comments

Comments
 (0)