Skip to content

Commit

Permalink
[typescript-angular] add customized encoder to use '+' char in query …
Browse files Browse the repository at this point in the history
…parameter #6306 (#6334)
  • Loading branch information
taxpon authored and wing328 committed Sep 5, 2017
1 parent 30fb132 commit 84bb749
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -215,7 +216,7 @@ export class PetService {
public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -316,7 +317,7 @@ export class PetService {
public findPetsByStatusWithHttpInfo(status: Array<string>, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -366,7 +367,7 @@ export class PetService {
public findPetsByTagsWithHttpInfo(tags: Array<string>, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -459,7 +460,7 @@ export class PetService {
public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -181,7 +182,7 @@ export class StoreService {
public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable<Response> {
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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -256,7 +257,7 @@ export class StoreService {
public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -210,7 +211,7 @@ export class UserService {
public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -250,7 +251,7 @@ export class UserService {
public createUsersWithArrayInputWithHttpInfo(body: Array<User>, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -290,7 +291,7 @@ export class UserService {
public createUsersWithListInputWithHttpInfo(body: Array<User>, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -407,7 +408,7 @@ export class UserService {
public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -455,7 +456,7 @@ export class UserService {
public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable<Response> {
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


Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions samples/client/petstore/typescript-angular-v2/default/encoder.ts
Original file line number Diff line number Diff line change
@@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -215,7 +216,7 @@ export class PetService {
public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -316,7 +317,7 @@ export class PetService {
public findPetsByStatusWithHttpInfo(status: Array<string>, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -366,7 +367,7 @@ export class PetService {
public findPetsByTagsWithHttpInfo(tags: Array<string>, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -459,7 +460,7 @@ export class PetService {
public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable<Response> {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 84bb749

Please sign in to comment.