@@ -57,6 +57,26 @@ import java.util.concurrent.CompletableFuture;
57
57
58
58
{ {#operations} }
59
59
public 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
+ }
60
80
private final HttpClient memberVarHttpClient;
61
81
private final ObjectMapper memberVarObjectMapper;
62
82
private final String memberVarBaseUri;
@@ -78,6 +98,7 @@ public class {{classname}} {
78
98
memberVarResponseInterceptor = apiClient.getResponseInterceptor();
79
99
memberVarAsyncResponseInterceptor = apiClient.getAsyncResponseInterceptor();
80
100
}
101
+
81
102
{ {#asyncNative} }
82
103
83
104
private ApiException getApiException(String operationId, HttpResponse<String > response) {
@@ -177,11 +198,40 @@ public class {{classname}} {
177
198
@Deprecated
178
199
{ {/isDeprecated} }
179
200
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 {
180
230
{{#allParams} }
181
231
{ {> nullable_var_annotations} }{ {! prevent indent} }
182
232
{ {{dataType} }} { {paramName} } = apiRequest.{ {paramName} }();
183
233
{ {/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 );
185
235
}
186
236
187
237
/**
@@ -202,10 +252,32 @@ public class {{classname}} {
202
252
@Deprecated
203
253
{ {/isDeprecated} }
204
254
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 {
205
277
{{#allParams} }
206
278
{ {{dataType} }} { {paramName} } = apiRequest.{ {paramName} }();
207
279
{ {/allParams} }
208
- return { {operationId} }WithHttpInfo({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} });
280
+ return { {operationId} }WithHttpInfo({ {#allParams} }{ {paramName} }{ {^-last} }, { {/-last} }{ {/allParams} }{ {#hasParams } }, { {/hasParams } }headers );
209
281
}
210
282
211
283
{ {/hasParams} }
@@ -237,15 +309,46 @@ public class {{classname}} {
237
309
@Deprecated
238
310
{ {/isDeprecated} }
239
311
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 {
240
343
{{^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 );
242
345
{ {#returnType} }
243
346
return localVarResponse.getData();
244
347
{ {/returnType} }
245
348
{ {/asyncNative} }
246
349
{ {#asyncNative} }
247
350
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 );
249
352
return memberVarHttpClient.sendAsync(
250
353
localVarRequestBuilder.build(),
251
354
HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> {
@@ -293,8 +396,32 @@ public class {{classname}} {
293
396
@Deprecated
294
397
{ {/isDeprecated} }
295
398
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 {
296
423
{{^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 );
298
425
try {
299
426
HttpResponse< InputStream> localVarResponse = memberVarHttpClient.send(
300
427
localVarRequestBuilder.build(),
@@ -386,7 +513,7 @@ public class {{classname}} {
386
513
{ {/asyncNative} }
387
514
{ {#asyncNative} }
388
515
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 );
390
517
return memberVarHttpClient.sendAsync(
391
518
localVarRequestBuilder.build(),
392
519
HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> {
@@ -423,7 +550,7 @@ public class {{classname}} {
423
550
{ {/asyncNative} }
424
551
}
425
552
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 {
427
554
{{#allParams} }
428
555
{ {#required} }
429
556
// verify the required parameter '{ {paramName} }' is set
@@ -628,6 +755,8 @@ public class {{classname}} {
628
755
if (memberVarReadTimeout != null) {
629
756
localVarRequestBuilder.timeout(memberVarReadTimeout);
630
757
}
758
+ // Add custom headers if provided
759
+ localVarRequestBuilder = HttpRequestBuilderExtensions.withAdditionalHeaders(localVarRequestBuilder, headers);
631
760
if (memberVarInterceptor != null) {
632
761
memberVarInterceptor.accept(localVarRequestBuilder);
633
762
}
0 commit comments