-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Description
Currently, in the generated client code for typescript-angular2 as well as for typescript-angular,
the api service builds the API path from the base path and the endpoint path. However, path-parameters are inserted as is, which means they are not url-encoded and therefore a parameter value containing e.g. +, &, %, / etc. leads to problems.
Here is a fragment from a generated code example:
public orderOrderIdSomethingGetWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable<Response> {
const path = this.basePath + '/order/${orderId}/something'
.replace('${' + 'orderId' + '}', orderId);
...
}
Swagger-codegen version
master (2.3.0 SNAPSHOT?)
Swagger declaration file content or url
any swagger file with a path parameter, e.g.
/pet/{petId}/uploadImage:
post:
summary: "uploads an image"
operationId: "uploadFile"
parameters:
- name: "petId"
in: "path"
required: true
type: "string"Command line used for generation
java -jar ../modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l typescript-angular2 -i my-swagger-file.json
Steps to reproduce
Generate the typescript-angular2 client code with the command above and check the ...Api.ts files.
Related issues/PRs
PR #6525 resolves this issue
similar issue: #6306
Suggest a fix/enhancement
An easy fix would be to change
swagger-codegen/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache
Line 120 in 84bb749
| .replace('${' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; |
from
const path = this.basePath + '{{{path}}}'{{#pathParams}}
.replace('${' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
to
const path = this.basePath + '{{{path}}}'{{#pathParams}}
.replace('${' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};