From f5d6aaebb2b54a645674ea2b7df1c4b1048abcb1 Mon Sep 17 00:00:00 2001 From: Silas Boyd-Wickizer Date: Tue, 15 Jan 2019 18:31:30 -0800 Subject: [PATCH] [TypeScript-Node] support setting the content-type header per-call (#1868) * [TypeScript-Node] support setting the content-type header per-call This approach is inspired by the typescript-fetch implementation in swagger-codegen. Fixes https://github.com/OpenAPITools/openapi-generator/issues/1867 * Update modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache Co-Authored-By: silasbw * Update modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache Co-Authored-By: silasbw * Update Petstore sample * Fix types * update "npm" petstore example * Rename --- .../typescript-node/api-single.mustache | 3 ++- .../typescript-node/api/fakeApi.ts | 3 ++- .../typescript-node/default/api/petApi.ts | 24 ++++++++++++------- .../typescript-node/default/api/storeApi.ts | 12 ++++++---- .../typescript-node/default/api/userApi.ts | 24 ++++++++++++------- .../typescript-node/npm/api/petApi.ts | 24 ++++++++++++------- .../typescript-node/npm/api/storeApi.ts | 12 ++++++---- .../typescript-node/npm/api/userApi.ts | 24 ++++++++++++------- 8 files changed, 84 insertions(+), 42 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache index b3508727eb6..c1ae478c2f8 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache @@ -127,7 +127,7 @@ export class {{classname}} { * @param {{paramName}} {{description}} {{/allParams}} */ - public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.{{#supportsES6}}IncomingMessage{{/supportsES6}}{{^supportsES6}}ClientResponse{{/supportsES6}}; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { + public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.{{#supportsES6}}IncomingMessage{{/supportsES6}}{{^supportsES6}}ClientResponse{{/supportsES6}}; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { const localVarPath = this.basePath + '{{{path}}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}}; let localVarQueryParameters: any = {}; @@ -152,6 +152,7 @@ export class {{classname}} { {{#headerParams}} localVarHeaderParams['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}"); {{/headerParams}} + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; diff --git a/samples/client/petstore-security-test/typescript-node/api/fakeApi.ts b/samples/client/petstore-security-test/typescript-node/api/fakeApi.ts index ce68adb739b..a00664839d1 100644 --- a/samples/client/petstore-security-test/typescript-node/api/fakeApi.ts +++ b/samples/client/petstore-security-test/typescript-node/api/fakeApi.ts @@ -74,12 +74,13 @@ export class FakeApi { * @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * @param testCodeInjectEndRnNR To test code injection *_/ ' \\\" =end -- \\\\r\\\\n \\\\n \\\\r */ - public testCodeInjectEndRnNR (testCodeInjectEndRnNR?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public testCodeInjectEndRnNR (testCodeInjectEndRnNR?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/fake'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); let localVarFormParams: any = {}; + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; diff --git a/samples/client/petstore/typescript-node/default/api/petApi.ts b/samples/client/petstore/typescript-node/default/api/petApi.ts index b5c995c5702..d7d08ae5db8 100644 --- a/samples/client/petstore/typescript-node/default/api/petApi.ts +++ b/samples/client/petstore/typescript-node/default/api/petApi.ts @@ -83,7 +83,7 @@ export class PetApi { * @summary Add a new pet to the store * @param body Pet object that needs to be added to the store */ - public addPet (body: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { + public addPet (body: Pet, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/pet'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -94,6 +94,7 @@ export class PetApi { throw new Error('Required parameter body was null or undefined when calling addPet.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -138,7 +139,7 @@ export class PetApi { * @param petId Pet id to delete * @param apiKey */ - public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public deletePet (petId: number, apiKey?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', encodeURIComponent(String(petId))); let localVarQueryParameters: any = {}; @@ -151,6 +152,7 @@ export class PetApi { } localVarHeaderParams['api_key'] = ObjectSerializer.serialize(apiKey, "string"); + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -193,7 +195,7 @@ export class PetApi { * @summary Finds Pets by status * @param status Status values that need to be considered for filter */ - public findPetsByStatus (status: Array<'available' | 'pending' | 'sold'>) : Promise<{ response: http.ClientResponse; body: Array; }> { + public findPetsByStatus (status: Array<'available' | 'pending' | 'sold'>, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array; }> { const localVarPath = this.basePath + '/pet/findByStatus'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -208,6 +210,7 @@ export class PetApi { localVarQueryParameters['status'] = ObjectSerializer.serialize(status, "Array<'available' | 'pending' | 'sold'>"); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -251,7 +254,7 @@ export class PetApi { * @summary Finds Pets by tags * @param tags Tags to filter by */ - public findPetsByTags (tags: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { + public findPetsByTags (tags: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array; }> { const localVarPath = this.basePath + '/pet/findByTags'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -266,6 +269,7 @@ export class PetApi { localVarQueryParameters['tags'] = ObjectSerializer.serialize(tags, "Array"); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -309,7 +313,7 @@ export class PetApi { * @summary Find pet by ID * @param petId ID of pet to return */ - public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { + public getPetById (petId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Pet; }> { const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', encodeURIComponent(String(petId))); let localVarQueryParameters: any = {}; @@ -321,6 +325,7 @@ export class PetApi { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -364,7 +369,7 @@ export class PetApi { * @summary Update an existing pet * @param body Pet object that needs to be added to the store */ - public updatePet (body: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { + public updatePet (body: Pet, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/pet'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -375,6 +380,7 @@ export class PetApi { throw new Error('Required parameter body was null or undefined when calling updatePet.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -420,7 +426,7 @@ export class PetApi { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithForm (petId: number, name?: string, status?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public updatePetWithForm (petId: number, name?: string, status?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', encodeURIComponent(String(petId))); let localVarQueryParameters: any = {}; @@ -432,6 +438,7 @@ export class PetApi { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -484,7 +491,7 @@ export class PetApi { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile (petId: number, additionalMetadata?: string, file?: Buffer) : Promise<{ response: http.ClientResponse; body: ApiResponse; }> { + public uploadFile (petId: number, additionalMetadata?: string, file?: Buffer, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: ApiResponse; }> { const localVarPath = this.basePath + '/pet/{petId}/uploadImage' .replace('{' + 'petId' + '}', encodeURIComponent(String(petId))); let localVarQueryParameters: any = {}; @@ -496,6 +503,7 @@ export class PetApi { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; diff --git a/samples/client/petstore/typescript-node/default/api/storeApi.ts b/samples/client/petstore/typescript-node/default/api/storeApi.ts index e491efe0394..dbbce5ad5e9 100644 --- a/samples/client/petstore/typescript-node/default/api/storeApi.ts +++ b/samples/client/petstore/typescript-node/default/api/storeApi.ts @@ -77,7 +77,7 @@ export class StoreApi { * @summary Delete purchase order by ID * @param orderId ID of the order that needs to be deleted */ - public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public deleteOrder (orderId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', encodeURIComponent(String(orderId))); let localVarQueryParameters: any = {}; @@ -89,6 +89,7 @@ export class StoreApi { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -128,12 +129,13 @@ export class StoreApi { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { + public getInventory (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { const localVarPath = this.basePath + '/store/inventory'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); let localVarFormParams: any = {}; + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -177,7 +179,7 @@ export class StoreApi { * @summary Find purchase order by ID * @param orderId ID of pet that needs to be fetched */ - public getOrderById (orderId: number) : Promise<{ response: http.ClientResponse; body: Order; }> { + public getOrderById (orderId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Order; }> { const localVarPath = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', encodeURIComponent(String(orderId))); let localVarQueryParameters: any = {}; @@ -189,6 +191,7 @@ export class StoreApi { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -230,7 +233,7 @@ export class StoreApi { * @summary Place an order for a pet * @param body order placed for purchasing the pet */ - public placeOrder (body: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { + public placeOrder (body: Order, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Order; }> { const localVarPath = this.basePath + '/store/order'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -241,6 +244,7 @@ export class StoreApi { throw new Error('Required parameter body was null or undefined when calling placeOrder.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; diff --git a/samples/client/petstore/typescript-node/default/api/userApi.ts b/samples/client/petstore/typescript-node/default/api/userApi.ts index a7bae51a45d..6438051f2e2 100644 --- a/samples/client/petstore/typescript-node/default/api/userApi.ts +++ b/samples/client/petstore/typescript-node/default/api/userApi.ts @@ -75,7 +75,7 @@ export class UserApi { * @summary Create user * @param body Created user object */ - public createUser (body: User) : Promise<{ response: http.ClientResponse; body?: any; }> { + public createUser (body: User, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -86,6 +86,7 @@ export class UserApi { throw new Error('Required parameter body was null or undefined when calling createUser.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -127,7 +128,7 @@ export class UserApi { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithArrayInput (body: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { + public createUsersWithArrayInput (body: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/createWithArray'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -138,6 +139,7 @@ export class UserApi { throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -179,7 +181,7 @@ export class UserApi { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithListInput (body: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { + public createUsersWithListInput (body: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/createWithList'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -190,6 +192,7 @@ export class UserApi { throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -231,7 +234,7 @@ export class UserApi { * @summary Delete user * @param username The name that needs to be deleted */ - public deleteUser (username: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public deleteUser (username: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', encodeURIComponent(String(username))); let localVarQueryParameters: any = {}; @@ -243,6 +246,7 @@ export class UserApi { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -283,7 +287,7 @@ export class UserApi { * @summary Get user by user name * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByName (username: string) : Promise<{ response: http.ClientResponse; body: User; }> { + public getUserByName (username: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: User; }> { const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', encodeURIComponent(String(username))); let localVarQueryParameters: any = {}; @@ -295,6 +299,7 @@ export class UserApi { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -337,7 +342,7 @@ export class UserApi { * @param username The user name for login * @param password The password for login in clear text */ - public loginUser (username: string, password: string) : Promise<{ response: http.ClientResponse; body: string; }> { + public loginUser (username: string, password: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: string; }> { const localVarPath = this.basePath + '/user/login'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -361,6 +366,7 @@ export class UserApi { localVarQueryParameters['password'] = ObjectSerializer.serialize(password, "string"); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -401,12 +407,13 @@ export class UserApi { * * @summary Logs out current logged in user session */ - public logoutUser () : Promise<{ response: http.ClientResponse; body?: any; }> { + public logoutUser (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/logout'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); let localVarFormParams: any = {}; + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -448,7 +455,7 @@ export class UserApi { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser (username: string, body: User) : Promise<{ response: http.ClientResponse; body?: any; }> { + public updateUser (username: string, body: User, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', encodeURIComponent(String(username))); let localVarQueryParameters: any = {}; @@ -465,6 +472,7 @@ export class UserApi { throw new Error('Required parameter body was null or undefined when calling updateUser.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; diff --git a/samples/client/petstore/typescript-node/npm/api/petApi.ts b/samples/client/petstore/typescript-node/npm/api/petApi.ts index b5c995c5702..d7d08ae5db8 100644 --- a/samples/client/petstore/typescript-node/npm/api/petApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/petApi.ts @@ -83,7 +83,7 @@ export class PetApi { * @summary Add a new pet to the store * @param body Pet object that needs to be added to the store */ - public addPet (body: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { + public addPet (body: Pet, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/pet'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -94,6 +94,7 @@ export class PetApi { throw new Error('Required parameter body was null or undefined when calling addPet.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -138,7 +139,7 @@ export class PetApi { * @param petId Pet id to delete * @param apiKey */ - public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public deletePet (petId: number, apiKey?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', encodeURIComponent(String(petId))); let localVarQueryParameters: any = {}; @@ -151,6 +152,7 @@ export class PetApi { } localVarHeaderParams['api_key'] = ObjectSerializer.serialize(apiKey, "string"); + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -193,7 +195,7 @@ export class PetApi { * @summary Finds Pets by status * @param status Status values that need to be considered for filter */ - public findPetsByStatus (status: Array<'available' | 'pending' | 'sold'>) : Promise<{ response: http.ClientResponse; body: Array; }> { + public findPetsByStatus (status: Array<'available' | 'pending' | 'sold'>, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array; }> { const localVarPath = this.basePath + '/pet/findByStatus'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -208,6 +210,7 @@ export class PetApi { localVarQueryParameters['status'] = ObjectSerializer.serialize(status, "Array<'available' | 'pending' | 'sold'>"); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -251,7 +254,7 @@ export class PetApi { * @summary Finds Pets by tags * @param tags Tags to filter by */ - public findPetsByTags (tags: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { + public findPetsByTags (tags: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array; }> { const localVarPath = this.basePath + '/pet/findByTags'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -266,6 +269,7 @@ export class PetApi { localVarQueryParameters['tags'] = ObjectSerializer.serialize(tags, "Array"); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -309,7 +313,7 @@ export class PetApi { * @summary Find pet by ID * @param petId ID of pet to return */ - public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { + public getPetById (petId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Pet; }> { const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', encodeURIComponent(String(petId))); let localVarQueryParameters: any = {}; @@ -321,6 +325,7 @@ export class PetApi { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -364,7 +369,7 @@ export class PetApi { * @summary Update an existing pet * @param body Pet object that needs to be added to the store */ - public updatePet (body: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { + public updatePet (body: Pet, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/pet'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -375,6 +380,7 @@ export class PetApi { throw new Error('Required parameter body was null or undefined when calling updatePet.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -420,7 +426,7 @@ export class PetApi { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithForm (petId: number, name?: string, status?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public updatePetWithForm (petId: number, name?: string, status?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', encodeURIComponent(String(petId))); let localVarQueryParameters: any = {}; @@ -432,6 +438,7 @@ export class PetApi { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -484,7 +491,7 @@ export class PetApi { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile (petId: number, additionalMetadata?: string, file?: Buffer) : Promise<{ response: http.ClientResponse; body: ApiResponse; }> { + public uploadFile (petId: number, additionalMetadata?: string, file?: Buffer, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: ApiResponse; }> { const localVarPath = this.basePath + '/pet/{petId}/uploadImage' .replace('{' + 'petId' + '}', encodeURIComponent(String(petId))); let localVarQueryParameters: any = {}; @@ -496,6 +503,7 @@ export class PetApi { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; diff --git a/samples/client/petstore/typescript-node/npm/api/storeApi.ts b/samples/client/petstore/typescript-node/npm/api/storeApi.ts index e491efe0394..dbbce5ad5e9 100644 --- a/samples/client/petstore/typescript-node/npm/api/storeApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/storeApi.ts @@ -77,7 +77,7 @@ export class StoreApi { * @summary Delete purchase order by ID * @param orderId ID of the order that needs to be deleted */ - public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public deleteOrder (orderId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', encodeURIComponent(String(orderId))); let localVarQueryParameters: any = {}; @@ -89,6 +89,7 @@ export class StoreApi { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -128,12 +129,13 @@ export class StoreApi { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { + public getInventory (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { const localVarPath = this.basePath + '/store/inventory'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); let localVarFormParams: any = {}; + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -177,7 +179,7 @@ export class StoreApi { * @summary Find purchase order by ID * @param orderId ID of pet that needs to be fetched */ - public getOrderById (orderId: number) : Promise<{ response: http.ClientResponse; body: Order; }> { + public getOrderById (orderId: number, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Order; }> { const localVarPath = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', encodeURIComponent(String(orderId))); let localVarQueryParameters: any = {}; @@ -189,6 +191,7 @@ export class StoreApi { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -230,7 +233,7 @@ export class StoreApi { * @summary Place an order for a pet * @param body order placed for purchasing the pet */ - public placeOrder (body: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { + public placeOrder (body: Order, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Order; }> { const localVarPath = this.basePath + '/store/order'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -241,6 +244,7 @@ export class StoreApi { throw new Error('Required parameter body was null or undefined when calling placeOrder.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; diff --git a/samples/client/petstore/typescript-node/npm/api/userApi.ts b/samples/client/petstore/typescript-node/npm/api/userApi.ts index a7bae51a45d..6438051f2e2 100644 --- a/samples/client/petstore/typescript-node/npm/api/userApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/userApi.ts @@ -75,7 +75,7 @@ export class UserApi { * @summary Create user * @param body Created user object */ - public createUser (body: User) : Promise<{ response: http.ClientResponse; body?: any; }> { + public createUser (body: User, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -86,6 +86,7 @@ export class UserApi { throw new Error('Required parameter body was null or undefined when calling createUser.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -127,7 +128,7 @@ export class UserApi { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithArrayInput (body: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { + public createUsersWithArrayInput (body: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/createWithArray'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -138,6 +139,7 @@ export class UserApi { throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -179,7 +181,7 @@ export class UserApi { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithListInput (body: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { + public createUsersWithListInput (body: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/createWithList'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -190,6 +192,7 @@ export class UserApi { throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -231,7 +234,7 @@ export class UserApi { * @summary Delete user * @param username The name that needs to be deleted */ - public deleteUser (username: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + public deleteUser (username: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', encodeURIComponent(String(username))); let localVarQueryParameters: any = {}; @@ -243,6 +246,7 @@ export class UserApi { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -283,7 +287,7 @@ export class UserApi { * @summary Get user by user name * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByName (username: string) : Promise<{ response: http.ClientResponse; body: User; }> { + public getUserByName (username: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: User; }> { const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', encodeURIComponent(String(username))); let localVarQueryParameters: any = {}; @@ -295,6 +299,7 @@ export class UserApi { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -337,7 +342,7 @@ export class UserApi { * @param username The user name for login * @param password The password for login in clear text */ - public loginUser (username: string, password: string) : Promise<{ response: http.ClientResponse; body: string; }> { + public loginUser (username: string, password: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: string; }> { const localVarPath = this.basePath + '/user/login'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -361,6 +366,7 @@ export class UserApi { localVarQueryParameters['password'] = ObjectSerializer.serialize(password, "string"); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -401,12 +407,13 @@ export class UserApi { * * @summary Logs out current logged in user session */ - public logoutUser () : Promise<{ response: http.ClientResponse; body?: any; }> { + public logoutUser (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/logout'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); let localVarFormParams: any = {}; + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -448,7 +455,7 @@ export class UserApi { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser (username: string, body: User) : Promise<{ response: http.ClientResponse; body?: any; }> { + public updateUser (username: string, body: User, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', encodeURIComponent(String(username))); let localVarQueryParameters: any = {}; @@ -465,6 +472,7 @@ export class UserApi { throw new Error('Required parameter body was null or undefined when calling updateUser.'); } + (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false;