From a3e7f63d02990ad0e81d4094392d4787130ff404 Mon Sep 17 00:00:00 2001 From: Takuro Wada Date: Thu, 17 Aug 2017 10:32:30 +0900 Subject: [PATCH] [typescript-angular] add customized encoder to use '+' char in query parameter #6306 --- .../TypeScriptAngularClientCodegen.java | 1 + .../typescript-angular/api.service.mustache | 3 ++- .../typescript-angular2/encoder.mustache | 17 +++++++++++++++++ .../.swagger-codegen/VERSION | 2 +- .../typescript-angular2/api.module.ts | 4 ++-- .../typescript-angular2/api/fake.service.ts | 14 ++++++++------ .../typescript-angular2/configuration.ts | 14 +++++++------- .../typescript-angular2/encoder.ts | 17 +++++++++++++++++ .../typescript-angular2/variables.ts | 4 ++-- .../default/api/pet.service.ts | 17 +++++++++-------- .../default/api/store.service.ts | 9 +++++---- .../default/api/user.service.ts | 17 +++++++++-------- .../npm/api/pet.service.ts | 17 +++++++++-------- .../npm/api/store.service.ts | 9 +++++---- .../npm/api/user.service.ts | 17 +++++++++-------- .../with-interfaces/api/pet.service.ts | 17 +++++++++-------- .../with-interfaces/api/store.service.ts | 9 +++++---- .../with-interfaces/api/user.service.ts | 17 +++++++++-------- .../typescript-angular2/default/encoder.ts | 17 +++++++++++++++++ .../petstore/typescript-angular2/npm/encoder.ts | 17 +++++++++++++++++ .../with-interfaces/encoder.ts | 17 +++++++++++++++++ 21 files changed, 177 insertions(+), 79 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/typescript-angular2/encoder.mustache create mode 100644 samples/client/petstore-security-test/typescript-angular2/encoder.ts create mode 100644 samples/client/petstore/typescript-angular2/default/encoder.ts create mode 100644 samples/client/petstore/typescript-angular2/npm/encoder.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/encoder.ts diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java index 20f4dc16a891..bd29088651f3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java @@ -84,6 +84,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts")); supportingFiles.add(new SupportingFile("configuration.mustache", getIndexDirectory(), "configuration.ts")); supportingFiles.add(new SupportingFile("variables.mustache", getIndexDirectory(), "variables.ts")); + supportingFiles.add(new SupportingFile("encoder.mustache", getIndexDirectory(), "encoder.ts")); supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore")); supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); 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 85f1fab8d9ee..5da473f5ccbb 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 @@ -15,6 +15,7 @@ import { {{classname}} } from '../{{filename}}'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; {{#withInterfaces}} import { {{classname}}Interface } from './{{classname}}Interface'; {{/withInterfaces}} @@ -118,7 +119,7 @@ export class {{classname}} { const path = this.basePath + '{{{path}}}'{{#pathParams}} .replace('${' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 {{#allParams}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/encoder.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/encoder.mustache new file mode 100644 index 000000000000..f54e40eb8a67 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/encoder.mustache @@ -0,0 +1,17 @@ +/* +* CustomQueryEncoderHelper +* Fix plus sign (+) not encoding, so sent as blank space +* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318 +*/ +import { QueryEncoder } from "@angular/http"; + +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'); + } +} diff --git a/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION b/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION index 7fea99011a6f..f9f7450d1359 100644 --- a/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION +++ b/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION @@ -1 +1 @@ -2.2.3-SNAPSHOT \ 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-angular2/api.module.ts b/samples/client/petstore-security-test/typescript-angular2/api.module.ts index 4ed0510d0d13..c3bde487bc4d 100644 --- a/samples/client/petstore-security-test/typescript-angular2/api.module.ts +++ b/samples/client/petstore-security-test/typescript-angular2/api.module.ts @@ -12,10 +12,10 @@ import { FakeService } from './api/fake.service'; providers: [ FakeService ] }) export class ApiModule { - public static forConfig(configuration: Configuration): ModuleWithProviders { + public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders { return { ngModule: ApiModule, - providers: [ {provide: Configuration, useValue: configuration}] + providers: [ {provide: Configuration, useFactory: configurationFactory}] } } } diff --git a/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts b/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts index ec12093e92c5..818da2925d20 100644 --- a/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts +++ b/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts @@ -10,6 +10,8 @@ * 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'; @@ -21,12 +23,12 @@ import '../rxjs-operators'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; - -/* tslint:disable:no-unused-variable member-ordering */ +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(); @@ -71,8 +73,8 @@ export class FakeService { } /** - * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * + * @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<{}> { @@ -95,12 +97,12 @@ export class FakeService { public testCodeInjectEndRnNRWithHttpInfo(test code inject * ' " =end rn n r?: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/fake'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // to determine the Content-Type header let consumes: string[] = [ - 'application/json', + 'application/json', '*_/ =end -- ' ]; let canConsumeForm = this.canConsumeForm(consumes); @@ -111,7 +113,7 @@ export class FakeService { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', '*_/ =end -- ' ]; diff --git a/samples/client/petstore-security-test/typescript-angular2/configuration.ts b/samples/client/petstore-security-test/typescript-angular2/configuration.ts index 0eed43fd575a..005c3a26df33 100644 --- a/samples/client/petstore-security-test/typescript-angular2/configuration.ts +++ b/samples/client/petstore-security-test/typescript-angular2/configuration.ts @@ -2,18 +2,18 @@ export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string; + accessToken?: string | (() => string); basePath?: string; withCredentials?: boolean; } export class Configuration { - apiKeys: {[ key: string ]: string}; - username: string; - password: string; - accessToken: string | (() => string); - basePath: string; - withCredentials: boolean; + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | (() => string); + basePath?: string; + withCredentials?: boolean; constructor(configurationParameters: ConfigurationParameters = {}) { this.apiKeys = configurationParameters.apiKeys; diff --git a/samples/client/petstore-security-test/typescript-angular2/encoder.ts b/samples/client/petstore-security-test/typescript-angular2/encoder.ts new file mode 100644 index 000000000000..f54e40eb8a67 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular2/encoder.ts @@ -0,0 +1,17 @@ +/* +* CustomQueryEncoderHelper +* Fix plus sign (+) not encoding, so sent as blank space +* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318 +*/ +import { QueryEncoder } from "@angular/http"; + +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'); + } +} diff --git a/samples/client/petstore-security-test/typescript-angular2/variables.ts b/samples/client/petstore-security-test/typescript-angular2/variables.ts index b734b2e59182..6fe58549f395 100644 --- a/samples/client/petstore-security-test/typescript-angular2/variables.ts +++ b/samples/client/petstore-security-test/typescript-angular2/variables.ts @@ -1,4 +1,4 @@ -import { InjectionToken } from '@angular/core'; +import { InjectionToken } from '@angular/core'; export const BASE_PATH = new InjectionToken('basePath'); export const COLLECTION_FORMATS = { @@ -6,4 +6,4 @@ export const COLLECTION_FORMATS = { 'tsv': ' ', 'ssv': ' ', 'pipes': '|' -} \ No newline at end of file +} 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 285f40c739cd..b05fe8fc6371 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 @@ -25,6 +25,7 @@ import { Pet } from '../model/pet'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; @Injectable() @@ -215,7 +216,7 @@ export class PetService { public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -266,7 +267,7 @@ export class PetService { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -316,7 +317,7 @@ export class PetService { public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/findByStatus'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'status' is not null or undefined @@ -366,7 +367,7 @@ export class PetService { public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/findByTags'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'tags' is not null or undefined @@ -417,7 +418,7 @@ export class PetService { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -459,7 +460,7 @@ export class PetService { public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -511,7 +512,7 @@ export class PetService { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -578,7 +579,7 @@ export class PetService { const path = this.basePath + '/pet/${petId}/uploadImage' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined 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 15b9479e5a6c..8765ad7c4a93 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 @@ -24,6 +24,7 @@ import { Order } from '../model/order'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; @Injectable() @@ -145,7 +146,7 @@ export class StoreService { const path = this.basePath + '/store/order/${orderId}' .replace('${' + 'orderId' + '}', String(orderId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined @@ -181,7 +182,7 @@ export class StoreService { public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/inventory'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -219,7 +220,7 @@ export class StoreService { const path = this.basePath + '/store/order/${orderId}' .replace('${' + 'orderId' + '}', String(orderId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined @@ -256,7 +257,7 @@ export class StoreService { public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/order'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined 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 05738cabea6d..4322a11f7efb 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 @@ -24,6 +24,7 @@ import { User } from '../model/user'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; @Injectable() @@ -210,7 +211,7 @@ export class UserService { public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -250,7 +251,7 @@ export class UserService { public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/createWithArray'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -290,7 +291,7 @@ export class UserService { public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/createWithList'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -331,7 +332,7 @@ export class UserService { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -369,7 +370,7 @@ export class UserService { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -407,7 +408,7 @@ export class UserService { public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/login'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -455,7 +456,7 @@ export class UserService { public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/logout'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -490,7 +491,7 @@ export class UserService { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined 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 285f40c739cd..b05fe8fc6371 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 @@ -25,6 +25,7 @@ import { Pet } from '../model/pet'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; @Injectable() @@ -215,7 +216,7 @@ export class PetService { public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -266,7 +267,7 @@ export class PetService { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -316,7 +317,7 @@ export class PetService { public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/findByStatus'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'status' is not null or undefined @@ -366,7 +367,7 @@ export class PetService { public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/findByTags'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'tags' is not null or undefined @@ -417,7 +418,7 @@ export class PetService { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -459,7 +460,7 @@ export class PetService { public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -511,7 +512,7 @@ export class PetService { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -578,7 +579,7 @@ export class PetService { const path = this.basePath + '/pet/${petId}/uploadImage' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined 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 15b9479e5a6c..8765ad7c4a93 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 @@ -24,6 +24,7 @@ import { Order } from '../model/order'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; @Injectable() @@ -145,7 +146,7 @@ export class StoreService { const path = this.basePath + '/store/order/${orderId}' .replace('${' + 'orderId' + '}', String(orderId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined @@ -181,7 +182,7 @@ export class StoreService { public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/inventory'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -219,7 +220,7 @@ export class StoreService { const path = this.basePath + '/store/order/${orderId}' .replace('${' + 'orderId' + '}', String(orderId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined @@ -256,7 +257,7 @@ export class StoreService { public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/order'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined 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 05738cabea6d..4322a11f7efb 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 @@ -24,6 +24,7 @@ import { User } from '../model/user'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; @Injectable() @@ -210,7 +211,7 @@ export class UserService { public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -250,7 +251,7 @@ export class UserService { public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/createWithArray'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -290,7 +291,7 @@ export class UserService { public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/createWithList'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -331,7 +332,7 @@ export class UserService { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -369,7 +370,7 @@ export class UserService { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -407,7 +408,7 @@ export class UserService { public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/login'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -455,7 +456,7 @@ export class UserService { public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/logout'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -490,7 +491,7 @@ export class UserService { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined 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 41774ce9aa7a..cfba17412165 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 @@ -25,6 +25,7 @@ import { Pet } from '../model/pet'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; import { PetServiceInterface } from './PetServiceInterface'; @@ -216,7 +217,7 @@ export class PetService implements PetServiceInterface { public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -267,7 +268,7 @@ export class PetService implements PetServiceInterface { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -317,7 +318,7 @@ export class PetService implements PetServiceInterface { public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/findByStatus'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'status' is not null or undefined @@ -367,7 +368,7 @@ export class PetService implements PetServiceInterface { public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/findByTags'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'tags' is not null or undefined @@ -418,7 +419,7 @@ export class PetService implements PetServiceInterface { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -460,7 +461,7 @@ export class PetService implements PetServiceInterface { public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -512,7 +513,7 @@ export class PetService implements PetServiceInterface { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined @@ -579,7 +580,7 @@ export class PetService implements PetServiceInterface { const path = this.basePath + '/pet/${petId}/uploadImage' .replace('${' + 'petId' + '}', String(petId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'petId' is not null or undefined 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 1b7992f172de..6a3d0fc745cb 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 @@ -24,6 +24,7 @@ import { Order } from '../model/order'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; import { StoreServiceInterface } from './StoreServiceInterface'; @@ -146,7 +147,7 @@ export class StoreService implements StoreServiceInterface { const path = this.basePath + '/store/order/${orderId}' .replace('${' + 'orderId' + '}', String(orderId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined @@ -182,7 +183,7 @@ export class StoreService implements StoreServiceInterface { public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/inventory'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -220,7 +221,7 @@ export class StoreService implements StoreServiceInterface { const path = this.basePath + '/store/order/${orderId}' .replace('${' + 'orderId' + '}', String(orderId)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'orderId' is not null or undefined @@ -257,7 +258,7 @@ export class StoreService implements StoreServiceInterface { public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/order'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined 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 040aede3139e..593c8d71a92d 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 @@ -24,6 +24,7 @@ import { User } from '../model/user'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; import { UserServiceInterface } from './UserServiceInterface'; @@ -211,7 +212,7 @@ export class UserService implements UserServiceInterface { public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -251,7 +252,7 @@ export class UserService implements UserServiceInterface { public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/createWithArray'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -291,7 +292,7 @@ export class UserService implements UserServiceInterface { public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/createWithList'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'body' is not null or undefined @@ -332,7 +333,7 @@ export class UserService implements UserServiceInterface { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -370,7 +371,7 @@ export class UserService implements UserServiceInterface { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -408,7 +409,7 @@ export class UserService implements UserServiceInterface { public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/login'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined @@ -456,7 +457,7 @@ export class UserService implements UserServiceInterface { public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/logout'; - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -491,7 +492,7 @@ export class UserService implements UserServiceInterface { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // verify required parameter 'username' is not null or undefined diff --git a/samples/client/petstore/typescript-angular2/default/encoder.ts b/samples/client/petstore/typescript-angular2/default/encoder.ts new file mode 100644 index 000000000000..f54e40eb8a67 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/default/encoder.ts @@ -0,0 +1,17 @@ +/* +* CustomQueryEncoderHelper +* Fix plus sign (+) not encoding, so sent as blank space +* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318 +*/ +import { QueryEncoder } from "@angular/http"; + +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'); + } +} diff --git a/samples/client/petstore/typescript-angular2/npm/encoder.ts b/samples/client/petstore/typescript-angular2/npm/encoder.ts new file mode 100644 index 000000000000..f54e40eb8a67 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/npm/encoder.ts @@ -0,0 +1,17 @@ +/* +* CustomQueryEncoderHelper +* Fix plus sign (+) not encoding, so sent as blank space +* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318 +*/ +import { QueryEncoder } from "@angular/http"; + +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'); + } +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/encoder.ts b/samples/client/petstore/typescript-angular2/with-interfaces/encoder.ts new file mode 100644 index 000000000000..f54e40eb8a67 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/encoder.ts @@ -0,0 +1,17 @@ +/* +* CustomQueryEncoderHelper +* Fix plus sign (+) not encoding, so sent as blank space +* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318 +*/ +import { QueryEncoder } from "@angular/http"; + +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'); + } +}