Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript] add encodeURIComponent to encode path parameters #6551

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class {{classname}} {
{{/allParams}}*/
public {{nickname}}WithHttpInfo({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any): Observable<Response> {
const path = this.basePath + '{{{path}}}'{{#pathParams}}
.replace('${' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ export class {{classname}} {
{{#summary}}
* @summary {{&summary}}
{{/summary}}
{{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/
{{#allParams}}
* @param {{paramName}} {{description}}
{{/allParams}}
*/
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
const localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
Expand All @@ -47,6 +49,7 @@ export class {{classname}} {
if ({{paramName}} === null || {{paramName}} === undefined) {
throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.');
}

{{/required}}
{{/allParams}}
{{#queryParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ export class {{classname}} extends Api {
}

{{#operation}}
/**{{#summary}}
/**
{{#summary}}
* {{summary}}
*{{/summary}}{{#notes}}
* {{notes}}{{/notes}}{{#allParams}}
* @param params.{{paramName}} {{description}}{{/allParams}}
{{/summary}}
{{#notes}}
* {{notes}}
{{/notes}}
{{#allParams}}
* @param params.{{paramName}} {{description}}
{{/allParams}}
*/
async {{nickname}}({{#hasParams}}params: I{{operationIdCamelCase}}Params{{/hasParams}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}any{{/returnType}}> {
// Verify required parameters are set
Expand All @@ -52,7 +57,7 @@ export class {{classname}} extends Api {

// Create URL to call
const url = `${this.basePath}{{{path}}}`{{#pathParams}}
.replace(`{${'{{baseName}}'}}`, `${params['{{paramName}}']}`){{/pathParams}};
.replace(`{${'{{baseName}}'}}`, encodeURIComponent(String(${params['{{paramName}}']}))){{/pathParams}};

const response = await this.httpClient.createRequest(url)
// Set HTTP method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
{{/required}}
{{/allParams}}
const path = `{{{path}}}`{{#pathParams}}
.replace(`{${"{{baseName}}"}}`, String({{paramName}})){{/pathParams}};
.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String({{paramName}}))){{/pathParams}};
const urlObj = url.parse(path, true);
const requestOptions = Object.assign({ method: '{{httpMethod}}' }, options);
const headerParameter = {} as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ export class {{classname}} {
{{#summary}}
* @summary {{&summary}}
{{/summary}}
{{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/
{{#allParams}}
* @param {{paramName}} {{description}}
{{/allParams}}
*/
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): JQueryPromise<{ response: JQueryXHR; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
let localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
let localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};

let queryParameters: any = {};
let headerParams: any = {};
Expand All @@ -66,8 +68,8 @@ export class {{classname}} {
if ({{paramName}} === null || {{paramName}} === undefined) {
throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.');
}
{{/required}}

{{/required}}
{{/allParams}}
{{#queryParams}}
{{#isListContainer}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,26 @@ export class {{classname}} {
{{#summary}}
* @summary {{&summary}}
{{/summary}}
{{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/
{{#allParams}}
* @param {{paramName}} {{description}}
{{/allParams}}
*/
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.{{#supportsES6}}IncomingMessage{{/supportsES6}}{{^supportsES6}}ClientResponse{{/supportsES6}}; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
const localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};
let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
let formParams: any = {};

{{#allParams}}{{#required}}
{{#allParams}}
{{#required}}
// verify required parameter '{{paramName}}' is not null or undefined
if ({{paramName}} === null || {{paramName}} === undefined) {
throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.');
}
{{/required}}{{/allParams}}

{{/required}}
{{/allParams}}
{{#queryParams}}
if ({{paramName}} !== undefined) {
queryParameters['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
Expand Down
16 changes: 12 additions & 4 deletions samples/client/petstore/typescript-angularjs/api/PetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class PetApi {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling addPet.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
Expand All @@ -62,14 +63,15 @@ export class PetApi {
*/
public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
// 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.');
}

headerParams['api_key'] = apiKey;

let httpRequestParams: ng.IRequestConfig = {
Expand Down Expand Up @@ -99,6 +101,7 @@ export class PetApi {
if (status === null || status === undefined) {
throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.');
}

if (status !== undefined) {
queryParameters['status'] = status;
}
Expand Down Expand Up @@ -130,6 +133,7 @@ export class PetApi {
if (tags === null || tags === undefined) {
throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.');
}

if (tags !== undefined) {
queryParameters['tags'] = tags;
}
Expand All @@ -154,14 +158,15 @@ export class PetApi {
*/
public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<models.Pet> {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
// 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.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
Expand Down Expand Up @@ -189,6 +194,7 @@ export class PetApi {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling updatePet.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'PUT',
url: localVarPath,
Expand All @@ -212,7 +218,7 @@ export class PetApi {
*/
public updatePetWithForm (petId: number, name?: string, status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
Expand All @@ -222,6 +228,7 @@ export class PetApi {
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.');
}

headerParams['Content-Type'] = 'application/x-www-form-urlencoded';

formParams['name'] = name;
Expand Down Expand Up @@ -251,7 +258,7 @@ export class PetApi {
*/
public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<models.ApiResponse> {
const localVarPath = this.basePath + '/pet/{petId}/uploadImage'
.replace('{' + 'petId' + '}', String(petId));
.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
Expand All @@ -261,6 +268,7 @@ export class PetApi {
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling uploadFile.');
}

headerParams['Content-Type'] = 'application/x-www-form-urlencoded';

formParams['additionalMetadata'] = additionalMetadata;
Expand Down
7 changes: 5 additions & 2 deletions samples/client/petstore/typescript-angularjs/api/StoreApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ export class StoreApi {
*/
public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', String(orderId));
.replace('{' + 'orderId' + '}', encodeURIComponent(String(orderId)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
// 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.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'DELETE',
url: localVarPath,
Expand Down Expand Up @@ -83,14 +84,15 @@ export class StoreApi {
*/
public getOrderById (orderId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<models.Order> {
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', String(orderId));
.replace('{' + 'orderId' + '}', encodeURIComponent(String(orderId)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
// 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.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
Expand Down Expand Up @@ -118,6 +120,7 @@ export class StoreApi {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling placeOrder.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
Expand Down
15 changes: 12 additions & 3 deletions samples/client/petstore/typescript-angularjs/api/UserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class UserApi {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling createUser.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
Expand Down Expand Up @@ -68,6 +69,7 @@ export class UserApi {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
Expand Down Expand Up @@ -96,6 +98,7 @@ export class UserApi {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'POST',
url: localVarPath,
Expand All @@ -117,14 +120,15 @@ export class UserApi {
*/
public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
.replace('{' + 'username' + '}', encodeURIComponent(String(username)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
// 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.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'DELETE',
url: localVarPath,
Expand All @@ -145,14 +149,15 @@ export class UserApi {
*/
public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<models.User> {
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
.replace('{' + 'username' + '}', encodeURIComponent(String(username)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
// 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.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'GET',
url: localVarPath,
Expand Down Expand Up @@ -181,10 +186,12 @@ export class UserApi {
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['username'] = username;
}
Expand Down Expand Up @@ -236,18 +243,20 @@ export class UserApi {
*/
public updateUser (username: string, body: models.User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
.replace('{' + 'username' + '}', encodeURIComponent(String(username)));

let queryParameters: any = {};
let headerParams: any = (<any>Object).assign({}, this.defaultHeaders);
// 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.');
}

let httpRequestParams: ng.IRequestConfig = {
method: 'PUT',
url: localVarPath,
Expand Down
Loading