Skip to content

Commit f1d05fc

Browse files
Allow Java apache-httpclient users to supply additional HTTP headers per call, updated (#14929)
* Allow Java apache-httpclient users to supply additional HTTP headers per API call * fix 'unexpected return value' problem * make "fullJavaUtil" work * Revert 'make "fullJavaUtil" work' This reverts commit 60c8846. --------- Co-authored-by: Jigar Joshi <jigarjm@gmail.com>
1 parent b172f62 commit f1d05fc

File tree

13 files changed

+948
-0
lines changed

13 files changed

+948
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {{invokerPackage}}.Pair;
1515

1616
{{^fullJavaUtil}}
1717
import java.util.ArrayList;
18+
import java.util.Collections;
1819
import java.util.HashMap;
1920
import java.util.List;
2021
import java.util.Map;
@@ -24,6 +25,8 @@ import java.util.StringJoiner;
2425
{{>generatedAnnotation}}
2526
{{#operations}}
2627
public class {{classname}} {
28+
29+
2730
private ApiClient apiClient;
2831
2932
public {{classname}}() {
@@ -65,6 +68,33 @@ public class {{classname}} {
6568
@Deprecated
6669
{{/isDeprecated}}
6770
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException {
71+
{{#returnType}}return {{/returnType}}this.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}Collections.emptyMap());
72+
}
73+
74+
75+
/**
76+
* {{summary}}
77+
* {{notes}}
78+
{{#allParams}}
79+
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/isContainer}}{{/required}}
80+
{{/allParams}}
81+
* @param additionalHeaders additionalHeaders for this call
82+
{{#returnType}}
83+
* @return {{returnType}}
84+
{{/returnType}}
85+
* @throws ApiException if fails to make API call
86+
{{#isDeprecated}}
87+
* @deprecated
88+
{{/isDeprecated}}
89+
{{#externalDocs}}
90+
* {{description}}
91+
* @see <a href="{{url}}">{{summary}} Documentation</a>
92+
{{/externalDocs}}
93+
*/
94+
{{#isDeprecated}}
95+
@Deprecated
96+
{{/isDeprecated}}
97+
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}Map<String, String> additionalHeaders) throws ApiException {
6898
Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
6999
{{#allParams}}{{#required}}
70100
// verify the required parameter '{{paramName}}' is set
@@ -126,6 +156,8 @@ public class {{classname}} {
126156
localVarHeaderParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
127157
{{/headerParams}}
128158

159+
localVarHeaderParams.putAll(additionalHeaders);
160+
129161
{{#cookieParams}}if ({{paramName}} != null)
130162
localVarCookieParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
131163
{{/cookieParams}}
@@ -168,6 +200,7 @@ public class {{classname}} {
168200
{{#returnType}}localVarReturnType{{/returnType}}{{^returnType}}null{{/returnType}}
169201
);
170202
}
203+
171204
{{/operation}}
172205
}
173206
{{/operations}}

samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/BodyApi.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424

2525

2626
import java.util.ArrayList;
27+
import java.util.Collections;
2728
import java.util.HashMap;
2829
import java.util.List;
2930
import java.util.Map;
3031
import java.util.StringJoiner;
3132

3233
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
3334
public class BodyApi {
35+
36+
3437
private ApiClient apiClient;
3538

3639
public BodyApi() {
@@ -57,6 +60,19 @@ public void setApiClient(ApiClient apiClient) {
5760
* @throws ApiException if fails to make API call
5861
*/
5962
public Pet testEchoBodyPet(Pet pet) throws ApiException {
63+
return this.testEchoBodyPet(pet, Collections.emptyMap());
64+
}
65+
66+
67+
/**
68+
* Test body parameter(s)
69+
* Test body parameter(s)
70+
* @param pet Pet object that needs to be added to the store (optional)
71+
* @param additionalHeaders additionalHeaders for this call
72+
* @return Pet
73+
* @throws ApiException if fails to make API call
74+
*/
75+
public Pet testEchoBodyPet(Pet pet, Map<String, String> additionalHeaders) throws ApiException {
6076
Object localVarPostBody = pet;
6177

6278
// create path and map variables
@@ -71,6 +87,8 @@ public Pet testEchoBodyPet(Pet pet) throws ApiException {
7187
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
7288

7389

90+
localVarHeaderParams.putAll(additionalHeaders);
91+
7492

7593

7694
final String[] localVarAccepts = {
@@ -102,6 +120,7 @@ public Pet testEchoBodyPet(Pet pet) throws ApiException {
102120
localVarReturnType
103121
);
104122
}
123+
105124
/**
106125
* Test empty response body
107126
* Test empty response body
@@ -110,6 +129,19 @@ public Pet testEchoBodyPet(Pet pet) throws ApiException {
110129
* @throws ApiException if fails to make API call
111130
*/
112131
public String testEchoBodyPetResponseString(Pet pet) throws ApiException {
132+
return this.testEchoBodyPetResponseString(pet, Collections.emptyMap());
133+
}
134+
135+
136+
/**
137+
* Test empty response body
138+
* Test empty response body
139+
* @param pet Pet object that needs to be added to the store (optional)
140+
* @param additionalHeaders additionalHeaders for this call
141+
* @return String
142+
* @throws ApiException if fails to make API call
143+
*/
144+
public String testEchoBodyPetResponseString(Pet pet, Map<String, String> additionalHeaders) throws ApiException {
113145
Object localVarPostBody = pet;
114146

115147
// create path and map variables
@@ -124,6 +156,8 @@ public String testEchoBodyPetResponseString(Pet pet) throws ApiException {
124156
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
125157

126158

159+
localVarHeaderParams.putAll(additionalHeaders);
160+
127161

128162

129163
final String[] localVarAccepts = {
@@ -155,4 +189,5 @@ public String testEchoBodyPetResponseString(Pet pet) throws ApiException {
155189
localVarReturnType
156190
);
157191
}
192+
158193
}

samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/FormApi.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323

2424

2525
import java.util.ArrayList;
26+
import java.util.Collections;
2627
import java.util.HashMap;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.StringJoiner;
3031

3132
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
3233
public class FormApi {
34+
35+
3336
private ApiClient apiClient;
3437

3538
public FormApi() {
@@ -58,6 +61,21 @@ public void setApiClient(ApiClient apiClient) {
5861
* @throws ApiException if fails to make API call
5962
*/
6063
public String testFormIntegerBooleanString(Integer integerForm, Boolean booleanForm, String stringForm) throws ApiException {
64+
return this.testFormIntegerBooleanString(integerForm, booleanForm, stringForm, Collections.emptyMap());
65+
}
66+
67+
68+
/**
69+
* Test form parameter(s)
70+
* Test form parameter(s)
71+
* @param integerForm (optional)
72+
* @param booleanForm (optional)
73+
* @param stringForm (optional)
74+
* @param additionalHeaders additionalHeaders for this call
75+
* @return String
76+
* @throws ApiException if fails to make API call
77+
*/
78+
public String testFormIntegerBooleanString(Integer integerForm, Boolean booleanForm, String stringForm, Map<String, String> additionalHeaders) throws ApiException {
6179
Object localVarPostBody = null;
6280

6381
// create path and map variables
@@ -72,6 +90,8 @@ public String testFormIntegerBooleanString(Integer integerForm, Boolean booleanF
7290
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
7391

7492

93+
localVarHeaderParams.putAll(additionalHeaders);
94+
7595

7696
if (integerForm != null)
7797
localVarFormParams.put("integer_form", integerForm);
@@ -109,4 +129,5 @@ public String testFormIntegerBooleanString(Integer integerForm, Boolean booleanF
109129
localVarReturnType
110130
);
111131
}
132+
112133
}

samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/HeaderApi.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323

2424

2525
import java.util.ArrayList;
26+
import java.util.Collections;
2627
import java.util.HashMap;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.StringJoiner;
3031

3132
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
3233
public class HeaderApi {
34+
35+
3336
private ApiClient apiClient;
3437

3538
public HeaderApi() {
@@ -58,6 +61,21 @@ public void setApiClient(ApiClient apiClient) {
5861
* @throws ApiException if fails to make API call
5962
*/
6063
public String testHeaderIntegerBooleanString(Integer integerHeader, Boolean booleanHeader, String stringHeader) throws ApiException {
64+
return this.testHeaderIntegerBooleanString(integerHeader, booleanHeader, stringHeader, Collections.emptyMap());
65+
}
66+
67+
68+
/**
69+
* Test header parameter(s)
70+
* Test header parameter(s)
71+
* @param integerHeader (optional)
72+
* @param booleanHeader (optional)
73+
* @param stringHeader (optional)
74+
* @param additionalHeaders additionalHeaders for this call
75+
* @return String
76+
* @throws ApiException if fails to make API call
77+
*/
78+
public String testHeaderIntegerBooleanString(Integer integerHeader, Boolean booleanHeader, String stringHeader, Map<String, String> additionalHeaders) throws ApiException {
6179
Object localVarPostBody = null;
6280

6381
// create path and map variables
@@ -78,6 +96,8 @@ public String testHeaderIntegerBooleanString(Integer integerHeader, Boolean bool
7896
if (stringHeader != null)
7997
localVarHeaderParams.put("string_header", apiClient.parameterToString(stringHeader));
8098

99+
localVarHeaderParams.putAll(additionalHeaders);
100+
81101

82102

83103
final String[] localVarAccepts = {
@@ -109,4 +129,5 @@ public String testHeaderIntegerBooleanString(Integer integerHeader, Boolean bool
109129
localVarReturnType
110130
);
111131
}
132+
112133
}

samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/api/PathApi.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323

2424

2525
import java.util.ArrayList;
26+
import java.util.Collections;
2627
import java.util.HashMap;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.StringJoiner;
3031

3132
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
3233
public class PathApi {
34+
35+
3336
private ApiClient apiClient;
3437

3538
public PathApi() {
@@ -57,6 +60,20 @@ public void setApiClient(ApiClient apiClient) {
5760
* @throws ApiException if fails to make API call
5861
*/
5962
public String testsPathStringPathStringIntegerPathInteger(String pathString, Integer pathInteger) throws ApiException {
63+
return this.testsPathStringPathStringIntegerPathInteger(pathString, pathInteger, Collections.emptyMap());
64+
}
65+
66+
67+
/**
68+
* Test path parameter(s)
69+
* Test path parameter(s)
70+
* @param pathString (required)
71+
* @param pathInteger (required)
72+
* @param additionalHeaders additionalHeaders for this call
73+
* @return String
74+
* @throws ApiException if fails to make API call
75+
*/
76+
public String testsPathStringPathStringIntegerPathInteger(String pathString, Integer pathInteger, Map<String, String> additionalHeaders) throws ApiException {
6077
Object localVarPostBody = null;
6178

6279
// verify the required parameter 'pathString' is set
@@ -83,6 +100,8 @@ public String testsPathStringPathStringIntegerPathInteger(String pathString, Int
83100
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
84101

85102

103+
localVarHeaderParams.putAll(additionalHeaders);
104+
86105

87106

88107
final String[] localVarAccepts = {
@@ -114,4 +133,5 @@ public String testsPathStringPathStringIntegerPathInteger(String pathString, Int
114133
localVarReturnType
115134
);
116135
}
136+
117137
}

0 commit comments

Comments
 (0)