@@ -57,6 +57,26 @@ import java.util.concurrent.CompletableFuture;
5757
5858{ {#operations} }
5959public class { {classname} } {
60+ /**
61+ * Utility class for extending HttpRequest.Builder functionality.
62+ */
63+ private static class HttpRequestBuilderExtensions {
64+ /**
65+ * Adds additional headers to the provided HttpRequest.Builder. Useful for adding method/endpoint specific headers.
66+ *
67+ * @param builder the HttpRequest.Builder to which headers will be added
68+ * @param headers a map of header names and values to add; may be null
69+ * @return the same HttpRequest.Builder instance with the additional headers set
70+ */
71+ static HttpRequest.Builder withAdditionalHeaders(HttpRequest.Builder builder, Map< String, String> headers) {
72+ if (headers != null) {
73+ for (Map.Entry< String, String> entry : headers.entrySet()) {
74+ builder.header(entry.getKey(), entry.getValue());
75+ }
76+ }
77+ return builder;
78+ }
79+ }
6080 private final HttpClient memberVarHttpClient;
6181 private final ObjectMapper memberVarObjectMapper;
6282 private final String memberVarBaseUri;
@@ -78,6 +98,7 @@ public class {{classname}} {
7898 memberVarResponseInterceptor = apiClient.getResponseInterceptor();
7999 memberVarAsyncResponseInterceptor = apiClient.getAsyncResponseInterceptor();
80100 }
101+
81102 { {#asyncNative} }
82103
83104 private ApiException getApiException(String operationId, HttpResponse<String > response) {
@@ -177,11 +198,40 @@ public class {{classname}} {
177198 @Deprecated
178199 { {/isDeprecated} }
179200 public { {#returnType} }{ {#asyncNative} }CompletableFuture<{ {{returnType} }}>{ {/asyncNative} }{ {^asyncNative} }{ {{returnType} }}{ {/asyncNative} }{ {/returnType} }{ {^returnType} }{ {#asyncNative} }CompletableFuture<Void >{ {/asyncNative} }{ {^asyncNative} }void{ {/asyncNative} }{ {/returnType} } { {operationId} }(API{ {#lambda.titlecase} }{ {operationId} }{ {/lambda.titlecase} }Request apiRequest) throws ApiException {
201+ {{#returnType} }return { {/returnType} }{ {^returnType} }{ {#asyncNative} }return { {/asyncNative} }{ {/returnType} }{ {operationId} }(apiRequest, null);
202+ }
203+
204+ /**
205+ * { {summary} }
206+ * { {notes} }
207+ * @param apiRequest { @link API{{#lambda.titlecase} }{ {operationId} }{ {/lambda.titlecase} }Request}
208+ * @param headers Optional headers to include in the request
209+ { {#returnType} }
210+ * @return { {#asyncNative} }CompletableFuture< ; { {/asyncNative} }{ {returnType} }{ {#asyncNative} }> ; { {/asyncNative} }
211+ { {/returnType} }
212+ { {^returnType} }
213+ { {#asyncNative} }
214+ * @return CompletableFuture< ; Void> ;
215+ { {/asyncNative} }
216+ { {/returnType} }
217+ * @throws ApiException if fails to make API call
218+ { {#isDeprecated} }
219+ * @deprecated
220+ { {/isDeprecated} }
221+ { {#externalDocs} }
222+ * { {description} }
223+ * @see <a href =" { { url} } " >{ {summary} } Documentation</a >
224+ { {/externalDocs} }
225+ */
226+ { {#isDeprecated} }
227+ @Deprecated
228+ { {/isDeprecated} }
229+ public { {#returnType} }{ {#asyncNative} }CompletableFuture<{ {{returnType} }}>{ {/asyncNative} }{ {^asyncNative} }{ {{returnType} }}{ {/asyncNative} }{ {/returnType} }{ {^returnType} }{ {#asyncNative} }CompletableFuture<Void >{ {/asyncNative} }{ {^asyncNative} }void{ {/asyncNative} }{ {/returnType} } { {operationId} }(API{ {#lambda.titlecase} }{ {operationId} }{ {/lambda.titlecase} }Request apiRequest, Map<String , String > headers) throws ApiException {
180230 {{#allParams} }
181231 { {> nullable_var_annotations} }{ {! prevent indent} }
182232 { {{dataType} }} { {paramName} } = apiRequest.{ {paramName} }();
183233 { {/allParams} }
184- { {#returnType} }return { {/returnType} }{ {^returnType} }{ {#asyncNative} }return { {/asyncNative} }{ {/returnType} }{ {operationId} }({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} });
234+ { {#returnType} }return { {/returnType} }{ {^returnType} }{ {#asyncNative} }return { {/asyncNative} }{ {/returnType} }{ {operationId} }({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams } }, { {/hasParams } }headers );
185235 }
186236
187237 /**
@@ -202,10 +252,32 @@ public class {{classname}} {
202252 @Deprecated
203253 { {/isDeprecated} }
204254 public { {#asyncNative} }CompletableFuture<{ {/asyncNative} }ApiResponse<{ {{returnType} }}{ {^returnType} }Void{ {/returnType} }>{ {#asyncNative} }>{ {/asyncNative} } { {operationId} }WithHttpInfo(API{ {#lambda.titlecase} }{ {operationId} }{ {/lambda.titlecase} }Request apiRequest) throws ApiException {
255+ return {{operationId} }WithHttpInfo(apiRequest, null);
256+ }
257+
258+ /**
259+ * { {summary} }
260+ * { {notes} }
261+ * @param apiRequest { @link API{{#lambda.titlecase} }{ {operationId} }{ {/lambda.titlecase} }Request}
262+ * @param headers Optional headers to include in the request
263+ * @return { {#asyncNative} }CompletableFuture< ; { {/asyncNative} }ApiResponse< ; { {returnType} }{ {^returnType} }Void{ {/returnType} }> ; { {#asyncNative} }> ; { {/asyncNative} }
264+ * @throws ApiException if fails to make API call
265+ { {#isDeprecated} }
266+ * @deprecated
267+ { {/isDeprecated} }
268+ { {#externalDocs} }
269+ * { {description} }
270+ * @see <a href =" { { url} } " >{ {summary} } Documentation</a >
271+ { {/externalDocs} }
272+ */
273+ { {#isDeprecated} }
274+ @Deprecated
275+ { {/isDeprecated} }
276+ public { {#asyncNative} }CompletableFuture<{ {/asyncNative} }ApiResponse<{ {{returnType} }}{ {^returnType} }Void{ {/returnType} }>{ {#asyncNative} }>{ {/asyncNative} } { {operationId} }WithHttpInfo(API{ {#lambda.titlecase} }{ {operationId} }{ {/lambda.titlecase} }Request apiRequest, Map<String , String > headers) throws ApiException {
205277 {{#allParams} }
206278 { {{dataType} }} { {paramName} } = apiRequest.{ {paramName} }();
207279 { {/allParams} }
208- return { {operationId} }WithHttpInfo({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} });
280+ return { {operationId} }WithHttpInfo({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams } }, { {/hasParams } }headers );
209281 }
210282
211283 { {/hasParams} }
@@ -237,15 +309,46 @@ public class {{classname}} {
237309 @Deprecated
238310 { {/isDeprecated} }
239311 public { {#returnType} }{ {#asyncNative} }CompletableFuture<{ {{returnType} }}>{ {/asyncNative} }{ {^asyncNative} }{ {{returnType} }}{ {/asyncNative} }{ {/returnType} }{ {^returnType} }{ {#asyncNative} }CompletableFuture<Void >{ {/asyncNative} }{ {^asyncNative} }void{ {/asyncNative} }{ {/returnType} } { {operationId} }({ {#allParams} }{ {> nullable_var_annotations} } { {{dataType} }} { {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }) throws ApiException {
312+ {{#returnType} }return { {/returnType} }{ {^returnType} }{ {#asyncNative} }return { {/asyncNative} }{ {/returnType} }{ {operationId} }({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams} }, { {/hasParams} }null);
313+ }
314+
315+ /**
316+ * { {summary} }
317+ * { {notes} }
318+ { {#allParams} }
319+ * @param { {paramName} } { {description} }{ {#required} } (required){ {/required} }{ {^required} } (optional{ {^isContainer} }{ {#defaultValue} }, default to { {.} }{ {/defaultValue} }{ {/isContainer} }){ {/required} }
320+ { {/allParams} }
321+ * @param headers Optional headers to include in the request
322+ { {#returnType} }
323+ * @return { {#asyncNative} }CompletableFuture< ; { {/asyncNative} }{ {returnType} }{ {#asyncNative} }> ; { {/asyncNative} }
324+ { {/returnType} }
325+ { {^returnType} }
326+ { {#asyncNative} }
327+ * @return CompletableFuture< ; Void> ;
328+ { {/asyncNative} }
329+ { {/returnType} }
330+ * @throws ApiException if fails to make API call
331+ { {#isDeprecated} }
332+ * @deprecated
333+ { {/isDeprecated} }
334+ { {#externalDocs} }
335+ * { {description} }
336+ * @see <a href =" { { url} } " >{ {summary} } Documentation</a >
337+ { {/externalDocs} }
338+ */
339+ { {#isDeprecated} }
340+ @Deprecated
341+ { {/isDeprecated} }
342+ public { {#returnType} }{ {#asyncNative} }CompletableFuture<{ {{returnType} }}>{ {/asyncNative} }{ {^asyncNative} }{ {{returnType} }}{ {/asyncNative} }{ {/returnType} }{ {^returnType} }{ {#asyncNative} }CompletableFuture<Void >{ {/asyncNative} }{ {^asyncNative} }void{ {/asyncNative} }{ {/returnType} } { {operationId} }({ {#allParams} }{ {> nullable_var_annotations} } { {{dataType} }} { {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams} }, { {/hasParams} }Map<String , String > headers) throws ApiException {
240343 {{^asyncNative} }
241- { {#returnType} }ApiResponse<{ {{.} }}> localVarResponse = { {/returnType} }{ {operationId} }WithHttpInfo({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} });
344+ { {#returnType} }ApiResponse<{ {{.} }}> localVarResponse = { {/returnType} }{ {operationId} }WithHttpInfo({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams } }, { {/hasParams } }headers );
242345 { {#returnType} }
243346 return localVarResponse.getData();
244347 { {/returnType} }
245348 { {/asyncNative} }
246349 { {#asyncNative} }
247350 try {
248- HttpRequest.Builder localVarRequestBuilder = {{operationId} }RequestBuilder({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} });
351+ HttpRequest.Builder localVarRequestBuilder = {{operationId} }RequestBuilder({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams } }, { {/hasParams } }headers );
249352 return memberVarHttpClient.sendAsync(
250353 localVarRequestBuilder.build(),
251354 HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> {
@@ -293,8 +396,32 @@ public class {{classname}} {
293396 @Deprecated
294397 { {/isDeprecated} }
295398 public { {#asyncNative} }CompletableFuture<{ {/asyncNative} }ApiResponse<{ {{returnType} }}{ {^returnType} }Void{ {/returnType} }>{ {#asyncNative} }>{ {/asyncNative} } { {operationId} }WithHttpInfo({ {#allParams} }{ {> nullable_var_annotations} } { {{dataType} }} { {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }) throws ApiException {
399+ return {{operationId} }WithHttpInfo({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams} }, { {/hasParams} }null);
400+ }
401+
402+ /**
403+ * { {summary} }
404+ * { {notes} }
405+ { {#allParams} }
406+ * @param { {paramName} } { {description} }{ {#required} } (required){ {/required} }{ {^required} } (optional{ {^isContainer} }{ {#defaultValue} }, default to { {.} }{ {/defaultValue} }{ {/isContainer} }){ {/required} }
407+ { {/allParams} }
408+ * @param headers Optional headers to include in the request
409+ * @return { {#asyncNative} }CompletableFuture< ; { {/asyncNative} }ApiResponse< ; { {returnType} }{ {^returnType} }Void{ {/returnType} }> ; { {#asyncNative} }> ; { {/asyncNative} }
410+ * @throws ApiException if fails to make API call
411+ { {#isDeprecated} }
412+ * @deprecated
413+ { {/isDeprecated} }
414+ { {#externalDocs} }
415+ * { {description} }
416+ * @see <a href =" { { url} } " >{ {summary} } Documentation</a >
417+ { {/externalDocs} }
418+ */
419+ { {#isDeprecated} }
420+ @Deprecated
421+ { {/isDeprecated} }
422+ public { {#asyncNative} }CompletableFuture<{ {/asyncNative} }ApiResponse<{ {{returnType} }}{ {^returnType} }Void{ {/returnType} }>{ {#asyncNative} }>{ {/asyncNative} } { {operationId} }WithHttpInfo({ {#allParams} }{ {> nullable_var_annotations} } { {{dataType} }} { {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams} }, { {/hasParams} }Map<String , String > headers) throws ApiException {
296423 {{^asyncNative} }
297- HttpRequest.Builder localVarRequestBuilder = { {operationId} }RequestBuilder({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} });
424+ HttpRequest.Builder localVarRequestBuilder = { {operationId} }RequestBuilder({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams } }, { {/hasParams } }headers );
298425 try {
299426 HttpResponse< InputStream> localVarResponse = memberVarHttpClient.send(
300427 localVarRequestBuilder.build(),
@@ -386,7 +513,7 @@ public class {{classname}} {
386513 { {/asyncNative} }
387514 { {#asyncNative} }
388515 try {
389- HttpRequest.Builder localVarRequestBuilder = {{operationId} }RequestBuilder({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} });
516+ HttpRequest.Builder localVarRequestBuilder = {{operationId} }RequestBuilder({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams } }, { {/hasParams } }headers );
390517 return memberVarHttpClient.sendAsync(
391518 localVarRequestBuilder.build(),
392519 HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> {
@@ -423,7 +550,7 @@ public class {{classname}} {
423550 { {/asyncNative} }
424551 }
425552
426- private HttpRequest.Builder { {operationId} }RequestBuilder({ {#allParams} }{ {> nullable_var_annotations} } { {{dataType} }} { {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }) throws ApiException {
553+ private HttpRequest.Builder { {operationId} }RequestBuilder({ {#allParams} }{ {> nullable_var_annotations} } { {{dataType} }} { {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams } }, { {/hasParams } }Map< String , String > headers ) throws ApiException {
427554 {{#allParams} }
428555 { {#required} }
429556 // verify the required parameter '{ {paramName} }' is set
@@ -628,6 +755,8 @@ public class {{classname}} {
628755 if (memberVarReadTimeout != null) {
629756 localVarRequestBuilder.timeout(memberVarReadTimeout);
630757 }
758+ // Add custom headers if provided
759+ localVarRequestBuilder = HttpRequestBuilderExtensions.withAdditionalHeaders(localVarRequestBuilder, headers);
631760 if (memberVarInterceptor != null) {
632761 memberVarInterceptor.accept(localVarRequestBuilder);
633762 }
0 commit comments