[typescript-nestjs] Accept async function for fetching access token (#18190)

* feat: starts accepting async function for fetching access token in typescript-nestjs

* fix: adds Provider in the import to fix build error

* chore: deletes package lock

* chore: deletes package lock for v6

* fix: switches to switchMap for map
This commit is contained in:
Archit Mathur 2024-04-22 12:04:02 +05:30 committed by GitHub
parent 406d00fe9b
commit c64d569a7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 709 additions and 307 deletions

View File

@ -3,7 +3,7 @@ import { DynamicModule, Module, Global, Provider } from '@nestjs/common';
import { HttpModule, HttpService } from '@nestjs/axios'; import { HttpModule, HttpService } from '@nestjs/axios';
{{/useAxiosHttpModule}} {{/useAxiosHttpModule}}
{{^useAxiosHttpModule}} {{^useAxiosHttpModule}}
import { DynamicModule, HttpService, HttpModule, Module, Global } from '@nestjs/common'; import { DynamicModule, HttpService, HttpModule, Module, Global, Provider } from '@nestjs/common';
{{/useAxiosHttpModule}} {{/useAxiosHttpModule}}
import { AsyncConfiguration, Configuration, ConfigurationFactory } from './configuration'; import { AsyncConfiguration, Configuration, ConfigurationFactory } from './configuration';

View File

@ -9,11 +9,12 @@ import { HttpService } from '@nestjs/axios';
import { HttpService, Inject, Injectable, Optional } from '@nestjs/common'; import { HttpService, Inject, Injectable, Optional } from '@nestjs/common';
{{/useAxiosHttpModule}} {{/useAxiosHttpModule}}
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { Observable } from 'rxjs'; import { Observable, from, of, switchMap } from 'rxjs';
{{#imports}} {{#imports}}
import { {{classname}} } from '../{{filename}}'; import { {{classname}} } from '../{{filename}}';
{{/imports}} {{/imports}}
import { Configuration } from '../configuration'; import { Configuration } from '../configuration';
import { COLLECTION_FORMATS } from '../variables';
{{#withInterfaces}} {{#withInterfaces}}
import { {{classname}}Interface } from './{{classFilename}}Interface'; import { {{classname}}Interface } from './{{classFilename}}Interface';
{{/withInterfaces}} {{/withInterfaces}}
@ -117,6 +118,8 @@ export class {{classname}} {
{{/isArray}} {{/isArray}}
{{/headerParams}} {{/headerParams}}
let accessTokenObservable: Observable<any> = of(null);
{{#authMethods}} {{#authMethods}}
// authentication ({{name}}) required // authentication ({{name}}) required
{{#isApiKey}} {{#isApiKey}}
@ -144,17 +147,16 @@ export class {{classname}} {
{{/isBasicBasic}} {{/isBasicBasic}}
{{#isBasicBearer}} {{#isBasicBearer}}
if (typeof this.configuration.accessToken === 'function') { if (typeof this.configuration.accessToken === 'function') {
headers['Authorization'] = `Bearer ${this.configuration.accessToken()}`; accessTokenObservable = from(Promise.resolve(this.configuration.accessToken()));
} else if (this.configuration.accessToken) { } else if (this.configuration.accessToken) {
headers['Authorization'] = `Bearer ${this.configuration.accessToken}`; accessTokenObservable = from(Promise.resolve(this.configuration.accessToken));
} }
{{/isBasicBearer}} {{/isBasicBearer}}
{{#isOAuth}} {{#isOAuth}}
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
{{/isOAuth}} {{/isOAuth}}
@ -224,6 +226,12 @@ export class {{classname}} {
{{/formParams}} {{/formParams}}
{{/hasFormParams}} {{/hasFormParams}}
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.{{httpMethod}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}(`${this.basePath}{{{path}}}`,{{#isBodyAllowed}} return this.httpClient.{{httpMethod}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}(`${this.basePath}{{{path}}}`,{{#isBodyAllowed}}
{{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams!.toString() : formParams!{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}} {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams!.toString() : formParams!{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}}
{ {
@ -237,6 +245,8 @@ export class {{classname}} {
headers: headers headers: headers
} }
); );
})
);
} }
{{/operation}} {{/operation}}
} }

View File

@ -1,4 +1,4 @@
import { DynamicModule, HttpService, HttpModule, Module, Global } from '@nestjs/common'; import { DynamicModule, HttpService, HttpModule, Module, Global, Provider } from '@nestjs/common';
import { AsyncConfiguration, Configuration, ConfigurationFactory } from './configuration'; import { AsyncConfiguration, Configuration, ConfigurationFactory } from './configuration';
import { PetService } from './api/pet.service'; import { PetService } from './api/pet.service';

View File

@ -13,10 +13,11 @@
import { HttpService, Inject, Injectable, Optional } from '@nestjs/common'; import { HttpService, Inject, Injectable, Optional } from '@nestjs/common';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { Observable } from 'rxjs'; import { Observable, from, of, switchMap } from 'rxjs';
import { ApiResponse } from '../model/apiResponse'; import { ApiResponse } from '../model/apiResponse';
import { Pet } from '../model/pet'; import { Pet } from '../model/pet';
import { Configuration } from '../configuration'; import { Configuration } from '../configuration';
import { COLLECTION_FORMATS } from '../variables';
@Injectable() @Injectable()
@ -56,12 +57,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -83,6 +85,12 @@ export class PetService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<Pet>(`${this.basePath}/pet`, return this.httpClient.post<Pet>(`${this.basePath}/pet`,
pet, pet,
{ {
@ -90,6 +98,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Deletes a pet * Deletes a pet
@ -112,12 +122,13 @@ export class PetService {
headers['api_key'] = String(apiKey); headers['api_key'] = String(apiKey);
} }
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -131,12 +142,20 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Finds Pets by status * Finds Pets by status
@ -159,12 +178,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -180,6 +200,12 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`, return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`,
{ {
params: queryParameters, params: queryParameters,
@ -187,6 +213,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Finds Pets by tags * Finds Pets by tags
@ -209,12 +237,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -230,6 +259,12 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`, return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`,
{ {
params: queryParameters, params: queryParameters,
@ -237,6 +272,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Find pet by ID * Find pet by ID
@ -254,6 +291,8 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -272,12 +311,20 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Update an existing pet * Update an existing pet
@ -295,12 +342,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -322,6 +370,12 @@ export class PetService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.put<Pet>(`${this.basePath}/pet`, return this.httpClient.put<Pet>(`${this.basePath}/pet`,
pet, pet,
{ {
@ -329,6 +383,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Updates a pet in the store with form data * Updates a pet in the store with form data
@ -350,12 +406,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -390,6 +447,12 @@ export class PetService {
formParams!.append('status', <any>status); formParams!.append('status', <any>status);
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, return this.httpClient.post<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
convertFormParamsToString ? formParams!.toString() : formParams!, convertFormParamsToString ? formParams!.toString() : formParams!,
{ {
@ -397,6 +460,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* uploads an image * uploads an image
@ -418,12 +483,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -463,6 +529,12 @@ export class PetService {
formParams!.append('file', <any>file); formParams!.append('file', <any>file);
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<ApiResponse>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, return this.httpClient.post<ApiResponse>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`,
convertFormParamsToString ? formParams!.toString() : formParams!, convertFormParamsToString ? formParams!.toString() : formParams!,
{ {
@ -470,5 +542,7 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
} }

View File

@ -13,9 +13,10 @@
import { HttpService, Inject, Injectable, Optional } from '@nestjs/common'; import { HttpService, Inject, Injectable, Optional } from '@nestjs/common';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { Observable } from 'rxjs'; import { Observable, from, of, switchMap } from 'rxjs';
import { Order } from '../model/order'; import { Order } from '../model/order';
import { Configuration } from '../configuration'; import { Configuration } from '../configuration';
import { COLLECTION_FORMATS } from '../variables';
@Injectable() @Injectable()
@ -55,6 +56,8 @@ export class StoreService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
]; ];
@ -66,12 +69,20 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Returns pet inventories by status * Returns pet inventories by status
@ -84,6 +95,8 @@ export class StoreService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -101,12 +114,20 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`, return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Find purchase order by ID * Find purchase order by ID
@ -124,6 +145,8 @@ export class StoreService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml', 'application/xml',
@ -137,12 +160,20 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Place an order for a pet * Place an order for a pet
@ -160,6 +191,8 @@ export class StoreService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml', 'application/xml',
@ -178,6 +211,12 @@ export class StoreService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<Order>(`${this.basePath}/store/order`, return this.httpClient.post<Order>(`${this.basePath}/store/order`,
order, order,
{ {
@ -185,5 +224,7 @@ export class StoreService {
headers: headers headers: headers
} }
); );
})
);
} }
} }

View File

@ -13,9 +13,10 @@
import { HttpService, Inject, Injectable, Optional } from '@nestjs/common'; import { HttpService, Inject, Injectable, Optional } from '@nestjs/common';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { Observable } from 'rxjs'; import { Observable, from, of, switchMap } from 'rxjs';
import { User } from '../model/user'; import { User } from '../model/user';
import { Configuration } from '../configuration'; import { Configuration } from '../configuration';
import { COLLECTION_FORMATS } from '../variables';
@Injectable() @Injectable()
@ -55,6 +56,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -76,6 +79,12 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<any>(`${this.basePath}/user`, return this.httpClient.post<any>(`${this.basePath}/user`,
user, user,
{ {
@ -83,6 +92,8 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -100,6 +111,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -121,6 +134,12 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`, return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`,
user, user,
{ {
@ -128,6 +147,8 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -145,6 +166,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -166,6 +189,12 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<any>(`${this.basePath}/user/createWithList`, return this.httpClient.post<any>(`${this.basePath}/user/createWithList`,
user, user,
{ {
@ -173,6 +202,8 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Delete user * Delete user
@ -190,6 +221,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -206,12 +239,20 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Get user by user name * Get user by user name
@ -229,6 +270,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml', 'application/xml',
@ -242,12 +285,20 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Logs user into the system * Logs user into the system
@ -278,6 +329,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml', 'application/xml',
@ -291,6 +344,12 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<string>(`${this.basePath}/user/login`, return this.httpClient.get<string>(`${this.basePath}/user/login`,
{ {
params: queryParameters, params: queryParameters,
@ -298,6 +357,8 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Logs out current logged in user session * Logs out current logged in user session
@ -310,6 +371,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -326,12 +389,20 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<any>(`${this.basePath}/user/logout`, return this.httpClient.get<any>(`${this.basePath}/user/logout`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Updated user * Updated user
@ -354,6 +425,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -375,6 +448,12 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
user, user,
{ {
@ -382,5 +461,7 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
} }

View File

@ -14,10 +14,11 @@
import { Inject, Injectable, Optional } from '@nestjs/common'; import { Inject, Injectable, Optional } from '@nestjs/common';
import { HttpService } from '@nestjs/axios'; import { HttpService } from '@nestjs/axios';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { Observable } from 'rxjs'; import { Observable, from, of, switchMap } from 'rxjs';
import { ApiResponse } from '../model/apiResponse'; import { ApiResponse } from '../model/apiResponse';
import { Pet } from '../model/pet'; import { Pet } from '../model/pet';
import { Configuration } from '../configuration'; import { Configuration } from '../configuration';
import { COLLECTION_FORMATS } from '../variables';
@Injectable() @Injectable()
@ -57,12 +58,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -84,6 +86,12 @@ export class PetService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<Pet>(`${this.basePath}/pet`, return this.httpClient.post<Pet>(`${this.basePath}/pet`,
pet, pet,
{ {
@ -91,6 +99,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Deletes a pet * Deletes a pet
@ -113,12 +123,13 @@ export class PetService {
headers['api_key'] = String(apiKey); headers['api_key'] = String(apiKey);
} }
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -132,12 +143,20 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Finds Pets by status * Finds Pets by status
@ -160,12 +179,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -181,6 +201,12 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`, return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`,
{ {
params: queryParameters, params: queryParameters,
@ -188,6 +214,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Finds Pets by tags * Finds Pets by tags
@ -210,12 +238,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -231,6 +260,12 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`, return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`,
{ {
params: queryParameters, params: queryParameters,
@ -238,6 +273,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Find pet by ID * Find pet by ID
@ -255,6 +292,8 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -273,12 +312,20 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Update an existing pet * Update an existing pet
@ -296,12 +343,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -323,6 +371,12 @@ export class PetService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.put<Pet>(`${this.basePath}/pet`, return this.httpClient.put<Pet>(`${this.basePath}/pet`,
pet, pet,
{ {
@ -330,6 +384,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Updates a pet in the store with form data * Updates a pet in the store with form data
@ -351,12 +407,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -391,6 +448,12 @@ export class PetService {
formParams!.append('status', <any>status); formParams!.append('status', <any>status);
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, return this.httpClient.post<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
convertFormParamsToString ? formParams!.toString() : formParams!, convertFormParamsToString ? formParams!.toString() : formParams!,
{ {
@ -398,6 +461,8 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* uploads an image * uploads an image
@ -419,12 +484,13 @@ export class PetService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (petstore_auth) required // authentication (petstore_auth) required
if (this.configuration.accessToken) { if (this.configuration.accessToken) {
const accessToken = typeof this.configuration.accessToken === 'function' accessTokenObservable = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken() ? from(Promise.resolve(this.configuration.accessToken()))
: this.configuration.accessToken; : from(Promise.resolve(this.configuration.accessToken))
headers['Authorization'] = 'Bearer ' + accessToken;
} }
// to determine the Accept header // to determine the Accept header
@ -464,6 +530,12 @@ export class PetService {
formParams!.append('file', <any>file); formParams!.append('file', <any>file);
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<ApiResponse>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, return this.httpClient.post<ApiResponse>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`,
convertFormParamsToString ? formParams!.toString() : formParams!, convertFormParamsToString ? formParams!.toString() : formParams!,
{ {
@ -471,5 +543,7 @@ export class PetService {
headers: headers headers: headers
} }
); );
})
);
} }
} }

View File

@ -14,9 +14,10 @@
import { Inject, Injectable, Optional } from '@nestjs/common'; import { Inject, Injectable, Optional } from '@nestjs/common';
import { HttpService } from '@nestjs/axios'; import { HttpService } from '@nestjs/axios';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { Observable } from 'rxjs'; import { Observable, from, of, switchMap } from 'rxjs';
import { Order } from '../model/order'; import { Order } from '../model/order';
import { Configuration } from '../configuration'; import { Configuration } from '../configuration';
import { COLLECTION_FORMATS } from '../variables';
@Injectable() @Injectable()
@ -56,6 +57,8 @@ export class StoreService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
]; ];
@ -67,12 +70,20 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Returns pet inventories by status * Returns pet inventories by status
@ -85,6 +96,8 @@ export class StoreService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -102,12 +115,20 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`, return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Find purchase order by ID * Find purchase order by ID
@ -125,6 +146,8 @@ export class StoreService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml', 'application/xml',
@ -138,12 +161,20 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Place an order for a pet * Place an order for a pet
@ -161,6 +192,8 @@ export class StoreService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml', 'application/xml',
@ -179,6 +212,12 @@ export class StoreService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<Order>(`${this.basePath}/store/order`, return this.httpClient.post<Order>(`${this.basePath}/store/order`,
order, order,
{ {
@ -186,5 +225,7 @@ export class StoreService {
headers: headers headers: headers
} }
); );
})
);
} }
} }

View File

@ -14,9 +14,10 @@
import { Inject, Injectable, Optional } from '@nestjs/common'; import { Inject, Injectable, Optional } from '@nestjs/common';
import { HttpService } from '@nestjs/axios'; import { HttpService } from '@nestjs/axios';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { Observable } from 'rxjs'; import { Observable, from, of, switchMap } from 'rxjs';
import { User } from '../model/user'; import { User } from '../model/user';
import { Configuration } from '../configuration'; import { Configuration } from '../configuration';
import { COLLECTION_FORMATS } from '../variables';
@Injectable() @Injectable()
@ -56,6 +57,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -77,6 +80,12 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<any>(`${this.basePath}/user`, return this.httpClient.post<any>(`${this.basePath}/user`,
user, user,
{ {
@ -84,6 +93,8 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -101,6 +112,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -122,6 +135,12 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`, return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`,
user, user,
{ {
@ -129,6 +148,8 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -146,6 +167,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -167,6 +190,12 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.post<any>(`${this.basePath}/user/createWithList`, return this.httpClient.post<any>(`${this.basePath}/user/createWithList`,
user, user,
{ {
@ -174,6 +203,8 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Delete user * Delete user
@ -191,6 +222,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -207,12 +240,20 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Get user by user name * Get user by user name
@ -230,6 +271,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml', 'application/xml',
@ -243,12 +286,20 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Logs user into the system * Logs user into the system
@ -279,6 +330,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml', 'application/xml',
@ -292,6 +345,12 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<string>(`${this.basePath}/user/login`, return this.httpClient.get<string>(`${this.basePath}/user/login`,
{ {
params: queryParameters, params: queryParameters,
@ -299,6 +358,8 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Logs out current logged in user session * Logs out current logged in user session
@ -311,6 +372,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -327,12 +390,20 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.get<any>(`${this.basePath}/user/logout`, return this.httpClient.get<any>(`${this.basePath}/user/logout`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
headers: headers headers: headers
} }
); );
})
);
} }
/** /**
* Updated user * Updated user
@ -355,6 +426,8 @@ export class UserService {
let headers = {...this.defaultHeaders}; let headers = {...this.defaultHeaders};
let accessTokenObservable: Observable<any> = of(null);
// authentication (api_key) required // authentication (api_key) required
if (this.configuration.apiKeys?.["api_key"]) { if (this.configuration.apiKeys?.["api_key"]) {
headers['api_key'] = this.configuration.apiKeys["api_key"]; headers['api_key'] = this.configuration.apiKeys["api_key"];
@ -376,6 +449,12 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return accessTokenObservable.pipe(
switchMap((accessToken) => {
if (accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
}
return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
user, user,
{ {
@ -383,5 +462,7 @@ export class UserService {
headers: headers headers: headers
} }
); );
})
);
} }
} }