diff --git a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.module.mustache b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.module.mustache index 0aeeaa782550..005aabdff6c8 100644 --- a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.module.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.module.mustache @@ -3,7 +3,7 @@ import { DynamicModule, Module, Global, Provider } from '@nestjs/common'; import { HttpModule, HttpService } from '@nestjs/axios'; {{/useAxiosHttpModule}} {{^useAxiosHttpModule}} -import { DynamicModule, HttpService, HttpModule, Module, Global } from '@nestjs/common'; +import { DynamicModule, HttpService, HttpModule, Module, Global, Provider } from '@nestjs/common'; {{/useAxiosHttpModule}} import { AsyncConfiguration, Configuration, ConfigurationFactory } from './configuration'; diff --git a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache index 064978b97537..fee3b7ff2023 100644 --- a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache @@ -9,11 +9,12 @@ import { HttpService } from '@nestjs/axios'; import { HttpService, Inject, Injectable, Optional } from '@nestjs/common'; {{/useAxiosHttpModule}} import { AxiosResponse } from 'axios'; -import { Observable } from 'rxjs'; +import { Observable, from, of, switchMap } from 'rxjs'; {{#imports}} import { {{classname}} } from '../{{filename}}'; {{/imports}} import { Configuration } from '../configuration'; +import { COLLECTION_FORMATS } from '../variables'; {{#withInterfaces}} import { {{classname}}Interface } from './{{classFilename}}Interface'; {{/withInterfaces}} @@ -117,6 +118,8 @@ export class {{classname}} { {{/isArray}} {{/headerParams}} + let accessTokenObservable: Observable = of(null); + {{#authMethods}} // authentication ({{name}}) required {{#isApiKey}} @@ -144,17 +147,16 @@ export class {{classname}} { {{/isBasicBasic}} {{#isBasicBearer}} if (typeof this.configuration.accessToken === 'function') { - headers['Authorization'] = `Bearer ${this.configuration.accessToken()}`; + accessTokenObservable = from(Promise.resolve(this.configuration.accessToken())); } else if (this.configuration.accessToken) { - headers['Authorization'] = `Bearer ${this.configuration.accessToken}`; + accessTokenObservable = from(Promise.resolve(this.configuration.accessToken)); } {{/isBasicBearer}} {{#isOAuth}} if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } {{/isOAuth}} @@ -224,18 +226,26 @@ export class {{classname}} { {{/formParams}} {{/hasFormParams}} - 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}} - { -{{#hasQueryParams}} - params: queryParameters, -{{/hasQueryParams}} -{{#isResponseFile}} - responseType: "blob", -{{/isResponseFile}} - withCredentials: this.configuration.withCredentials, - headers: headers - } + 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}} + {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams!.toString() : formParams!{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}} + { + {{#hasQueryParams}} + params: queryParameters, + {{/hasQueryParams}} + {{#isResponseFile}} + responseType: "blob", + {{/isResponseFile}} + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } {{/operation}} diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api.module.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api.module.ts index 39681eb809d8..dc0d40220dde 100644 --- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api.module.ts +++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api.module.ts @@ -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 { PetService } from './api/pet.service'; diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts index 32b236cddb2c..f3e3af328e68 100644 --- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts @@ -13,10 +13,11 @@ import { HttpService, Inject, Injectable, Optional } from '@nestjs/common'; import { AxiosResponse } from 'axios'; -import { Observable } from 'rxjs'; +import { Observable, from, of, switchMap } from 'rxjs'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; import { Configuration } from '../configuration'; +import { COLLECTION_FORMATS } from '../variables'; @Injectable() @@ -56,12 +57,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -83,12 +85,20 @@ export class PetService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/pet`, - pet, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/pet`, + pet, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -112,12 +122,13 @@ export class PetService { headers['api_key'] = String(apiKey); } + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -131,11 +142,19 @@ export class PetService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -159,12 +178,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -180,12 +200,20 @@ export class PetService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get>(`${this.basePath}/pet/findByStatus`, - { - params: queryParameters, - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get>(`${this.basePath}/pet/findByStatus`, + { + params: queryParameters, + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -209,12 +237,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -230,12 +259,20 @@ export class PetService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get>(`${this.basePath}/pet/findByTags`, - { - params: queryParameters, - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get>(`${this.basePath}/pet/findByTags`, + { + params: queryParameters, + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -254,6 +291,8 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -272,11 +311,19 @@ export class PetService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -295,12 +342,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -322,12 +370,20 @@ export class PetService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.put(`${this.basePath}/pet`, - pet, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.put(`${this.basePath}/pet`, + pet, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -350,12 +406,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -390,12 +447,20 @@ export class PetService { formParams!.append('status', status); } - return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - convertFormParamsToString ? formParams!.toString() : formParams!, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + convertFormParamsToString ? formParams!.toString() : formParams!, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -418,12 +483,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -463,12 +529,20 @@ export class PetService { formParams!.append('file', file); } - return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, - convertFormParamsToString ? formParams!.toString() : formParams!, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, + convertFormParamsToString ? formParams!.toString() : formParams!, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } } diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts index 84b80c0f1d88..bc34e3910920 100644 --- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts +++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts @@ -13,9 +13,10 @@ import { HttpService, Inject, Injectable, Optional } from '@nestjs/common'; import { AxiosResponse } from 'axios'; -import { Observable } from 'rxjs'; +import { Observable, from, of, switchMap } from 'rxjs'; import { Order } from '../model/order'; import { Configuration } from '../configuration'; +import { COLLECTION_FORMATS } from '../variables'; @Injectable() @@ -55,6 +56,8 @@ export class StoreService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ ]; @@ -66,11 +69,19 @@ export class StoreService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -84,6 +95,8 @@ export class StoreService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -101,11 +114,19 @@ export class StoreService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -124,6 +145,8 @@ export class StoreService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ 'application/xml', @@ -137,11 +160,19 @@ export class StoreService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -160,6 +191,8 @@ export class StoreService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ 'application/xml', @@ -178,12 +211,20 @@ export class StoreService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/store/order`, - order, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/store/order`, + order, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } } diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts index 32ed0c7a5fe6..7019b9bde7a1 100644 --- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts +++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts @@ -13,9 +13,10 @@ import { HttpService, Inject, Injectable, Optional } from '@nestjs/common'; import { AxiosResponse } from 'axios'; -import { Observable } from 'rxjs'; +import { Observable, from, of, switchMap } from 'rxjs'; import { User } from '../model/user'; import { Configuration } from '../configuration'; +import { COLLECTION_FORMATS } from '../variables'; @Injectable() @@ -55,6 +56,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -76,12 +79,20 @@ export class UserService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/user`, - user, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/user`, + user, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -100,6 +111,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -121,12 +134,20 @@ export class UserService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/user/createWithArray`, - user, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/user/createWithArray`, + user, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -145,6 +166,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -166,12 +189,20 @@ export class UserService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/user/createWithList`, - user, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/user/createWithList`, + user, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -190,6 +221,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -206,11 +239,19 @@ export class UserService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(String(username))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -229,6 +270,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ 'application/xml', @@ -242,11 +285,19 @@ export class UserService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(String(username))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -278,6 +329,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ 'application/xml', @@ -291,12 +344,20 @@ export class UserService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/user/login`, - { - params: queryParameters, - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/user/login`, + { + params: queryParameters, + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -310,6 +371,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -326,11 +389,19 @@ export class UserService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/user/logout`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/user/logout`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -354,6 +425,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -375,12 +448,20 @@ export class UserService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(String(username))}`, - user, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + user, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } } diff --git a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/pet.service.ts b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/pet.service.ts index 8a3d572777d3..a34f4b18d012 100644 --- a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/pet.service.ts @@ -14,10 +14,11 @@ import { Inject, Injectable, Optional } from '@nestjs/common'; import { HttpService } from '@nestjs/axios'; import { AxiosResponse } from 'axios'; -import { Observable } from 'rxjs'; +import { Observable, from, of, switchMap } from 'rxjs'; import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; import { Configuration } from '../configuration'; +import { COLLECTION_FORMATS } from '../variables'; @Injectable() @@ -57,12 +58,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -84,12 +86,20 @@ export class PetService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/pet`, - pet, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/pet`, + pet, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -113,12 +123,13 @@ export class PetService { headers['api_key'] = String(apiKey); } + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -132,11 +143,19 @@ export class PetService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -160,12 +179,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -181,12 +201,20 @@ export class PetService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get>(`${this.basePath}/pet/findByStatus`, - { - params: queryParameters, - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get>(`${this.basePath}/pet/findByStatus`, + { + params: queryParameters, + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -210,12 +238,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -231,12 +260,20 @@ export class PetService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get>(`${this.basePath}/pet/findByTags`, - { - params: queryParameters, - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get>(`${this.basePath}/pet/findByTags`, + { + params: queryParameters, + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -255,6 +292,8 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -273,11 +312,19 @@ export class PetService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -296,12 +343,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -323,12 +371,20 @@ export class PetService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.put(`${this.basePath}/pet`, - pet, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.put(`${this.basePath}/pet`, + pet, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -351,12 +407,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -391,12 +448,20 @@ export class PetService { formParams!.append('status', status); } - return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - convertFormParamsToString ? formParams!.toString() : formParams!, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + convertFormParamsToString ? formParams!.toString() : formParams!, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -419,12 +484,13 @@ export class PetService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (petstore_auth) required if (this.configuration.accessToken) { - const accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers['Authorization'] = 'Bearer ' + accessToken; + accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? from(Promise.resolve(this.configuration.accessToken())) + : from(Promise.resolve(this.configuration.accessToken)) } // to determine the Accept header @@ -464,12 +530,20 @@ export class PetService { formParams!.append('file', file); } - return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, - convertFormParamsToString ? formParams!.toString() : formParams!, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, + convertFormParamsToString ? formParams!.toString() : formParams!, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } } diff --git a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/store.service.ts b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/store.service.ts index daae6d1dbee8..2520dfe41059 100644 --- a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/store.service.ts +++ b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/store.service.ts @@ -14,9 +14,10 @@ import { Inject, Injectable, Optional } from '@nestjs/common'; import { HttpService } from '@nestjs/axios'; import { AxiosResponse } from 'axios'; -import { Observable } from 'rxjs'; +import { Observable, from, of, switchMap } from 'rxjs'; import { Order } from '../model/order'; import { Configuration } from '../configuration'; +import { COLLECTION_FORMATS } from '../variables'; @Injectable() @@ -56,6 +57,8 @@ export class StoreService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ ]; @@ -67,11 +70,19 @@ export class StoreService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -85,6 +96,8 @@ export class StoreService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -102,11 +115,19 @@ export class StoreService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -125,6 +146,8 @@ export class StoreService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ 'application/xml', @@ -138,11 +161,19 @@ export class StoreService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -161,6 +192,8 @@ export class StoreService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ 'application/xml', @@ -179,12 +212,20 @@ export class StoreService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/store/order`, - order, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/store/order`, + order, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } } diff --git a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/user.service.ts b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/user.service.ts index c34c9ae18780..f21364efad83 100644 --- a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/user.service.ts +++ b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/user.service.ts @@ -14,9 +14,10 @@ import { Inject, Injectable, Optional } from '@nestjs/common'; import { HttpService } from '@nestjs/axios'; import { AxiosResponse } from 'axios'; -import { Observable } from 'rxjs'; +import { Observable, from, of, switchMap } from 'rxjs'; import { User } from '../model/user'; import { Configuration } from '../configuration'; +import { COLLECTION_FORMATS } from '../variables'; @Injectable() @@ -56,6 +57,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -77,12 +80,20 @@ export class UserService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/user`, - user, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/user`, + user, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -101,6 +112,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -122,12 +135,20 @@ export class UserService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/user/createWithArray`, - user, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/user/createWithArray`, + user, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -146,6 +167,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -167,12 +190,20 @@ export class UserService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.post(`${this.basePath}/user/createWithList`, - user, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.post(`${this.basePath}/user/createWithList`, + user, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -191,6 +222,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -207,11 +240,19 @@ export class UserService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(String(username))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -230,6 +271,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ 'application/xml', @@ -243,11 +286,19 @@ export class UserService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(String(username))}`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -279,6 +330,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // to determine the Accept header let httpHeaderAccepts: string[] = [ 'application/xml', @@ -292,12 +345,20 @@ export class UserService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/user/login`, - { - params: queryParameters, - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/user/login`, + { + params: queryParameters, + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -311,6 +372,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -327,11 +390,19 @@ export class UserService { // to determine the Content-Type header const consumes: string[] = [ ]; - return this.httpClient.get(`${this.basePath}/user/logout`, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.get(`${this.basePath}/user/logout`, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } /** @@ -355,6 +426,8 @@ export class UserService { let headers = {...this.defaultHeaders}; + let accessTokenObservable: Observable = of(null); + // authentication (api_key) required if (this.configuration.apiKeys?.["api_key"]) { headers['api_key'] = this.configuration.apiKeys["api_key"]; @@ -376,12 +449,20 @@ export class UserService { if (httpContentTypeSelected != undefined) { headers['Content-Type'] = httpContentTypeSelected; } - return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(String(username))}`, - user, - { - withCredentials: this.configuration.withCredentials, - headers: headers - } + return accessTokenObservable.pipe( + switchMap((accessToken) => { + if (accessToken) { + headers['Authorization'] = `Bearer ${accessToken}`; + } + + return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + user, + { + withCredentials: this.configuration.withCredentials, + headers: headers + } + ); + }) ); } }