Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export enum {{classname}}ApiKeys {

export class {{classname}} {
protected _basePath = defaultBasePath;
protected defaultHeaders : any = {};
protected _defaultHeaders : any = {};
protected _useQuerystring : boolean = false;

protected authentications = {
Expand Down Expand Up @@ -93,6 +93,14 @@ export class {{classname}} {
this._basePath = basePath;
}

set defaultHeaders(defaultHeaders: any) {
this._defaultHeaders = defaultHeaders;
}

get defaultHeaders() {
return this._defaultHeaders;
}

get basePath() {
return this._basePath;
}
Expand Down Expand Up @@ -149,7 +157,7 @@ export class {{classname}} {
const localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
{{#hasProduces}}
const produces = [{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}];
// give precedence to 'application/json'
Expand Down Expand Up @@ -216,8 +224,26 @@ export class {{classname}} {

let authenticationPromise = Promise.resolve();
{{#authMethods}}
authenticationPromise = authenticationPromise.then(() => this.authentications.{{name}}.applyToRequest(localVarRequestOptions));

{{#isApiKey}}
if (this.authentications.{{name}}.apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications.{{name}}.applyToRequest(localVarRequestOptions));
}
{{/isApiKey}}
{{#isBasicBasic}}
if (this.authentications.{{name}}.username && this.authentications.{{name}}.password) {
authenticationPromise = authenticationPromise.then(() => this.authentications.{{name}}.applyToRequest(localVarRequestOptions));
}
{{/isBasicBasic}}
{{#isBasicBearer}}
if (this.authentications.{{name}}.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.{{name}}.applyToRequest(localVarRequestOptions));
}
{{/isBasicBearer}}
{{#isOAuth}}
if (this.authentications.{{name}}.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.{{name}}.applyToRequest(localVarRequestOptions));
}
{{/isOAuth}}
{{/authMethods}}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

Expand Down
66 changes: 41 additions & 25 deletions samples/client/petstore/typescript-node/default/api/petApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export enum PetApiApiKeys {

export class PetApi {
protected _basePath = defaultBasePath;
protected defaultHeaders : any = {};
protected _defaultHeaders : any = {};
protected _useQuerystring : boolean = false;

protected authentications = {
Expand Down Expand Up @@ -66,6 +66,14 @@ export class PetApi {
this._basePath = basePath;
}

set defaultHeaders(defaultHeaders: any) {
this._defaultHeaders = defaultHeaders;
}

get defaultHeaders() {
return this._defaultHeaders;
}

get basePath() {
return this._basePath;
}
Expand Down Expand Up @@ -94,7 +102,7 @@ export class PetApi {
public async 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 = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
let localVarFormParams: any = {};

// verify required parameter 'body' is not null or undefined
Expand All @@ -117,8 +125,9 @@ export class PetApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));

if (this.authentications.petstore_auth.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down Expand Up @@ -159,7 +168,7 @@ export class PetApi {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
let localVarFormParams: any = {};

// verify required parameter 'petId' is not null or undefined
Expand All @@ -182,8 +191,9 @@ export class PetApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));

if (this.authentications.petstore_auth.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down Expand Up @@ -222,7 +232,7 @@ export class PetApi {
public async findPetsByStatus (status: Array<'available' | 'pending' | 'sold'>, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
const localVarPath = this.basePath + '/pet/findByStatus';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/xml', 'application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand Down Expand Up @@ -255,8 +265,9 @@ export class PetApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));

if (this.authentications.petstore_auth.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down Expand Up @@ -296,7 +307,7 @@ export class PetApi {
public async findPetsByTags (tags: Array<string>, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
const localVarPath = this.basePath + '/pet/findByTags';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/xml', 'application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand Down Expand Up @@ -329,8 +340,9 @@ export class PetApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));

if (this.authentications.petstore_auth.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down Expand Up @@ -371,7 +383,7 @@ export class PetApi {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/xml', 'application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand Down Expand Up @@ -400,8 +412,9 @@ export class PetApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.api_key.applyToRequest(localVarRequestOptions));

if (this.authentications.api_key.apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications.api_key.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down Expand Up @@ -441,7 +454,7 @@ export class PetApi {
public async 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 = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
let localVarFormParams: any = {};

// verify required parameter 'body' is not null or undefined
Expand All @@ -464,8 +477,9 @@ export class PetApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));

if (this.authentications.petstore_auth.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down Expand Up @@ -507,7 +521,7 @@ export class PetApi {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
let localVarFormParams: any = {};

// verify required parameter 'petId' is not null or undefined
Expand Down Expand Up @@ -537,8 +551,9 @@ export class PetApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));

if (this.authentications.petstore_auth.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down Expand Up @@ -580,7 +595,7 @@ export class PetApi {
const localVarPath = this.basePath + '/pet/{petId}/uploadImage'
.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand Down Expand Up @@ -618,8 +633,9 @@ export class PetApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));

if (this.authentications.petstore_auth.accessToken) {
authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down
23 changes: 16 additions & 7 deletions samples/client/petstore/typescript-node/default/api/storeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export enum StoreApiApiKeys {

export class StoreApi {
protected _basePath = defaultBasePath;
protected defaultHeaders : any = {};
protected _defaultHeaders : any = {};
protected _useQuerystring : boolean = false;

protected authentications = {
Expand Down Expand Up @@ -64,6 +64,14 @@ export class StoreApi {
this._basePath = basePath;
}

set defaultHeaders(defaultHeaders: any) {
this._defaultHeaders = defaultHeaders;
}

get defaultHeaders() {
return this._defaultHeaders;
}

get basePath() {
return this._basePath;
}
Expand All @@ -89,7 +97,7 @@ export class StoreApi {
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', encodeURIComponent(String(orderId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
let localVarFormParams: any = {};

// verify required parameter 'orderId' is not null or undefined
Expand Down Expand Up @@ -148,7 +156,7 @@ export class StoreApi {
public async 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 = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand All @@ -172,8 +180,9 @@ export class StoreApi {
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.api_key.applyToRequest(localVarRequestOptions));

if (this.authentications.api_key.apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications.api_key.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
Expand Down Expand Up @@ -214,7 +223,7 @@ export class StoreApi {
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', encodeURIComponent(String(orderId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/xml', 'application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand Down Expand Up @@ -282,7 +291,7 @@ export class StoreApi {
public async 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 = (<any>Object).assign({}, this.defaultHeaders);
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/xml', 'application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand Down
Loading