diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java index 1273b96c5c29..64e76df04828 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java @@ -140,6 +140,15 @@ public class CodegenOperation { return Arrays.asList("PUT", "PATCH").contains(httpMethod.toUpperCase()) && isMemberPath(); } + /** + * Check if body param is allowed for the request method + * + * @return true request method is PUT, PATCH or POST; false otherwise + */ + public boolean isBodyAllowed() { + return Arrays.asList("PUT", "PATCH", "POST").contains(httpMethod.toUpperCase()); + } + /** * Check if act as Restful destroy method * 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 ea2b19b78852..20be74cfa61e 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 @@ -263,17 +263,19 @@ export class {{classname}} { {{/hasFormParams}} {{#useHttpClient}} - return this.httpClient.{{httpMethod}}{{^isResponseFile}}{{/isResponseFile}}(`${this.basePath}{{{path}}}`, {{#bodyParam}}{{paramName}}, {{/bodyParam}} - {{#hasFormParams}}convertFormParamsToString ? formParams.toString() : formParams, {{/hasFormParams}}{ + return this.httpClient.{{httpMethod}}{{^isResponseFile}}{{/isResponseFile}}(`${this.basePath}{{{path}}}`,{{#isBodyAllowed}} + {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams.toString() : formParams{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}}, {{/isBodyAllowed}} + { {{#hasQueryParams}} - params: queryParameters, + params: queryParameters, {{/hasQueryParams}} - headers: headers, + headers: headers, {{#isResponseFile}} - responseType: "blob", + responseType: "blob", {{/isResponseFile}} - withCredentials: this.configuration.withCredentials, - }); + withCredentials: this.configuration.withCredentials, + } + ); {{/useHttpClient}} {{^useHttpClient}} let requestOptions: RequestOptionsArgs = new RequestOptions({ diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts index 16a19cdefa87..93d9553627c2 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts @@ -78,11 +78,13 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.post(`${this.basePath}/pet`, body, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.post(`${this.basePath}/pet`, + body, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -109,11 +111,12 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -141,12 +144,13 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.get(`${this.basePath}/pet/findByStatus`, - { - params: queryParameters, - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.get(`${this.basePath}/pet/findByStatus`, + { + params: queryParameters, + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -174,12 +178,13 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.get(`${this.basePath}/pet/findByTags`, - { - params: queryParameters, - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.get(`${this.basePath}/pet/findByTags`, + { + params: queryParameters, + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -199,11 +204,12 @@ export class PetService { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } - return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -226,11 +232,13 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.put(`${this.basePath}/pet`, body, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.put(`${this.basePath}/pet`, + body, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -279,11 +287,13 @@ export class PetService { formParams = formParams.append('status', status) || formParams; } - return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - convertFormParamsToString ? formParams.toString() : formParams, { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + convertFormParamsToString ? formParams.toString() : formParams, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -335,11 +345,13 @@ export class PetService { formParams = formParams.append('file', file) || formParams; } - return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, - convertFormParamsToString ? formParams.toString() : formParams, { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, + convertFormParamsToString ? formParams.toString() : formParams, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } } diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts index 3b9c88fbb772..7e05cddef8e8 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts @@ -69,11 +69,12 @@ export class StoreService { let headers = this.defaultHeaders; - return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -89,11 +90,12 @@ export class StoreService { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } - return this.httpClient.get(`${this.basePath}/store/inventory`, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.get(`${this.basePath}/store/inventory`, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -108,11 +110,12 @@ export class StoreService { let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -127,11 +130,13 @@ export class StoreService { let headers = this.defaultHeaders; - return this.httpClient.post(`${this.basePath}/store/order`, body, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.post(`${this.basePath}/store/order`, + body, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } } diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts index 4cf879c80ccc..f8146a76f454 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts @@ -69,11 +69,13 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.post(`${this.basePath}/user`, body, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.post(`${this.basePath}/user`, + body, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -88,11 +90,13 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.post(`${this.basePath}/user/createWithArray`, body, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.post(`${this.basePath}/user/createWithArray`, + body, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -107,11 +111,13 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.post(`${this.basePath}/user/createWithList`, body, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.post(`${this.basePath}/user/createWithList`, + body, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -126,11 +132,12 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(String(username))}`, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -145,11 +152,12 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(String(username))}`, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -176,12 +184,13 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/user/login`, - { - params: queryParameters, - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.get(`${this.basePath}/user/login`, + { + params: queryParameters, + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -192,11 +201,12 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/user/logout`, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.get(`${this.basePath}/user/logout`, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } /** @@ -215,11 +225,13 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(String(username))}`, body, - { - headers: headers, - withCredentials: this.configuration.withCredentials, - }); + return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + body, + { + headers: headers, + withCredentials: this.configuration.withCredentials, + } + ); } } diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts index 33b60bb6e163..8c1869a4c130 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts @@ -27,9 +27,6 @@ export interface Order { } export namespace Order { export type StatusEnum = 'placed' | 'approved' | 'delivered'; - export const StatusEnum = { - Placed: 'placed' as StatusEnum, - Approved: 'approved' as StatusEnum, - Delivered: 'delivered' as StatusEnum - } } + + diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts index 342ab5f8e752..ce6a095b840d 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts @@ -29,9 +29,6 @@ export interface Pet { } export namespace Pet { export type StatusEnum = 'available' | 'pending' | 'sold'; - export const StatusEnum = { - Available: 'available' as StatusEnum, - Pending: 'pending' as StatusEnum, - Sold: 'sold' as StatusEnum - } } + +