From 61a56eebc0474a477ecda01940dd44388c6a8399 Mon Sep 17 00:00:00 2001 From: Alexander Rashed Date: Wed, 13 Sep 2017 19:43:56 +0200 Subject: [PATCH] [typescript-angular2] Allow lazy oauth token refresh (#6486) - Startover with a new branch after pr #6493 was created on the wrong branch - Handover authentication scheme name as well as the scopes to the accessToken function in the Configuration class - accessToken returns an Observable to allow a lazy refresh of the accessToken --- .../typescript-angular/api.service.mustache | 62 ++-- .../typescript-angular/configuration.mustache | 6 +- .../rxjs-operators.mustache | 4 + .../typescript-angular/.gitignore | 1 + .../.swagger-codegen/VERSION | 2 +- .../typescript-angular/api.module.ts | 24 +- .../typescript-angular/api/api.ts | 6 +- .../typescript-angular/api/fake.service.ts | 144 ++++++++ .../typescript-angular/configuration.ts | 28 ++ .../typescript-angular/encoder.ts | 17 + .../typescript-angular/index.ts | 5 +- .../typescript-angular/model/ModelReturn.ts | 6 +- .../typescript-angular/model/models.ts | 2 +- .../typescript-angular/rxjs-operators.ts | 15 + .../typescript-angular/variables.ts | 9 + .../default/api/pet.service.ts | 324 ++++++++++-------- .../default/api/store.service.ts | 124 ++++--- .../default/api/user.service.ts | 248 ++++++++------ .../default/configuration.ts | 6 +- .../default/rxjs-operators.ts | 4 + .../npm/api/pet.service.ts | 324 ++++++++++-------- .../npm/api/store.service.ts | 124 ++++--- .../npm/api/user.service.ts | 248 ++++++++------ .../npm/configuration.ts | 6 +- .../npm/rxjs-operators.ts | 4 + .../with-interfaces/api/pet.service.ts | 324 ++++++++++-------- .../with-interfaces/api/store.service.ts | 124 ++++--- .../with-interfaces/api/user.service.ts | 248 ++++++++------ .../with-interfaces/configuration.ts | 6 +- .../with-interfaces/rxjs-operators.ts | 4 + .../npm/api/pet.service.ts | 324 ++++++++++-------- .../npm/api/store.service.ts | 124 ++++--- .../npm/api/user.service.ts | 248 ++++++++------ .../npm/configuration.ts | 6 +- .../npm/rxjs-operators.ts | 4 + 35 files changed, 1933 insertions(+), 1222 deletions(-) create mode 100644 samples/client/petstore-security-test/typescript-angular/api/fake.service.ts create mode 100644 samples/client/petstore-security-test/typescript-angular/configuration.ts create mode 100644 samples/client/petstore-security-test/typescript-angular/encoder.ts create mode 100644 samples/client/petstore-security-test/typescript-angular/rxjs-operators.ts create mode 100644 samples/client/petstore-security-test/typescript-angular/variables.ts diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache index 5da473f5ccbb..70b6587de818 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache @@ -45,12 +45,12 @@ export class {{classname}} { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -120,7 +120,7 @@ export class {{classname}} { .replace('${' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 {{#allParams}} {{#required}} @@ -158,12 +158,12 @@ export class {{classname}} { {{#headerParams}} {{#isListContainer}} if ({{paramName}}) { - headers.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); + headersObservable = headersObservable.do((headers: Headers) => headers.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']))); } {{/isListContainer}} {{^isListContainer}} if ({{paramName}} !== undefined && {{paramName}} !== null) { - headers.set('{{baseName}}', String({{paramName}})); + headersObservable = headersObservable.do((headers: Headers) => headers.set('{{baseName}}', String({{paramName}}))); } {{/isListContainer}} @@ -199,7 +199,8 @@ export class {{classname}} { {{#isApiKey}} {{#isKeyInHeader}} if (this.configuration.apiKeys["{{keyParamName}}"]) { - headers.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"])); } {{/isKeyInHeader}} @@ -213,24 +214,29 @@ export class {{classname}} { {{#isBasic}} // http basic authentication required if (this.configuration.username || this.configuration.password) { - headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password)); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password))); } {{/isBasic}} {{#isOAuth}} // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } {{/isOAuth}} {{/authMethods}} - + {{#bodyParam}} - headers.set('Content-Type', 'application/json'); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); {{/bodyParam}} {{#formParams}} @@ -253,27 +259,31 @@ export class {{classname}} { {{/isListContainer}} {{/formParams}} - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: {{httpMethod}}, - headers: headers, + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: {{httpMethod}}, + headers: headers, {{#bodyParam}} - body: {{paramName}} == null ? '' : JSON.stringify({{paramName}}), // https://github.com/angular/angular/issues/10612 + body: {{paramName}} == null ? '' : JSON.stringify({{paramName}}), // https://github.com/angular/angular/issues/10612 {{/bodyParam}} {{#hasFormParams}} - body: formParams.toString(), + body: formParams.toString(), {{/hasFormParams}} {{#isResponseFile}} - responseType: ResponseContentType.Blob, + responseType: ResponseContentType.Blob, {{/isResponseFile}} - search: queryParameters, - withCredentials:this.configuration.withCredentials + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } {{/operation}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/configuration.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/configuration.mustache index 005c3a26df33..d78472350741 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/configuration.mustache @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache index 5659cd0694f1..f81b512d8f02 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore-security-test/typescript-angular/.gitignore b/samples/client/petstore-security-test/typescript-angular/.gitignore index 35e2fb2b02ed..149b57654723 100644 --- a/samples/client/petstore-security-test/typescript-angular/.gitignore +++ b/samples/client/petstore-security-test/typescript-angular/.gitignore @@ -1,3 +1,4 @@ wwwroot/*.js node_modules typings +dist diff --git a/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION b/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION index 6b4d15773825..f9f7450d1359 100644 --- a/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION +++ b/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION @@ -1 +1 @@ -2.2.3 \ No newline at end of file +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular/api.module.ts b/samples/client/petstore-security-test/typescript-angular/api.module.ts index daa111453cad..c3bde487bc4d 100644 --- a/samples/client/petstore-security-test/typescript-angular/api.module.ts +++ b/samples/client/petstore-security-test/typescript-angular/api.module.ts @@ -1,7 +1,21 @@ -import * as api from './api/api'; -import * as angular from 'angular'; +import { NgModule, ModuleWithProviders } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { HttpModule } from '@angular/http'; +import { Configuration } from './configuration'; -const apiModule = angular.module('api', []) -.service('FakeApi', api.FakeApi) +import { FakeService } from './api/fake.service'; -export default apiModule; +@NgModule({ + imports: [ CommonModule, HttpModule ], + declarations: [], + exports: [], + providers: [ FakeService ] +}) +export class ApiModule { + public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders { + return { + ngModule: ApiModule, + providers: [ {provide: Configuration, useFactory: configurationFactory}] + } + } +} diff --git a/samples/client/petstore-security-test/typescript-angular/api/api.ts b/samples/client/petstore-security-test/typescript-angular/api/api.ts index 4c0b3c9f56b1..1457e1d01f40 100644 --- a/samples/client/petstore-security-test/typescript-angular/api/api.ts +++ b/samples/client/petstore-security-test/typescript-angular/api/api.ts @@ -1,3 +1,3 @@ -export * from './FakeApi'; -import { FakeApi } from './FakeApi'; -export const APIS = [FakeApi]; +export * from './fake.service'; +import { FakeService } from './fake.service'; +export const APIS = [FakeService]; diff --git a/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts b/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts new file mode 100644 index 000000000000..c1125b4395ad --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts @@ -0,0 +1,144 @@ +/** + * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { Http, Headers, URLSearchParams } from '@angular/http'; +import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; +import { Response, ResponseContentType } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; +import '../rxjs-operators'; + + +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; + + +@Injectable() +export class FakeService { + + protected basePath = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; + public defaultHeaders: Headers = new Headers(); + public configuration: Configuration = new Configuration(); + + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + this.basePath = basePath || configuration.basePath || this.basePath; + } + } + + /** + * + * Extends object by coping non-existing properties. + * @param objA object to be extended + * @param objB source object + */ + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + (objA as any)[key] = (objB as any)[key]; + } + } + return objA; + } + + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + + /** + * + * @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + */ + public testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, extraHttpRequestParams?: any): Observable<{}> { + return this.testCodeInjectEndRnNRWithHttpInfo(test code inject * ' " =end rn n r, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + + /** + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * + * @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + */ + public testCodeInjectEndRnNRWithHttpInfo(test code inject * ' " =end rn n r?: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/fake'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 + + // to determine the Content-Type header + let consumes: string[] = [ + 'application/json', + '*_/ =end -- ' + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + '*_/ =end -- ' + ]; + + + if (test code inject * ' " =end rn n r !== undefined) { + formParams.set('test code inject */ ' " =end -- \r\n \n \r', test code inject * ' " =end rn n r); + } + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); + } + +} diff --git a/samples/client/petstore-security-test/typescript-angular/configuration.ts b/samples/client/petstore-security-test/typescript-angular/configuration.ts new file mode 100644 index 000000000000..d78472350741 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/configuration.ts @@ -0,0 +1,28 @@ +import { Observable } from 'rxjs/Observable'; + +export interface ConfigurationParameters { + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | ((name: string, scopes?: string[]) => Observable); + basePath?: string; + withCredentials?: boolean; +} + +export class Configuration { + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | ((name: string, scopes?: string[]) => Observable); + basePath?: string; + withCredentials?: boolean; + + constructor(configurationParameters: ConfigurationParameters = {}) { + this.apiKeys = configurationParameters.apiKeys; + this.username = configurationParameters.username; + this.password = configurationParameters.password; + this.accessToken = configurationParameters.accessToken; + this.basePath = configurationParameters.basePath; + this.withCredentials = configurationParameters.withCredentials; + } +} diff --git a/samples/client/petstore-security-test/typescript-angular/encoder.ts b/samples/client/petstore-security-test/typescript-angular/encoder.ts new file mode 100644 index 000000000000..319f79da15a6 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/encoder.ts @@ -0,0 +1,17 @@ +import { QueryEncoder } from "@angular/http"; + +/** +* CustomQueryEncoderHelper +* Fix plus sign (+) not encoding, so sent as blank space +* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318 +*/ +export class CustomQueryEncoderHelper extends QueryEncoder { + encodeKey(k: string): string { + k = super.encodeKey(k); + return k.replace(/\+/gi, '%2B'); + } + encodeValue(v: string): string { + v = super.encodeValue(v); + return v.replace(/\+/gi, '%2B'); + } +} \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular/index.ts b/samples/client/petstore-security-test/typescript-angular/index.ts index 557365516ad3..c312b70fa3ef 100644 --- a/samples/client/petstore-security-test/typescript-angular/index.ts +++ b/samples/client/petstore-security-test/typescript-angular/index.ts @@ -1,2 +1,5 @@ export * from './api/api'; -export * from './model/models'; \ No newline at end of file +export * from './model/models'; +export * from './variables'; +export * from './configuration'; +export * from './api.module'; \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular/model/ModelReturn.ts b/samples/client/petstore-security-test/typescript-angular/model/ModelReturn.ts index 0440a6393c6b..170661be61a9 100644 --- a/samples/client/petstore-security-test/typescript-angular/model/ModelReturn.ts +++ b/samples/client/petstore-security-test/typescript-angular/model/ModelReturn.ts @@ -10,7 +10,7 @@ * Do not edit the class manually. */ -import * as models from './models'; + /** * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r @@ -19,6 +19,6 @@ export interface ModelReturn { /** * property description *_/ ' \" =end -- \\r\\n \\n \\r */ - "return"?: number; -} + return?: number; +} diff --git a/samples/client/petstore-security-test/typescript-angular/model/models.ts b/samples/client/petstore-security-test/typescript-angular/model/models.ts index df8a2d48008b..bca4c78d6b07 100644 --- a/samples/client/petstore-security-test/typescript-angular/model/models.ts +++ b/samples/client/petstore-security-test/typescript-angular/model/models.ts @@ -1 +1 @@ -export * from './ModelReturn'; +export * from './modelReturn'; diff --git a/samples/client/petstore-security-test/typescript-angular/rxjs-operators.ts b/samples/client/petstore-security-test/typescript-angular/rxjs-operators.ts new file mode 100644 index 000000000000..f81b512d8f02 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/rxjs-operators.ts @@ -0,0 +1,15 @@ +// RxJS imports according to https://angular.io/docs/ts/latest/guide/server-communication.html#!#rxjs + +// See node_module/rxjs/Rxjs.js +// Import just the rxjs statics and operators we need for THIS app. + +// Statics +import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; + +// Operators +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore-security-test/typescript-angular/variables.ts b/samples/client/petstore-security-test/typescript-angular/variables.ts new file mode 100644 index 000000000000..6fe58549f395 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/variables.ts @@ -0,0 +1,9 @@ +import { InjectionToken } from '@angular/core'; + +export const BASE_PATH = new InjectionToken('basePath'); +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} diff --git a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts index b05fe8fc6371..113c36d49eed 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts @@ -41,12 +41,12 @@ export class PetService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -217,7 +217,7 @@ export class PetService { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -233,28 +233,36 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -268,14 +276,14 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } if (apiKey !== undefined && apiKey !== null) { - headers.set('api_key', String(apiKey)); + headersObservable = headersObservable.do((headers: Headers) => headers.set('api_key', String(apiKey))); } @@ -288,25 +296,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -318,7 +333,7 @@ export class PetService { const path = this.basePath + '/pet/findByStatus'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'status' is not null or undefined if (status === null || status === undefined) { @@ -338,25 +353,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -368,7 +390,7 @@ export class PetService { const path = this.basePath + '/pet/findByTags'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'tags' is not null or undefined if (tags === null || tags === undefined) { @@ -388,25 +410,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -419,7 +448,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -434,22 +463,27 @@ export class PetService { // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('api_key', this.configuration.apiKeys["api_key"])); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -461,7 +495,7 @@ export class PetService { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -477,28 +511,36 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -513,7 +555,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -538,13 +580,16 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - + if (name !== undefined) { formParams.set('name', name); } @@ -553,19 +598,23 @@ export class PetService { formParams.set('status', status); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -580,7 +629,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -605,13 +654,16 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - + if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } @@ -620,19 +672,23 @@ export class PetService { formParams.set('file', file); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts index 8765ad7c4a93..ead89e5be0c1 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts @@ -40,12 +40,12 @@ export class StoreService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -147,7 +147,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', String(orderId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { @@ -160,19 +160,23 @@ export class StoreService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -183,7 +187,7 @@ export class StoreService { const path = this.basePath + '/store/inventory'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Accept header @@ -193,22 +197,27 @@ export class StoreService { // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('api_key', this.configuration.apiKeys["api_key"])); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -221,7 +230,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', String(orderId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { @@ -234,19 +243,23 @@ export class StoreService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -258,7 +271,7 @@ export class StoreService { const path = this.basePath + '/store/order'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -271,22 +284,27 @@ export class StoreService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts index 4322a11f7efb..a237b714cf54 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts @@ -40,12 +40,12 @@ export class UserService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -212,7 +212,7 @@ export class UserService { const path = this.basePath + '/user'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -225,22 +225,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -252,7 +257,7 @@ export class UserService { const path = this.basePath + '/user/createWithArray'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -265,22 +270,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -292,7 +302,7 @@ export class UserService { const path = this.basePath + '/user/createWithList'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -305,22 +315,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -333,7 +348,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -346,19 +361,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -371,7 +390,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -384,19 +403,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -409,7 +432,7 @@ export class UserService { const path = this.basePath + '/user/login'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -434,19 +457,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -457,7 +484,7 @@ export class UserService { const path = this.basePath + '/user/logout'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Accept header @@ -466,19 +493,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -492,7 +523,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -509,22 +540,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/default/configuration.ts b/samples/client/petstore/typescript-angular-v2/default/configuration.ts index 005c3a26df33..d78472350741 100644 --- a/samples/client/petstore/typescript-angular-v2/default/configuration.ts +++ b/samples/client/petstore/typescript-angular-v2/default/configuration.ts @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/samples/client/petstore/typescript-angular-v2/default/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v2/default/rxjs-operators.ts index 5659cd0694f1..f81b512d8f02 100644 --- a/samples/client/petstore/typescript-angular-v2/default/rxjs-operators.ts +++ b/samples/client/petstore/typescript-angular-v2/default/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts index b05fe8fc6371..113c36d49eed 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts @@ -41,12 +41,12 @@ export class PetService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -217,7 +217,7 @@ export class PetService { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -233,28 +233,36 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -268,14 +276,14 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } if (apiKey !== undefined && apiKey !== null) { - headers.set('api_key', String(apiKey)); + headersObservable = headersObservable.do((headers: Headers) => headers.set('api_key', String(apiKey))); } @@ -288,25 +296,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -318,7 +333,7 @@ export class PetService { const path = this.basePath + '/pet/findByStatus'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'status' is not null or undefined if (status === null || status === undefined) { @@ -338,25 +353,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -368,7 +390,7 @@ export class PetService { const path = this.basePath + '/pet/findByTags'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'tags' is not null or undefined if (tags === null || tags === undefined) { @@ -388,25 +410,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -419,7 +448,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -434,22 +463,27 @@ export class PetService { // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('api_key', this.configuration.apiKeys["api_key"])); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -461,7 +495,7 @@ export class PetService { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -477,28 +511,36 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -513,7 +555,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -538,13 +580,16 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - + if (name !== undefined) { formParams.set('name', name); } @@ -553,19 +598,23 @@ export class PetService { formParams.set('status', status); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -580,7 +629,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -605,13 +654,16 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - + if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } @@ -620,19 +672,23 @@ export class PetService { formParams.set('file', file); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts index 8765ad7c4a93..ead89e5be0c1 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts @@ -40,12 +40,12 @@ export class StoreService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -147,7 +147,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', String(orderId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { @@ -160,19 +160,23 @@ export class StoreService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -183,7 +187,7 @@ export class StoreService { const path = this.basePath + '/store/inventory'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Accept header @@ -193,22 +197,27 @@ export class StoreService { // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('api_key', this.configuration.apiKeys["api_key"])); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -221,7 +230,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', String(orderId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { @@ -234,19 +243,23 @@ export class StoreService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -258,7 +271,7 @@ export class StoreService { const path = this.basePath + '/store/order'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -271,22 +284,27 @@ export class StoreService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts index 4322a11f7efb..a237b714cf54 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts @@ -40,12 +40,12 @@ export class UserService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -212,7 +212,7 @@ export class UserService { const path = this.basePath + '/user'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -225,22 +225,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -252,7 +257,7 @@ export class UserService { const path = this.basePath + '/user/createWithArray'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -265,22 +270,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -292,7 +302,7 @@ export class UserService { const path = this.basePath + '/user/createWithList'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -305,22 +315,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -333,7 +348,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -346,19 +361,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -371,7 +390,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -384,19 +403,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -409,7 +432,7 @@ export class UserService { const path = this.basePath + '/user/login'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -434,19 +457,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -457,7 +484,7 @@ export class UserService { const path = this.basePath + '/user/logout'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Accept header @@ -466,19 +493,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -492,7 +523,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -509,22 +540,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/npm/configuration.ts b/samples/client/petstore/typescript-angular-v2/npm/configuration.ts index 005c3a26df33..d78472350741 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/configuration.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/configuration.ts @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/samples/client/petstore/typescript-angular-v2/npm/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v2/npm/rxjs-operators.ts index 5659cd0694f1..f81b512d8f02 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/rxjs-operators.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts index cfba17412165..7681fddbfdda 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts @@ -42,12 +42,12 @@ export class PetService implements PetServiceInterface { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -218,7 +218,7 @@ export class PetService implements PetServiceInterface { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -234,28 +234,36 @@ export class PetService implements PetServiceInterface { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -269,14 +277,14 @@ export class PetService implements PetServiceInterface { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } if (apiKey !== undefined && apiKey !== null) { - headers.set('api_key', String(apiKey)); + headersObservable = headersObservable.do((headers: Headers) => headers.set('api_key', String(apiKey))); } @@ -289,25 +297,32 @@ export class PetService implements PetServiceInterface { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -319,7 +334,7 @@ export class PetService implements PetServiceInterface { const path = this.basePath + '/pet/findByStatus'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'status' is not null or undefined if (status === null || status === undefined) { @@ -339,25 +354,32 @@ export class PetService implements PetServiceInterface { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -369,7 +391,7 @@ export class PetService implements PetServiceInterface { const path = this.basePath + '/pet/findByTags'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'tags' is not null or undefined if (tags === null || tags === undefined) { @@ -389,25 +411,32 @@ export class PetService implements PetServiceInterface { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -420,7 +449,7 @@ export class PetService implements PetServiceInterface { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -435,22 +464,27 @@ export class PetService implements PetServiceInterface { // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('api_key', this.configuration.apiKeys["api_key"])); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -462,7 +496,7 @@ export class PetService implements PetServiceInterface { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -478,28 +512,36 @@ export class PetService implements PetServiceInterface { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -514,7 +556,7 @@ export class PetService implements PetServiceInterface { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -539,13 +581,16 @@ export class PetService implements PetServiceInterface { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - + if (name !== undefined) { formParams.set('name', name); } @@ -554,19 +599,23 @@ export class PetService implements PetServiceInterface { formParams.set('status', status); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -581,7 +630,7 @@ export class PetService implements PetServiceInterface { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -606,13 +655,16 @@ export class PetService implements PetServiceInterface { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - + if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } @@ -621,19 +673,23 @@ export class PetService implements PetServiceInterface { formParams.set('file', file); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts index 6a3d0fc745cb..9a51e35cf68d 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts @@ -41,12 +41,12 @@ export class StoreService implements StoreServiceInterface { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -148,7 +148,7 @@ export class StoreService implements StoreServiceInterface { .replace('${' + 'orderId' + '}', String(orderId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { @@ -161,19 +161,23 @@ export class StoreService implements StoreServiceInterface { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -184,7 +188,7 @@ export class StoreService implements StoreServiceInterface { const path = this.basePath + '/store/inventory'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Accept header @@ -194,22 +198,27 @@ export class StoreService implements StoreServiceInterface { // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('api_key', this.configuration.apiKeys["api_key"])); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -222,7 +231,7 @@ export class StoreService implements StoreServiceInterface { .replace('${' + 'orderId' + '}', String(orderId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { @@ -235,19 +244,23 @@ export class StoreService implements StoreServiceInterface { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -259,7 +272,7 @@ export class StoreService implements StoreServiceInterface { const path = this.basePath + '/store/order'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -272,22 +285,27 @@ export class StoreService implements StoreServiceInterface { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts index 593c8d71a92d..7465740a51b4 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts @@ -41,12 +41,12 @@ export class UserService implements UserServiceInterface { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -213,7 +213,7 @@ export class UserService implements UserServiceInterface { const path = this.basePath + '/user'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -226,22 +226,27 @@ export class UserService implements UserServiceInterface { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -253,7 +258,7 @@ export class UserService implements UserServiceInterface { const path = this.basePath + '/user/createWithArray'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -266,22 +271,27 @@ export class UserService implements UserServiceInterface { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -293,7 +303,7 @@ export class UserService implements UserServiceInterface { const path = this.basePath + '/user/createWithList'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -306,22 +316,27 @@ export class UserService implements UserServiceInterface { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -334,7 +349,7 @@ export class UserService implements UserServiceInterface { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -347,19 +362,23 @@ export class UserService implements UserServiceInterface { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -372,7 +391,7 @@ export class UserService implements UserServiceInterface { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -385,19 +404,23 @@ export class UserService implements UserServiceInterface { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -410,7 +433,7 @@ export class UserService implements UserServiceInterface { const path = this.basePath + '/user/login'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -435,19 +458,23 @@ export class UserService implements UserServiceInterface { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -458,7 +485,7 @@ export class UserService implements UserServiceInterface { const path = this.basePath + '/user/logout'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Accept header @@ -467,19 +494,23 @@ export class UserService implements UserServiceInterface { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -493,7 +524,7 @@ export class UserService implements UserServiceInterface { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -510,22 +541,27 @@ export class UserService implements UserServiceInterface { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/configuration.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/configuration.ts index 005c3a26df33..d78472350741 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/configuration.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/configuration.ts @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/rxjs-operators.ts index 5659cd0694f1..f81b512d8f02 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/rxjs-operators.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts index b05fe8fc6371..113c36d49eed 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts @@ -41,12 +41,12 @@ export class PetService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -217,7 +217,7 @@ export class PetService { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -233,28 +233,36 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -268,14 +276,14 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } if (apiKey !== undefined && apiKey !== null) { - headers.set('api_key', String(apiKey)); + headersObservable = headersObservable.do((headers: Headers) => headers.set('api_key', String(apiKey))); } @@ -288,25 +296,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -318,7 +333,7 @@ export class PetService { const path = this.basePath + '/pet/findByStatus'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'status' is not null or undefined if (status === null || status === undefined) { @@ -338,25 +353,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -368,7 +390,7 @@ export class PetService { const path = this.basePath + '/pet/findByTags'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'tags' is not null or undefined if (tags === null || tags === undefined) { @@ -388,25 +410,32 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -419,7 +448,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -434,22 +463,27 @@ export class PetService { // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('api_key', this.configuration.apiKeys["api_key"])); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -461,7 +495,7 @@ export class PetService { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -477,28 +511,36 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -513,7 +555,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -538,13 +580,16 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - + if (name !== undefined) { formParams.set('name', name); } @@ -553,19 +598,23 @@ export class PetService { formParams.set('status', status); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -580,7 +629,7 @@ export class PetService { .replace('${' + 'petId' + '}', String(petId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined if (petId === null || petId === undefined) { @@ -605,13 +654,16 @@ export class PetService { // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + let accessTokenObservable = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]) + : Observable.of(this.configuration.accessToken); + headersObservable = headersObservable.zip(accessTokenObservable, (headers: Headers, accessToken: string) => { + headers.set('Authorization', 'Bearer ' + accessToken); + return headers; + }); } - + if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } @@ -620,19 +672,23 @@ export class PetService { formParams.set('file', file); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts index 8765ad7c4a93..ead89e5be0c1 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts @@ -40,12 +40,12 @@ export class StoreService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -147,7 +147,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', String(orderId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { @@ -160,19 +160,23 @@ export class StoreService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -183,7 +187,7 @@ export class StoreService { const path = this.basePath + '/store/inventory'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Accept header @@ -193,22 +197,27 @@ export class StoreService { // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('api_key', this.configuration.apiKeys["api_key"])); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -221,7 +230,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', String(orderId)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined if (orderId === null || orderId === undefined) { @@ -234,19 +243,23 @@ export class StoreService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -258,7 +271,7 @@ export class StoreService { const path = this.basePath + '/store/order'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -271,22 +284,27 @@ export class StoreService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts index 4322a11f7efb..a237b714cf54 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts @@ -40,12 +40,12 @@ export class UserService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -212,7 +212,7 @@ export class UserService { const path = this.basePath + '/user'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -225,22 +225,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -252,7 +257,7 @@ export class UserService { const path = this.basePath + '/user/createWithArray'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -265,22 +270,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -292,7 +302,7 @@ export class UserService { const path = this.basePath + '/user/createWithList'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { @@ -305,22 +315,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -333,7 +348,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -346,19 +361,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -371,7 +390,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -384,19 +403,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -409,7 +432,7 @@ export class UserService { const path = this.basePath + '/user/login'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -434,19 +457,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -457,7 +484,7 @@ export class UserService { const path = this.basePath + '/user/logout'; let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Accept header @@ -466,19 +493,23 @@ export class UserService { 'application/json' ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, - headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -492,7 +523,7 @@ export class UserService { .replace('${' + 'username' + '}', String(username)); let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined if (username === null || username === undefined) { @@ -509,22 +540,27 @@ export class UserService { 'application/json' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', 'application/json')); + + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore/typescript-angular-v4/npm/configuration.ts b/samples/client/petstore/typescript-angular-v4/npm/configuration.ts index 005c3a26df33..d78472350741 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/configuration.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/configuration.ts @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/samples/client/petstore/typescript-angular-v4/npm/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v4/npm/rxjs-operators.ts index 5659cd0694f1..f81b512d8f02 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/rxjs-operators.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap';