From edb367ad700187003edd4b69a4c904b421a2878c 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 | 68 +- .../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 | 160 +++++ .../typescript-angular/configuration.ts | 28 + .../typescript-angular/encoder.ts | 17 + .../typescript-angular/index.ts | 5 +- .../typescript-angular/model/ModelReturn.ts | 6 +- .../typescript-angular/model/modelReturn.ts | 24 + .../typescript-angular/model/models.ts | 2 +- .../typescript-angular/rxjs-operators.ts | 15 + .../typescript-angular/variables.ts | 9 + .../default/api/pet.service.ts | 366 ++++++----- .../default/api/store.service.ts | 136 ++-- .../default/api/user.service.ts | 272 ++++---- .../default/configuration.ts | 6 +- .../model/{ApiResponse.ts => apiResponse.ts} | 0 .../default/rxjs-operators.ts | 4 + .../npm/api/pet.service.ts | 366 ++++++----- .../npm/api/store.service.ts | 136 ++-- .../npm/api/user.service.ts | 272 ++++---- .../npm/configuration.ts | 6 +- .../model/{ApiResponse.ts => apiResponse.ts} | 0 .../npm/package-lock.json | 6 +- .../typescript-angular-v2/npm/package.json | 2 +- .../npm/rxjs-operators.ts | 4 + .../with-interfaces/api/PetApi.ts | 610 ------------------ .../with-interfaces/api/PetApiInterface.ts | 87 --- .../with-interfaces/api/StoreApi.ts | 266 -------- .../with-interfaces/api/StoreApiInterface.ts | 53 -- .../with-interfaces/api/UserApi.ts | 507 --------------- .../with-interfaces/api/UserApiInterface.ts | 83 --- .../with-interfaces/api/pet.service.ts | 366 ++++++----- .../with-interfaces/api/store.service.ts | 136 ++-- .../with-interfaces/api/user.service.ts | 272 ++++---- .../with-interfaces/configuration.ts | 6 +- .../model/{Category.ts => category.ts} | 0 .../model/{Order.ts => order.ts} | 0 .../with-interfaces/model/{Pet.ts => pet.ts} | 0 .../with-interfaces/model/{Tag.ts => tag.ts} | 0 .../model/{User.ts => user.ts} | 0 .../with-interfaces/rxjs-operators.ts | 4 + .../npm/api/pet.service.ts | 374 ++++++----- .../npm/api/store.service.ts | 140 ++-- .../npm/api/user.service.ts | 278 ++++---- .../npm/configuration.ts | 6 +- .../npm/package-lock.json | 31 +- .../npm/rxjs-operators.ts | 4 + 52 files changed, 2217 insertions(+), 2959 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/model/modelReturn.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 rename samples/client/petstore/typescript-angular-v2/default/model/{ApiResponse.ts => apiResponse.ts} (100%) rename samples/client/petstore/typescript-angular-v2/npm/model/{ApiResponse.ts => apiResponse.ts} (100%) delete mode 100644 samples/client/petstore/typescript-angular-v2/with-interfaces/api/PetApi.ts delete mode 100644 samples/client/petstore/typescript-angular-v2/with-interfaces/api/PetApiInterface.ts delete mode 100644 samples/client/petstore/typescript-angular-v2/with-interfaces/api/StoreApi.ts delete mode 100644 samples/client/petstore/typescript-angular-v2/with-interfaces/api/StoreApiInterface.ts delete mode 100644 samples/client/petstore/typescript-angular-v2/with-interfaces/api/UserApi.ts delete mode 100644 samples/client/petstore/typescript-angular-v2/with-interfaces/api/UserApiInterface.ts rename samples/client/petstore/typescript-angular-v2/with-interfaces/model/{Category.ts => category.ts} (100%) rename samples/client/petstore/typescript-angular-v2/with-interfaces/model/{Order.ts => order.ts} (100%) rename samples/client/petstore/typescript-angular-v2/with-interfaces/model/{Pet.ts => pet.ts} (100%) rename samples/client/petstore/typescript-angular-v2/with-interfaces/model/{Tag.ts => tag.ts} (100%) rename samples/client/petstore/typescript-angular-v2/with-interfaces/model/{User.ts => user.ts} (100%) 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 376a6d6602f8..11d666678f0c 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 @@ -125,7 +125,7 @@ export class {{classname}} { .replace('${' + '{{baseName}}' + '}', encodeURIComponent(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}} @@ -163,12 +163,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}} @@ -182,7 +182,8 @@ export class {{classname}} { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -205,7 +206,8 @@ export class {{classname}} { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } {{#authMethods}} @@ -213,7 +215,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}} @@ -227,24 +230,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}} @@ -267,27 +275,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..9e4fb33fd477 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts @@ -0,0 +1,160 @@ +/** + * 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; + } + + public isJsonMime(mime: string): boolean { + const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); + return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); + } + + /** + * + * @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 -- ' + ]; + + if (consumes != null && consumes.length > 0) { + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); + } + + 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 (produces != null && produces.length > 0) { + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); + } + + + 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/modelReturn.ts b/samples/client/petstore-security-test/typescript-angular/model/modelReturn.ts new file mode 100644 index 000000000000..170661be61a9 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/model/modelReturn.ts @@ -0,0 +1,24 @@ +/** + * 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. + */ + + + +/** + * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r + */ +export interface ModelReturn { + /** + * property description *_/ ' \" =end -- \\r\\n \\n \\r + */ + 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 b1bf4505cc53..009aca5391dc 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 @@ -222,7 +222,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) { @@ -236,34 +236,43 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -277,14 +286,14 @@ export class PetService { .replace('${' + 'petId' + '}', encodeURIComponent(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))); } @@ -295,31 +304,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -331,7 +348,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) { @@ -349,31 +366,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -385,7 +410,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) { @@ -403,31 +428,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -440,7 +473,7 @@ export class PetService { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -454,27 +487,33 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -486,7 +525,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) { @@ -500,34 +539,43 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -542,7 +590,7 @@ export class PetService { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -554,7 +602,8 @@ export class PetService { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -570,19 +619,23 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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); } @@ -591,19 +644,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)); } /** @@ -618,7 +675,7 @@ export class PetService { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -630,7 +687,8 @@ export class PetService { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -646,19 +704,23 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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); } @@ -667,19 +729,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 3610483fd6b0..ac284c7ccd35 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 @@ -152,7 +152,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', encodeURIComponent(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) { @@ -166,22 +166,27 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -192,7 +197,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 @@ -201,27 +206,33 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -234,7 +245,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', encodeURIComponent(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) { @@ -248,22 +259,27 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -275,7 +291,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) { @@ -289,25 +305,31 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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 d608c6a4c274..752899ac38f0 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 @@ -217,7 +217,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) { @@ -231,25 +231,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -261,7 +267,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) { @@ -275,25 +281,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -305,7 +317,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) { @@ -319,25 +331,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -350,7 +368,7 @@ export class UserService { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -364,22 +382,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -392,7 +415,7 @@ export class UserService { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -406,22 +429,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -434,7 +462,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) { @@ -460,22 +488,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -486,7 +519,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 @@ -496,22 +529,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -525,7 +563,7 @@ export class UserService { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -543,25 +581,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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/model/ApiResponse.ts b/samples/client/petstore/typescript-angular-v2/default/model/apiResponse.ts similarity index 100% rename from samples/client/petstore/typescript-angular-v2/default/model/ApiResponse.ts rename to samples/client/petstore/typescript-angular-v2/default/model/apiResponse.ts 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 b1bf4505cc53..009aca5391dc 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 @@ -222,7 +222,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) { @@ -236,34 +236,43 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -277,14 +286,14 @@ export class PetService { .replace('${' + 'petId' + '}', encodeURIComponent(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))); } @@ -295,31 +304,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -331,7 +348,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) { @@ -349,31 +366,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -385,7 +410,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) { @@ -403,31 +428,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -440,7 +473,7 @@ export class PetService { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -454,27 +487,33 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -486,7 +525,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) { @@ -500,34 +539,43 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -542,7 +590,7 @@ export class PetService { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -554,7 +602,8 @@ export class PetService { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -570,19 +619,23 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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); } @@ -591,19 +644,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)); } /** @@ -618,7 +675,7 @@ export class PetService { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -630,7 +687,8 @@ export class PetService { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -646,19 +704,23 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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); } @@ -667,19 +729,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 3610483fd6b0..ac284c7ccd35 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 @@ -152,7 +152,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', encodeURIComponent(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) { @@ -166,22 +166,27 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -192,7 +197,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 @@ -201,27 +206,33 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -234,7 +245,7 @@ export class StoreService { .replace('${' + 'orderId' + '}', encodeURIComponent(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) { @@ -248,22 +259,27 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -275,7 +291,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) { @@ -289,25 +305,31 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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 d608c6a4c274..752899ac38f0 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 @@ -217,7 +217,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) { @@ -231,25 +231,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -261,7 +267,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) { @@ -275,25 +281,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -305,7 +317,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) { @@ -319,25 +331,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -350,7 +368,7 @@ export class UserService { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -364,22 +382,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -392,7 +415,7 @@ export class UserService { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -406,22 +429,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -434,7 +462,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) { @@ -460,22 +488,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -486,7 +519,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 @@ -496,22 +529,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -525,7 +563,7 @@ export class UserService { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -543,25 +581,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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/model/ApiResponse.ts b/samples/client/petstore/typescript-angular-v2/npm/model/apiResponse.ts similarity index 100% rename from samples/client/petstore/typescript-angular-v2/npm/model/ApiResponse.ts rename to samples/client/petstore/typescript-angular-v2/npm/model/apiResponse.ts diff --git a/samples/client/petstore/typescript-angular-v2/npm/package-lock.json b/samples/client/petstore/typescript-angular-v2/npm/package-lock.json index e75509b02949..d72ef2378788 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/package-lock.json +++ b/samples/client/petstore/typescript-angular-v2/npm/package-lock.json @@ -2,6 +2,7 @@ "name": "@swagger/angular2-typescript-petstore", "version": "0.0.1", "lockfileVersion": 1, + "requires": true, "dependencies": { "@angular/common": { "version": "2.4.10", @@ -43,7 +44,10 @@ "version": "5.4.2", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.4.2.tgz", "integrity": "sha1-KjI2/L8D31e64G/Wly/ZnlwI/Pc=", - "dev": true + "dev": true, + "requires": { + "symbol-observable": "1.0.4" + } }, "symbol-observable": { "version": "1.0.4", diff --git a/samples/client/petstore/typescript-angular-v2/npm/package.json b/samples/client/petstore/typescript-angular-v2/npm/package.json index d2e8c69bf95a..fb6731a3b24c 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/package.json +++ b/samples/client/petstore/typescript-angular-v2/npm/package.json @@ -35,6 +35,6 @@ "typescript": "^2.1.5" }, "publishConfig": { - "registry":"https://skimdb.npmjs.com/registry" + "registry": "https://skimdb.npmjs.com/registry" } } 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/PetApi.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/PetApi.ts deleted file mode 100644 index 0d1c1439c34f..000000000000 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/PetApi.ts +++ /dev/null @@ -1,610 +0,0 @@ -/** - * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * 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/add/operator/map'; - -import * as models from '../model/models'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; -import { PetApiInterface } from './PetApiInterface'; - - -@Injectable() -export class PetApi implements PetApiInterface { - - protected basePath = 'http://petstore.swagger.io/v2'; - 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; - } - } - - /** - * - * @summary Add a new pet to the store - * @param body Pet object that needs to be added to the store - */ - public addPet(body: models.Pet, extraHttpRequestParams?: any): Observable<{}> { - return this.addPetWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Deletes a pet - * @param petId Pet id to delete - * @param apiKey - */ - public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}> { - return this.deletePetWithHttpInfo(petId, apiKey, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * Multiple status values can be provided with comma separated strings - * @summary Finds Pets by status - * @param status Status values that need to be considered for filter - */ - public findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable> { - return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * @summary Finds Pets by tags - * @param tags Tags to filter by - */ - public findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable> { - return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * Returns a single pet - * @summary Find pet by ID - * @param petId ID of pet to return - */ - public getPetById(petId: number, extraHttpRequestParams?: any): Observable { - return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Update an existing pet - * @param body Pet object that needs to be added to the store - */ - public updatePet(body: models.Pet, extraHttpRequestParams?: any): Observable<{}> { - return this.updatePetWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Updates a pet in the store with form data - * @param petId ID of pet that needs to be updated - * @param name Updated name of the pet - * @param status Updated status of the pet - */ - public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { - return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary uploads an image - * @param petId ID of pet to update - * @param additionalMetadata Additional data to pass to server - * @param file file to upload - */ - public uploadFile(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable { - return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - - /** - * Add a new pet to the store - * - * @param body Pet object that needs to be added to the store - */ - public addPetWithHttpInfo(body: models.Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter body was null or undefined when calling addPet.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/json', - 'application/xml' - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // 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); - } - - 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 - }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); - } - - /** - * Deletes a pet - * - * @param petId Pet id to delete - * @param apiKey - */ - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams(); - let headers = 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)); - } - - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // 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 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 this.http.request(path, requestOptions); - } - - /** - * Finds Pets by status - * Multiple status values can be provided with comma separated strings - * @param status Status values that need to be considered for filter - */ - public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByStatus'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); - } - if (status) { - queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); - } - - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // 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 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 this.http.request(path, requestOptions); - } - - /** - * Finds Pets by tags - * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * @param tags Tags to filter by - */ - public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByTags'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); - } - if (tags) { - queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); - } - - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // 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 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 this.http.request(path, requestOptions); - } - - /** - * Find pet by ID - * Returns a single pet - * @param petId ID of pet to return - */ - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams(); - let headers = 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 getPetById.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // authentication (api_key) required - if (this.configuration.apiKey) { - headers.set('api_key', this.configuration.apiKey); - } - - 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 this.http.request(path, requestOptions); - } - - /** - * Update an existing pet - * - * @param body Pet object that needs to be added to the store - */ - public updatePetWithHttpInfo(body: models.Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter body was null or undefined when calling updatePet.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/json', - 'application/xml' - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // 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); - } - - 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 - }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); - } - - /** - * Updates a pet in the store with form data - * - * @param petId ID of pet that needs to be updated - * @param name Updated name of the pet - * @param status Updated status of the pet - */ - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams(); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let formParams = new URLSearchParams(); - - // 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 updatePetWithForm.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // 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); - } - - headers.set('Content-Type', 'application/x-www-form-urlencoded'); - - if (name !== undefined) { - formParams.set('name', name); - } - - if (status !== undefined) { - formParams.set('status', status); - } - - 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 this.http.request(path, requestOptions); - } - - /** - * uploads an image - * - * @param petId ID of pet to update - * @param additionalMetadata Additional data to pass to server - * @param file file to upload - */ - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams(); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let formParams = new URLSearchParams(); - - // 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 uploadFile.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - 'multipart/form-data' - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // 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); - } - - headers.set('Content-Type', 'application/x-www-form-urlencoded'); - - if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); - } - - if (file !== undefined) { - formParams.set('file', file); - } - - 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 this.http.request(path, requestOptions); - } - -} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/PetApiInterface.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/PetApiInterface.ts deleted file mode 100644 index 3f7c04d27dba..000000000000 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/PetApiInterface.ts +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * 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. - */ - -import { Headers } from '@angular/http'; - -import { Observable } from 'rxjs/Observable'; - -import * as models from '../model/models'; -import { Configuration } from '../configuration'; - - -export interface PetApiInterface { - defaultHeaders: Headers; - configuration: Configuration; - [others: string]: any; - - /** - * Add a new pet to the store - * - * @param body Pet object that needs to be added to the store - */ - addPet(body: models.Pet, extraHttpRequestParams?: any): Observable<{}>; - - /** - * Deletes a pet - * - * @param petId Pet id to delete - * @param apiKey - */ - deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}>; - - /** - * Finds Pets by status - * Multiple status values can be provided with comma separated strings - * @param status Status values that need to be considered for filter - */ - findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable>; - - /** - * Finds Pets by tags - * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * @param tags Tags to filter by - */ - findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable>; - - /** - * Find pet by ID - * Returns a single pet - * @param petId ID of pet to return - */ - getPetById(petId: number, extraHttpRequestParams?: any): Observable; - - /** - * Update an existing pet - * - * @param body Pet object that needs to be added to the store - */ - updatePet(body: models.Pet, extraHttpRequestParams?: any): Observable<{}>; - - /** - * Updates a pet in the store with form data - * - * @param petId ID of pet that needs to be updated - * @param name Updated name of the pet - * @param status Updated status of the pet - */ - updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}>; - - /** - * uploads an image - * - * @param petId ID of pet to update - * @param additionalMetadata Additional data to pass to server - * @param file file to upload - */ - uploadFile(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable; - -} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/StoreApi.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/StoreApi.ts deleted file mode 100644 index 137c9b76625b..000000000000 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/StoreApi.ts +++ /dev/null @@ -1,266 +0,0 @@ -/** - * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * 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/add/operator/map'; - -import * as models from '../model/models'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; -import { StoreApiInterface } from './StoreApiInterface'; - - -@Injectable() -export class StoreApi implements StoreApiInterface { - - protected basePath = 'http://petstore.swagger.io/v2'; - 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; - } - } - - /** - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * @summary Delete purchase order by ID - * @param orderId ID of the order that needs to be deleted - */ - public deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}> { - return this.deleteOrderWithHttpInfo(orderId, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * Returns a map of status codes to quantities - * @summary Returns pet inventories by status - */ - public getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }> { - return this.getInventoryWithHttpInfo(extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * @summary Find purchase order by ID - * @param orderId ID of pet that needs to be fetched - */ - public getOrderById(orderId: number, extraHttpRequestParams?: any): Observable { - return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Place an order for a pet - * @param body order placed for purchasing the pet - */ - public placeOrder(body: models.Order, extraHttpRequestParams?: any): Observable { - return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - - /** - * Delete purchase order by ID - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * @param orderId ID of the order that needs to be deleted - */ - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 this.http.request(path, requestOptions); - } - - /** - * Returns pet inventories by status - * Returns a map of status codes to quantities - */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/inventory'; - - let queryParameters = new URLSearchParams(); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - // authentication (api_key) required - if (this.configuration.apiKey) { - headers.set('api_key', this.configuration.apiKey); - } - - 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 this.http.request(path, requestOptions); - } - - /** - * Find purchase order by ID - * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * @param orderId ID of pet that needs to be fetched - */ - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 this.http.request(path, requestOptions); - } - - /** - * Place an order for a pet - * - * @param body order placed for purchasing the pet - */ - public placeOrderWithHttpInfo(body: models.Order, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter body was null or undefined when calling placeOrder.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 - }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); - } - -} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/StoreApiInterface.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/StoreApiInterface.ts deleted file mode 100644 index ca2476d82105..000000000000 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/StoreApiInterface.ts +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * 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. - */ - -import { Headers } from '@angular/http'; - -import { Observable } from 'rxjs/Observable'; - -import * as models from '../model/models'; -import { Configuration } from '../configuration'; - - -export interface StoreApiInterface { - defaultHeaders: Headers; - configuration: Configuration; - [others: string]: any; - - /** - * Delete purchase order by ID - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * @param orderId ID of the order that needs to be deleted - */ - deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}>; - - /** - * Returns pet inventories by status - * Returns a map of status codes to quantities - */ - getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }>; - - /** - * Find purchase order by ID - * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * @param orderId ID of pet that needs to be fetched - */ - getOrderById(orderId: number, extraHttpRequestParams?: any): Observable; - - /** - * Place an order for a pet - * - * @param body order placed for purchasing the pet - */ - placeOrder(body: models.Order, extraHttpRequestParams?: any): Observable; - -} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/UserApi.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/UserApi.ts deleted file mode 100644 index 1fb4f6c6f4d5..000000000000 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/UserApi.ts +++ /dev/null @@ -1,507 +0,0 @@ -/** - * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * 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/add/operator/map'; - -import * as models from '../model/models'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; -import { UserApiInterface } from './UserApiInterface'; - - -@Injectable() -export class UserApi implements UserApiInterface { - - protected basePath = 'http://petstore.swagger.io/v2'; - 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 can only be done by the logged in user. - * @summary Create user - * @param body Created user object - */ - public createUser(body: models.User, extraHttpRequestParams?: any): Observable<{}> { - return this.createUserWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Creates list of users with given input array - * @param body List of user object - */ - public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { - return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Creates list of users with given input array - * @param body List of user object - */ - public createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { - return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * This can only be done by the logged in user. - * @summary Delete user - * @param username The name that needs to be deleted - */ - public deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}> { - return this.deleteUserWithHttpInfo(username, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Get user by user name - * @param username The name that needs to be fetched. Use user1 for testing. - */ - public getUserByName(username: string, extraHttpRequestParams?: any): Observable { - return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Logs user into the system - * @param username The user name for login - * @param password The password for login in clear text - */ - public loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable { - return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Logs out current logged in user session - */ - public logoutUser(extraHttpRequestParams?: any): Observable<{}> { - return this.logoutUserWithHttpInfo(extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * This can only be done by the logged in user. - * @summary Updated user - * @param username name that need to be deleted - * @param body Updated user object - */ - public updateUser(username: string, body: models.User, extraHttpRequestParams?: any): Observable<{}> { - return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - - /** - * Create user - * This can only be done by the logged in user. - * @param body Created user object - */ - public createUserWithHttpInfo(body: models.User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter body was null or undefined when calling createUser.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 - }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); - } - - /** - * Creates list of users with given input array - * - * @param body List of user object - */ - public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithArray'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 - }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); - } - - /** - * Creates list of users with given input array - * - * @param body List of user object - */ - public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithList'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 - }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); - } - - /** - * Delete user - * This can only be done by the logged in user. - * @param username The name that needs to be deleted - */ - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter username was null or undefined when calling deleteUser.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 this.http.request(path, requestOptions); - } - - /** - * Get user by user name - * - * @param username The name that needs to be fetched. Use user1 for testing. - */ - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter username was null or undefined when calling getUserByName.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 this.http.request(path, requestOptions); - } - - /** - * Logs user into the system - * - * @param username The user name for login - * @param password The password for login in clear text - */ - public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/login'; - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter username was null or undefined when calling loginUser.'); - } - // verify required parameter 'password' is not null or undefined - if (password === null || password === undefined) { - throw new Error('Required parameter password was null or undefined when calling loginUser.'); - } - if (username !== undefined) { - queryParameters.set('username', username); - } - - if (password !== undefined) { - queryParameters.set('password', password); - } - - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 this.http.request(path, requestOptions); - } - - /** - * Logs out current logged in user session - * - */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/logout'; - - let queryParameters = new URLSearchParams(); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 this.http.request(path, requestOptions); - } - - /** - * Updated user - * This can only be done by the logged in user. - * @param username name that need to be deleted - * @param body Updated user object - */ - public updateUserWithHttpInfo(username: string, body: models.User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams(); - let headers = 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) { - throw new Error('Required parameter username was null or undefined when calling updateUser.'); - } - // verify required parameter 'body' is not null or undefined - if (body === null || body === undefined) { - throw new Error('Required parameter body was null or undefined when calling updateUser.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - ]; - - // to determine the Accept header - let produces: string[] = [ - 'application/json', - 'application/xml' - ]; - - 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 - }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); - } - -} diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/UserApiInterface.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/UserApiInterface.ts deleted file mode 100644 index 067befa18e7f..000000000000 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/UserApiInterface.ts +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. - * - * OpenAPI spec version: 1.0.0 - * Contact: apiteam@swagger.io - * - * 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. - */ - -import { Headers } from '@angular/http'; - -import { Observable } from 'rxjs/Observable'; - -import * as models from '../model/models'; -import { Configuration } from '../configuration'; - - -export interface UserApiInterface { - defaultHeaders: Headers; - configuration: Configuration; - [others: string]: any; - - /** - * Create user - * This can only be done by the logged in user. - * @param body Created user object - */ - createUser(body: models.User, extraHttpRequestParams?: any): Observable<{}>; - - /** - * Creates list of users with given input array - * - * @param body List of user object - */ - createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}>; - - /** - * Creates list of users with given input array - * - * @param body List of user object - */ - createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}>; - - /** - * Delete user - * This can only be done by the logged in user. - * @param username The name that needs to be deleted - */ - deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}>; - - /** - * Get user by user name - * - * @param username The name that needs to be fetched. Use user1 for testing. - */ - getUserByName(username: string, extraHttpRequestParams?: any): Observable; - - /** - * Logs user into the system - * - * @param username The user name for login - * @param password The password for login in clear text - */ - loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable; - - /** - * Logs out current logged in user session - * - */ - logoutUser(extraHttpRequestParams?: any): Observable<{}>; - - /** - * Updated user - * This can only be done by the logged in user. - * @param username name that need to be deleted - * @param body Updated user object - */ - updateUser(username: string, body: models.User, extraHttpRequestParams?: any): Observable<{}>; - -} 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 775efa6b32d3..dae8e02422a8 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 @@ -223,7 +223,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) { @@ -237,34 +237,43 @@ export class PetService implements PetServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -278,14 +287,14 @@ export class PetService implements PetServiceInterface { .replace('${' + 'petId' + '}', encodeURIComponent(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))); } @@ -296,31 +305,39 @@ export class PetService implements PetServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -332,7 +349,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) { @@ -350,31 +367,39 @@ export class PetService implements PetServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -386,7 +411,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) { @@ -404,31 +429,39 @@ export class PetService implements PetServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -441,7 +474,7 @@ export class PetService implements PetServiceInterface { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -455,27 +488,33 @@ export class PetService implements PetServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -487,7 +526,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) { @@ -501,34 +540,43 @@ export class PetService implements PetServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -543,7 +591,7 @@ export class PetService implements PetServiceInterface { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -555,7 +603,8 @@ export class PetService implements PetServiceInterface { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -571,19 +620,23 @@ export class PetService implements PetServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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); } @@ -592,19 +645,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)); } /** @@ -619,7 +676,7 @@ export class PetService implements PetServiceInterface { .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -631,7 +688,8 @@ export class PetService implements PetServiceInterface { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -647,19 +705,23 @@ export class PetService implements PetServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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); } @@ -668,19 +730,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 2c715fbab7c5..5aea93112f5e 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 @@ -153,7 +153,7 @@ export class StoreService implements StoreServiceInterface { .replace('${' + 'orderId' + '}', encodeURIComponent(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) { @@ -167,22 +167,27 @@ export class StoreService implements StoreServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -193,7 +198,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 @@ -202,27 +207,33 @@ export class StoreService implements StoreServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -235,7 +246,7 @@ export class StoreService implements StoreServiceInterface { .replace('${' + 'orderId' + '}', encodeURIComponent(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) { @@ -249,22 +260,27 @@ export class StoreService implements StoreServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -276,7 +292,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) { @@ -290,25 +306,31 @@ export class StoreService implements StoreServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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 0448df9297c8..7a682cc7dfdc 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 @@ -218,7 +218,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) { @@ -232,25 +232,31 @@ export class UserService implements UserServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -262,7 +268,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) { @@ -276,25 +282,31 @@ export class UserService implements UserServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -306,7 +318,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) { @@ -320,25 +332,31 @@ export class UserService implements UserServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -351,7 +369,7 @@ export class UserService implements UserServiceInterface { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -365,22 +383,27 @@ export class UserService implements UserServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -393,7 +416,7 @@ export class UserService implements UserServiceInterface { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -407,22 +430,27 @@ export class UserService implements UserServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -435,7 +463,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) { @@ -461,22 +489,27 @@ export class UserService implements UserServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -487,7 +520,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 @@ -497,22 +530,27 @@ export class UserService implements UserServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -526,7 +564,7 @@ export class UserService implements UserServiceInterface { .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -544,25 +582,31 @@ export class UserService implements UserServiceInterface { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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/model/Category.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/category.ts similarity index 100% rename from samples/client/petstore/typescript-angular-v2/with-interfaces/model/Category.ts rename to samples/client/petstore/typescript-angular-v2/with-interfaces/model/category.ts diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/Order.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/order.ts similarity index 100% rename from samples/client/petstore/typescript-angular-v2/with-interfaces/model/Order.ts rename to samples/client/petstore/typescript-angular-v2/with-interfaces/model/order.ts diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/Pet.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/pet.ts similarity index 100% rename from samples/client/petstore/typescript-angular-v2/with-interfaces/model/Pet.ts rename to samples/client/petstore/typescript-angular-v2/with-interfaces/model/pet.ts diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/Tag.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/tag.ts similarity index 100% rename from samples/client/petstore/typescript-angular-v2/with-interfaces/model/Tag.ts rename to samples/client/petstore/typescript-angular-v2/with-interfaces/model/tag.ts diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/model/User.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/model/user.ts similarity index 100% rename from samples/client/petstore/typescript-angular-v2/with-interfaces/model/User.ts rename to samples/client/petstore/typescript-angular-v2/with-interfaces/model/user.ts 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 25b50dd75468..009aca5391dc 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 @@ -222,7 +222,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) { @@ -236,34 +236,43 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -274,17 +283,17 @@ export class PetService { */ public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); + .replace('${' + 'petId' + '}', encodeURIComponent(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))); } @@ -295,31 +304,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -331,7 +348,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) { @@ -349,31 +366,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -385,7 +410,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) { @@ -403,31 +428,39 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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 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); + 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; + }); } - return this.http.request(path, requestOptions); + + 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; + }); + + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } /** @@ -437,10 +470,10 @@ export class PetService { */ public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); + .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -454,27 +487,33 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -486,7 +525,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) { @@ -500,34 +539,43 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -539,10 +587,10 @@ export class PetService { */ public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); + .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -554,7 +602,8 @@ export class PetService { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -570,19 +619,23 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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); } @@ -591,19 +644,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)); } /** @@ -615,10 +672,10 @@ export class PetService { */ public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', String(petId)); + .replace('${' + 'petId' + '}', encodeURIComponent(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) { @@ -630,7 +687,8 @@ export class PetService { ]; if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); } let canConsumeForm = this.canConsumeForm(consumes); @@ -646,19 +704,23 @@ export class PetService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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); } @@ -667,19 +729,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 1dd4980e43b8..ac284c7ccd35 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 @@ -149,10 +149,10 @@ export class StoreService { */ public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); + .replace('${' + 'orderId' + '}', encodeURIComponent(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) { @@ -166,22 +166,27 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -192,7 +197,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 @@ -201,27 +206,33 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } // 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)); } /** @@ -231,10 +242,10 @@ export class StoreService { */ public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); + .replace('${' + 'orderId' + '}', encodeURIComponent(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) { @@ -248,22 +259,27 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -275,7 +291,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) { @@ -289,25 +305,31 @@ export class StoreService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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 4f24303f5022..752899ac38f0 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 @@ -217,7 +217,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) { @@ -231,25 +231,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -261,7 +267,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) { @@ -275,25 +281,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -305,7 +317,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) { @@ -319,25 +331,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -347,10 +365,10 @@ export class UserService { */ public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); + .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -364,22 +382,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -389,10 +412,10 @@ export class UserService { */ public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); + .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -406,22 +429,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -434,7 +462,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) { @@ -460,22 +488,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -486,7 +519,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 @@ -496,22 +529,27 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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)); } /** @@ -522,10 +560,10 @@ export class UserService { */ public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); + .replace('${' + 'username' + '}', encodeURIComponent(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) { @@ -543,25 +581,31 @@ export class UserService { ]; if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); + headersObservable = headersObservable.do((headers: Headers) => + headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); } - - 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/package-lock.json b/samples/client/petstore/typescript-angular-v4/npm/package-lock.json index 270b88ce43f9..32a7ef05fe67 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/package-lock.json +++ b/samples/client/petstore/typescript-angular-v4/npm/package-lock.json @@ -2,36 +2,52 @@ "name": "@swagger/angular2-typescript-petstore", "version": "0.0.1", "lockfileVersion": 1, + "requires": true, "dependencies": { "@angular/common": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/@angular/common/-/common-4.2.6.tgz", "integrity": "sha1-IQrOS9JON1+LQbpS/rNLGKiH1do=", - "dev": true + "dev": true, + "requires": { + "tslib": "1.7.1" + } }, "@angular/compiler": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-4.2.6.tgz", "integrity": "sha1-ZndW1JXKDUXSBhJooQ1Sr4Ofr/Q=", - "dev": true + "dev": true, + "requires": { + "tslib": "1.7.1" + } }, "@angular/core": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/@angular/core/-/core-4.2.6.tgz", "integrity": "sha1-DByP8BV/B29KfAtyHKFCPxu+Fk4=", - "dev": true + "dev": true, + "requires": { + "tslib": "1.7.1" + } }, "@angular/http": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/@angular/http/-/http-4.2.6.tgz", "integrity": "sha1-SZ4roLvB89cbdt6+wDTJWMrxE04=", - "dev": true + "dev": true, + "requires": { + "tslib": "1.7.1" + } }, "@angular/platform-browser": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-4.2.6.tgz", "integrity": "sha1-oTH/WSIl/mSWvKLJr/YSpNvd9Dc=", - "dev": true + "dev": true, + "requires": { + "tslib": "1.7.1" + } }, "reflect-metadata": { "version": "0.1.10", @@ -43,7 +59,10 @@ "version": "5.4.2", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.4.2.tgz", "integrity": "sha1-KjI2/L8D31e64G/Wly/ZnlwI/Pc=", - "dev": true + "dev": true, + "requires": { + "symbol-observable": "1.0.4" + } }, "symbol-observable": { "version": "1.0.4", 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';