Skip to content

Commit

Permalink
allow headers overrides in jersey2 - PLUS 88fb6710
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Aug 8, 2024
1 parent e34685e commit a2fceee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/resources/handlebars/Java/libraries/jersey2/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.util.Map;
{{#operations}}
public class {{classname}} {
private ApiClient {{localVariablePrefix}}apiClient;
private Map<String, String> headers;

public {{classname}}() {
this(Configuration.getDefaultApiClient());
Expand All @@ -43,6 +44,10 @@ public class {{classname}} {
this.{{localVariablePrefix}}apiClient = apiClient;
}

public void setHeadersOverrides(Map<String, String> headers) {
this.headers = headers;
}

{{#operation}}
{{#contents}}
/**
Expand Down Expand Up @@ -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}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import java.util.Map;
{{#operations}}
public class {{classname}} {
private ApiClient {{localVariablePrefix}}apiClient;
private Map<String, String> headers;

public {{classname}}() {
this(Configuration.getDefaultApiClient());
Expand All @@ -75,6 +76,10 @@ public class {{classname}} {
this.{{localVariablePrefix}}apiClient = apiClient;
}

public void setHeadersOverrides(Map<String, String> headers) {
this.headers = headers;
}

{{#operation}}
{{#contents}}
/**
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit a2fceee

Please sign in to comment.