[typescript-axios] avoid stringifying header string values (#12919)

* feat(typescript-axios) don't stringify string headers

* samples
This commit is contained in:
stropho 2022-07-19 09:55:34 +02:00 committed by GitHub
parent b722fd9063
commit f176716a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 77 additions and 32 deletions

View File

@ -146,12 +146,16 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
}
{{/isArray}}
{{^isArray}}
if ({{paramName}} !== undefined && {{paramName}} !== null) {
{{! `val == null` covers for both `null` and `undefined`}}
if ({{paramName}} != null) {
{{#isString}}
localVarHeaderParameter['{{baseName}}'] = String({{paramName}});
{{/isString}}
{{^isString}}
localVarHeaderParameter['{{baseName}}'] = String(JSON.stringify({{paramName}}));
{{! isString is falsy also for $ref that defines a string or enum type}}
localVarHeaderParameter['{{baseName}}'] = typeof {{paramName}} === 'string'
? {{paramName}}
: JSON.stringify({{paramName}});
{{/isString}}
}
{{/isArray}}

View File

@ -43,6 +43,10 @@ paths:
type: array
items:
$ref: '#/components/requestBodies/Pet'
- name: Accept
in: header
schema:
$ref: '#/components/schemas/MediaType'
requestBody:
$ref: '#/components/requestBodies/Pet'
put:
@ -578,6 +582,9 @@ components:
name: api_key
in: header
schemas:
MediaType:
type: string
enum: ['application/json', 'application/xml']
Order:
title: Pet Order
description: An order for a pets from the pet store

View File

@ -318,7 +318,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -318,7 +318,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -2408,7 +2408,7 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
localVarHeaderParameter['enum_header_string_array'] = mapped.join(COLLECTION_FORMATS["csv"]);
}
if (enumHeaderString !== undefined && enumHeaderString !== null) {
if (enumHeaderString != null) {
localVarHeaderParameter['enum_header_string'] = String(enumHeaderString);
}
@ -2485,12 +2485,16 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['int64_group'] = int64Group;
}
if (requiredBooleanGroup !== undefined && requiredBooleanGroup !== null) {
localVarHeaderParameter['required_boolean_group'] = String(JSON.stringify(requiredBooleanGroup));
if (requiredBooleanGroup != null) {
localVarHeaderParameter['required_boolean_group'] = typeof requiredBooleanGroup === 'string'
? requiredBooleanGroup
: JSON.stringify(requiredBooleanGroup);
}
if (booleanGroup !== undefined && booleanGroup !== null) {
localVarHeaderParameter['boolean_group'] = String(JSON.stringify(booleanGroup));
if (booleanGroup != null) {
localVarHeaderParameter['boolean_group'] = typeof booleanGroup === 'string'
? booleanGroup
: JSON.stringify(booleanGroup);
}
@ -3431,7 +3435,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -65,6 +65,20 @@ export interface Category {
*/
'name'?: string;
}
/**
*
* @export
* @enum {string}
*/
export const MediaType = {
Json: 'application/json',
Xml: 'application/xml'
} as const;
export type MediaType = typeof MediaType[keyof typeof MediaType];
/**
* An order for a pets from the pet store
* @export
@ -256,10 +270,11 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
* @param {Pet} pet Pet object that needs to be added to the store
* @param {Pet} [header1]
* @param {Array<Pet>} [header2]
* @param {MediaType} [accept]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
addPet: async (pet: Pet, header1?: Pet, header2?: Array<Pet>, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
addPet: async (pet: Pet, header1?: Pet, header2?: Array<Pet>, accept?: MediaType, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'pet' is not null or undefined
assertParamExists('addPet', 'pet', pet)
const localVarPath = `/pet`;
@ -278,8 +293,10 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (header1 !== undefined && header1 !== null) {
localVarHeaderParameter['header1'] = String(JSON.stringify(header1));
if (header1 != null) {
localVarHeaderParameter['header1'] = typeof header1 === 'string'
? header1
: JSON.stringify(header1);
}
if (header2) {
@ -287,6 +304,12 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
localVarHeaderParameter['header2'] = mapped.join(COLLECTION_FORMATS["csv"]);
}
if (accept != null) {
localVarHeaderParameter['Accept'] = typeof accept === 'string'
? accept
: JSON.stringify(accept);
}
localVarHeaderParameter['Content-Type'] = 'application/json';
@ -329,7 +352,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}
@ -624,11 +647,12 @@ export const PetApiFp = function(configuration?: Configuration) {
* @param {Pet} pet Pet object that needs to be added to the store
* @param {Pet} [header1]
* @param {Array<Pet>} [header2]
* @param {MediaType} [accept]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async addPet(pet: Pet, header1?: Pet, header2?: Array<Pet>, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.addPet(pet, header1, header2, options);
async addPet(pet: Pet, header1?: Pet, header2?: Array<Pet>, accept?: MediaType, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.addPet(pet, header1, header2, accept, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
@ -730,11 +754,12 @@ export const PetApiFactory = function (configuration?: Configuration, basePath?:
* @param {Pet} pet Pet object that needs to be added to the store
* @param {Pet} [header1]
* @param {Array<Pet>} [header2]
* @param {MediaType} [accept]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
addPet(pet: Pet, header1?: Pet, header2?: Array<Pet>, options?: any): AxiosPromise<void> {
return localVarFp.addPet(pet, header1, header2, options).then((request) => request(axios, basePath));
addPet(pet: Pet, header1?: Pet, header2?: Array<Pet>, accept?: MediaType, options?: any): AxiosPromise<void> {
return localVarFp.addPet(pet, header1, header2, accept, options).then((request) => request(axios, basePath));
},
/**
*
@ -828,12 +853,13 @@ export class PetApi extends BaseAPI {
* @param {Pet} pet Pet object that needs to be added to the store
* @param {Pet} [header1]
* @param {Array<Pet>} [header2]
* @param {MediaType} [accept]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof PetApi
*/
public addPet(pet: Pet, header1?: Pet, header2?: Array<Pet>, options?: AxiosRequestConfig) {
return PetApiFp(this.configuration).addPet(pet, header1, header2, options).then((request) => request(this.axios, this.basePath));
public addPet(pet: Pet, header1?: Pet, header2?: Array<Pet>, accept?: MediaType, options?: AxiosRequestConfig) {
return PetApiFp(this.configuration).addPet(pet, header1, header2, accept, options).then((request) => request(this.axios, this.basePath));
}
/**

View File

@ -2006,7 +2006,7 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
localVarHeaderParameter['enum_header_string_array'] = mapped.join(COLLECTION_FORMATS["csv"]);
}
if (enumHeaderString !== undefined && enumHeaderString !== null) {
if (enumHeaderString != null) {
localVarHeaderParameter['enum_header_string'] = String(enumHeaderString);
}
@ -2083,12 +2083,16 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['int64_group'] = int64Group;
}
if (requiredBooleanGroup !== undefined && requiredBooleanGroup !== null) {
localVarHeaderParameter['required_boolean_group'] = String(JSON.stringify(requiredBooleanGroup));
if (requiredBooleanGroup != null) {
localVarHeaderParameter['required_boolean_group'] = typeof requiredBooleanGroup === 'string'
? requiredBooleanGroup
: JSON.stringify(requiredBooleanGroup);
}
if (booleanGroup !== undefined && booleanGroup !== null) {
localVarHeaderParameter['boolean_group'] = String(JSON.stringify(booleanGroup));
if (booleanGroup != null) {
localVarHeaderParameter['boolean_group'] = typeof booleanGroup === 'string'
? booleanGroup
: JSON.stringify(booleanGroup);
}
@ -3076,7 +3080,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -318,7 +318,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -322,7 +322,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -98,7 +98,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -318,7 +318,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -318,7 +318,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}

View File

@ -322,7 +322,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
if (apiKey !== undefined && apiKey !== null) {
if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}