Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript-axios] [Java] Respect User Supplied Header Params #20032

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/configs/typescript-axios-with-complex-headers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ generatorName: typescript-axios
outputDir: samples/client/petstore/typescript-axios/builds/with-complex-headers
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-complex-headers.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-axios
additionalProperties:
npmVersion: 1.0.0
npmName: '@openapitools/typescript-axios-petstore'
npmRepository: https://skimdb.npmjs.com/registry
snapshot: false
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ public class {{classname}} {

{{/isQueryParam}}
{{/constantParams}}
{{#headerParams}}
if ({{paramName}} != null) {
localVarHeaderParams.put("{{baseName}}", localVarApiClient.parameterToString({{paramName}}));
}

{{/headerParams}}
{{#constantParams}}
{{#isHeaderParam}}
// Set client side default value of Header Param "{{baseName}}".
Expand Down Expand Up @@ -230,6 +224,13 @@ public class {{classname}} {
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}
{{#headerParams}}

if ({{paramName}} != null) {
localVarHeaderParams.put("{{baseName}}", localVarApiClient.parameterToString({{paramName}}));
}

{{/headerParams}}

String[] localVarAuthNames = new String[] { {{#withAWSV4Signature}}"AWS4Auth"{{/withAWSV4Signature}}{{#authMethods}}{{#-first}}{{#withAWSV4Signature}}, {{/withAWSV4Signature}}{{/-first}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} };
return localVarApiClient.buildCall(basePath, localVarPath, {{^dynamicOperations}}"{{httpMethod}}"{{/dynamicOperations}}{{#dynamicOperations}}apiOperation.getMethod(){{/dynamicOperations}}, localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,34 +156,6 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
{{/isArray}}

{{/queryParams}}
{{#headerParams}}
{{#isArray}}
if ({{paramName}}) {
{{#uniqueItems}}
let mapped = Array.from({{paramName}}).map(value => (<any>"{{{dataType}}}" !== "Set<string>") ? JSON.stringify(value) : (value || ""));
{{/uniqueItems}}
{{^uniqueItems}}
let mapped = {{paramName}}.map(value => (<any>"{{{dataType}}}" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
{{/uniqueItems}}
localVarHeaderParameter['{{baseName}}'] = mapped.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
}
{{/isArray}}
{{^isArray}}
{{! `val == null` covers for both `null` and `undefined`}}
if ({{paramName}} != null) {
{{#isString}}
localVarHeaderParameter['{{baseName}}'] = String({{paramName}});
{{/isString}}
{{^isString}}
{{! isString is falsy also for $ref that defines a string or enum type}}
localVarHeaderParameter['{{baseName}}'] = typeof {{paramName}} === 'string'
? {{paramName}}
: JSON.stringify({{paramName}});
{{/isString}}
}
{{/isArray}}

{{/headerParams}}
{{#vendorExtensions}}
{{#formParams}}
{{#isArray}}
Expand Down Expand Up @@ -224,6 +196,33 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
{{/consumes.0}}

{{/bodyParam}}
{{#headerParams}}
{{#isArray}}
if ({{paramName}}) {
{{#uniqueItems}}
let mapped = Array.from({{paramName}}).map(value => (<any>"{{{dataType}}}" !== "Set<string>") ? JSON.stringify(value) : (value || ""));
{{/uniqueItems}}
{{^uniqueItems}}
let mapped = {{paramName}}.map(value => (<any>"{{{dataType}}}" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
{{/uniqueItems}}
localVarHeaderParameter['{{baseName}}'] = mapped.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
}
{{/isArray}}
{{^isArray}}
{{! `val == null` covers for both `null` and `undefined`}}
if ({{paramName}} != null) {
{{#isString}}
localVarHeaderParameter['{{baseName}}'] = String({{paramName}});
{{/isString}}
{{^isString}}
{{! isString is falsy also for $ref that defines a string or enum type}}
localVarHeaderParameter['{{baseName}}'] = typeof {{paramName}} === 'string'
? {{paramName}}
: JSON.stringify({{paramName}});
{{/isString}}
}
{{/isArray}}
{{/headerParams}}
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions,{{#hasFormParams}}{{#multipartFormData}} ...(localVarFormParams as any).getHeaders?.(),{{/multipartFormData}}{{/hasFormParams}} ...options.headers};
Expand Down Expand Up @@ -465,4 +464,4 @@ export type {{operationIdCamelCase}}{{enumName}} = typeof {{operationIdCamelCase
{{/isEnum}}
{{/allParams}}
{{/operation}}
{{/operations}}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ paths:
schema:
type: integer
format: int64
- name: Content-Type
in: header
style: simple
description: Content type header parameter
required: false
schema:
type: string
responses:
'200':
description: successful operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ paths:
schema:
type: integer
format: int64
- name: Content-Type
in: header
style: simple
description: Content type header parameter
required: false
schema:
type: string
responses:
'200':
description: successful operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ public okhttp3.Call deletePetCall(Long petId, String apiKey, final ApiCallback _
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

if (apiKey != null) {
localVarHeaderParams.put("api_key", localVarApiClient.parameterToString(apiKey));
}

final String[] localVarAccepts = {
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
Expand All @@ -260,6 +256,11 @@ public okhttp3.Call deletePetCall(Long petId, String apiKey, final ApiCallback _
localVarHeaderParams.put("Content-Type", localVarContentType);
}

if (apiKey != null) {
localVarHeaderParams.put("api_key", localVarApiClient.parameterToString(apiKey));
}


String[] localVarAuthNames = new String[] { "petstore_auth" };
return localVarApiClient.buildCall(basePath, localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 +113,45 @@ public okhttp3.Call testHeaderIntegerBooleanStringEnumsCall(Integer integerHeade
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

final String[] localVarAccepts = {
"text/plain"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}

final String[] localVarContentTypes = {
};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}

if (integerHeader != null) {
localVarHeaderParams.put("integer_header", localVarApiClient.parameterToString(integerHeader));
}


if (booleanHeader != null) {
localVarHeaderParams.put("boolean_header", localVarApiClient.parameterToString(booleanHeader));
}


if (stringHeader != null) {
localVarHeaderParams.put("string_header", localVarApiClient.parameterToString(stringHeader));
}


if (enumNonrefStringHeader != null) {
localVarHeaderParams.put("enum_nonref_string_header", localVarApiClient.parameterToString(enumNonrefStringHeader));
}


if (enumRefStringHeader != null) {
localVarHeaderParams.put("enum_ref_string_header", localVarApiClient.parameterToString(enumRefStringHeader));
}

final String[] localVarAccepts = {
"text/plain"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}

final String[] localVarContentTypes = {
};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}

String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
Expand Down
9 changes: 2 additions & 7 deletions samples/client/echo_api/typescript-axios/build/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1605,34 +1605,29 @@ export const HeaderApiAxiosParamCreator = function (configuration?: Configuratio
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



if (integerHeader != null) {
localVarHeaderParameter['integer_header'] = typeof integerHeader === 'string'
? integerHeader
: JSON.stringify(integerHeader);
}

if (booleanHeader != null) {
localVarHeaderParameter['boolean_header'] = typeof booleanHeader === 'string'
? booleanHeader
: JSON.stringify(booleanHeader);
}

if (stringHeader != null) {
localVarHeaderParameter['string_header'] = String(stringHeader);
}

if (enumNonrefStringHeader != null) {
localVarHeaderParameter['enum_nonref_string_header'] = String(enumNonrefStringHeader);
}

if (enumRefStringHeader != null) {
localVarHeaderParameter['enum_ref_string_header'] = typeof enumRefStringHeader === 'string'
? enumRefStringHeader
: JSON.stringify(enumRefStringHeader);
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,6 @@ public okhttp3.Call refToRefParameterCall(UUID refToUuid, final ApiCallback _cal
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

if (refToUuid != null) {
localVarHeaderParams.put("ref_to_uuid", localVarApiClient.parameterToString(refToUuid));
}

final String[] localVarAccepts = {
"text/plain"
};
Expand All @@ -825,6 +821,11 @@ public okhttp3.Call refToRefParameterCall(UUID refToUuid, final ApiCallback _cal
localVarHeaderParams.put("Content-Type", localVarContentType);
}

if (refToUuid != null) {
localVarHeaderParams.put("ref_to_uuid", localVarApiClient.parameterToString(refToUuid));
}


String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
Expand Down Expand Up @@ -932,10 +933,6 @@ public okhttp3.Call refToRefParameterAnyofCall(RefToRefParameterAnyofRefToAnyofP
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

if (refToAnyof != null) {
localVarHeaderParams.put("ref_to_anyof", localVarApiClient.parameterToString(refToAnyof));
}

final String[] localVarAccepts = {
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
Expand All @@ -950,6 +947,11 @@ public okhttp3.Call refToRefParameterAnyofCall(RefToRefParameterAnyofRefToAnyofP
localVarHeaderParams.put("Content-Type", localVarContentType);
}

if (refToAnyof != null) {
localVarHeaderParams.put("ref_to_anyof", localVarApiClient.parameterToString(refToAnyof));
}


String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
Expand Down Expand Up @@ -1053,10 +1055,6 @@ public okhttp3.Call refToRefParameterOneofCall(RefRefToPathLevelParameterOneofRe
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

if (refToOneof != null) {
localVarHeaderParams.put("ref_to_oneof", localVarApiClient.parameterToString(refToOneof));
}

final String[] localVarAccepts = {
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
Expand All @@ -1071,6 +1069,11 @@ public okhttp3.Call refToRefParameterOneofCall(RefRefToPathLevelParameterOneofRe
localVarHeaderParams.put("Content-Type", localVarContentType);
}

if (refToOneof != null) {
localVarHeaderParams.put("ref_to_oneof", localVarApiClient.parameterToString(refToOneof));
}


String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ public okhttp3.Call deletePetCall(Long petId, String apiKey, final ApiCallback _
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

if (apiKey != null) {
localVarHeaderParams.put("api_key", localVarApiClient.parameterToString(apiKey));
}

final String[] localVarAccepts = {
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
Expand All @@ -260,6 +256,11 @@ public okhttp3.Call deletePetCall(Long petId, String apiKey, final ApiCallback _
localVarHeaderParams.put("Content-Type", localVarContentType);
}

if (apiKey != null) {
localVarHeaderParams.put("api_key", localVarApiClient.parameterToString(apiKey));
}


String[] localVarAuthNames = new String[] { "petstore_auth" };
return localVarApiClient.buildCall(basePath, localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ public okhttp3.Call deletePetCall(Long petId, String apiKey, final ApiCallback _
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

if (apiKey != null) {
localVarHeaderParams.put("api_key", localVarApiClient.parameterToString(apiKey));
}

final String[] localVarAccepts = {
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
Expand All @@ -260,6 +256,11 @@ public okhttp3.Call deletePetCall(Long petId, String apiKey, final ApiCallback _
localVarHeaderParams.put("Content-Type", localVarContentType);
}

if (apiKey != null) {
localVarHeaderParams.put("api_key", localVarApiClient.parameterToString(apiKey));
}


String[] localVarAuthNames = new String[] { "AWS4Auth", "petstore_auth" };
return localVarApiClient.buildCall(basePath, localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ public okhttp3.Call call123testSpecialTagsCall(UUID uuidTest, Client body, final
localVarHeaderParams.put("Content-Type", localVarContentType);
}

if (uuidTest != null) {
localVarHeaderParams.put("uuid_test", localVarApiClient.parameterToString(uuidTest));
}


String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, apiOperation.getMethod(), localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
Expand Down
Loading
Loading