diff --git a/src/main/resources/handlebars/Java/libraries/jersey2/api.mustache b/src/main/resources/handlebars/Java/libraries/jersey2/api.mustache index 6e0dda863e..826a2c618e 100644 --- a/src/main/resources/handlebars/Java/libraries/jersey2/api.mustache +++ b/src/main/resources/handlebars/Java/libraries/jersey2/api.mustache @@ -26,6 +26,7 @@ import java.util.Map; {{#operations}} public class {{classname}} { private ApiClient {{localVariablePrefix}}apiClient; + private Map headers; public {{classname}}() { this(Configuration.getDefaultApiClient()); @@ -43,6 +44,10 @@ public class {{classname}} { this.{{localVariablePrefix}}apiClient = apiClient; } + public void setHeadersOverrides(Map headers) { + this.headers = headers; + } + {{#operation}} {{#contents}} /** @@ -114,8 +119,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); + } + {{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/src/main/resources/handlebars/Java/libraries/okhttp-gson/api.mustache b/src/main/resources/handlebars/Java/libraries/okhttp-gson/api.mustache index b1033181f5..ff1785a32f 100644 --- a/src/main/resources/handlebars/Java/libraries/okhttp-gson/api.mustache +++ b/src/main/resources/handlebars/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}} {{#contents}} /** @@ -138,6 +143,9 @@ public class {{classname}} { } String[] {{localVariablePrefix}}localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{#has this 'more'}}, {{/has}}{{/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); }