From 0c5872a905a84c153e54a2773390cc8ed4f82157 Mon Sep 17 00:00:00 2001 From: frantuma Date: Thu, 1 Aug 2024 14:42:38 +0200 Subject: [PATCH] jersey2 allow headers overrides - PLUS 498cef428 --- .../resources/Java/libraries/jersey2/api.mustache | 15 +++++++++++++++ .../Java/libraries/okhttp-gson/api.mustache | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache index d5db80321b2..e620519e227 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache @@ -27,6 +27,7 @@ import java.util.Map; {{#operations}} public class {{classname}} { private ApiClient {{localVariablePrefix}}apiClient; + private Map headers; public {{classname}}() { this(Configuration.getDefaultApiClient()); @@ -44,6 +45,10 @@ public class {{classname}} { this.{{localVariablePrefix}}apiClient = apiClient; } + public void setHeadersOverrides(Map headers) { + this.headers = headers; + } + {{#operation}} /** * {{summary}} @@ -138,8 +143,18 @@ public class {{classname}} { {{#returnType}} GenericType<{{{returnType}}}> {{localVariablePrefix}}localVarReturnType = new GenericType<{{{returnType}}}>() {}; + + if (headers != null) { + localVarHeaderParams.putAll(headers); + } + return {{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}localVarPath, "{{httpMethod}}", {{localVariablePrefix}}localVarQueryParams, {{localVariablePrefix}}localVarPostBody, {{localVariablePrefix}}localVarHeaderParams, {{localVariablePrefix}}localVarFormParams, {{localVariablePrefix}}localVarAccept, {{localVariablePrefix}}localVarContentType, {{localVariablePrefix}}localVarAuthNames, {{localVariablePrefix}}localVarReturnType); {{/returnType}}{{^returnType}} + + if (headers != null) { + localVarHeaderParams.putAll(headers); + } + return {{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}localVarPath, "{{httpMethod}}", {{localVariablePrefix}}localVarQueryParams, {{localVariablePrefix}}localVarPostBody, {{localVariablePrefix}}localVarHeaderParams, {{localVariablePrefix}}localVarFormParams, {{localVariablePrefix}}localVarAccept, {{localVariablePrefix}}localVarContentType, {{localVariablePrefix}}localVarAuthNames, null); {{/returnType}} } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache index 3986e598944..4a7a3c6cd9a 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache @@ -58,6 +58,7 @@ import java.util.Map; {{#operations}} public class {{classname}} { private ApiClient {{localVariablePrefix}}apiClient; + private Map headers; public {{classname}}() { this(Configuration.getDefaultApiClient()); @@ -75,6 +76,10 @@ public class {{classname}} { this.{{localVariablePrefix}}apiClient = apiClient; } + public void setHeadersOverrides(Map headers) { + this.headers = headers; + } + {{#operation}} /** * Build call for {{operationId}}{{#allParams}} @@ -139,6 +144,9 @@ public class {{classname}} { } String[] {{localVariablePrefix}}localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; + if (headers != null) { + localVarHeaderParams.putAll(headers); + } return {{localVariablePrefix}}apiClient.buildCall({{localVariablePrefix}}localVarPath, "{{httpMethod}}", {{localVariablePrefix}}localVarQueryParams, {{localVariablePrefix}}localVarCollectionQueryParams, {{localVariablePrefix}}localVarPostBody, {{localVariablePrefix}}localVarHeaderParams, {{localVariablePrefix}}localVarFormParams, {{localVariablePrefix}}localVarAuthNames, progressRequestListener); }