minor fixes to ts nestjs generator (#8622)

This commit is contained in:
William Cheng 2021-02-05 19:45:10 +08:00 committed by GitHub
parent e6cee8eb71
commit c33b5a66e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 35 deletions

View File

@ -1,6 +1,7 @@
generatorName: typescript-nestjs generatorName: typescript-nestjs
outputDir: samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default outputDir: samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-nestjs
additionalProperties: additionalProperties:
nestVersion: 6.0.0 nestVersion: 6.0.0
"npmName": "@openapitools/typescript-nestjs-petstore" "npmName": "@openapitools/typescript-nestjs-petstore"

View File

@ -107,7 +107,7 @@ export class {{classname}} {
{{/isListContainer}} {{/isListContainer}}
{{^isListContainer}} {{^isListContainer}}
if ({{paramName}} !== undefined && {{paramName}} !== null) { if ({{paramName}} !== undefined && {{paramName}} !== null) {
headers['{{baseName}}'] String({{paramName}}); headers['{{baseName}}'] = String({{paramName}});
} }
{{/isListContainer}} {{/isListContainer}}
{{/headerParams}} {{/headerParams}}
@ -147,7 +147,7 @@ export class {{classname}} {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
{{#produces}} {{#produces}}
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}} '{{{mediaType}}}'{{^-last}},{{/-last}}
{{/produces}} {{/produces}}
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -158,7 +158,7 @@ export class {{classname}} {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
{{#consumes}} {{#consumes}}
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}} '{{{mediaType}}}'{{^-last}},{{/-last}}
{{/consumes}} {{/consumes}}
]; ];
{{#bodyParam}} {{#bodyParam}}
@ -167,8 +167,8 @@ export class {{classname}} {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
{{/bodyParam}} {{/bodyParam}}
{{#hasFormParams}} {{#hasFormParams}}
const canConsumeForm = this.canConsumeForm(consumes); const canConsumeForm = this.canConsumeForm(consumes);
let formParams: { append(param: string, value: any): void; }; let formParams: { append(param: string, value: any): void; };
@ -176,6 +176,7 @@ export class {{classname}} {
let convertFormParamsToString = false; let convertFormParamsToString = false;
{{#formParams}} {{#formParams}}
{{#isFile}} {{#isFile}}
// use FormData to transmit files using content-type "multipart/form-data" // use FormData to transmit files using content-type "multipart/form-data"
// see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data
useForm = canConsumeForm; useForm = canConsumeForm;
@ -186,8 +187,8 @@ export class {{classname}} {
} else { } else {
// formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); // formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
} }
{{#formParams}} {{#formParams}}
{{#isListContainer}} {{#isListContainer}}
if ({{paramName}}) { if ({{paramName}}) {
{{#isCollectionFormatMulti}} {{#isCollectionFormatMulti}}

View File

@ -67,7 +67,7 @@ export class PetService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -77,14 +77,13 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
'application/json' 'application/json',
'application/xml' 'application/xml'
]; ];
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return this.httpClient.post<Pet>(`${this.basePath}/pet`, return this.httpClient.post<Pet>(`${this.basePath}/pet`,
pet, pet,
{ {
@ -111,7 +110,7 @@ export class PetService {
let headers = this.defaultHeaders; let headers = this.defaultHeaders;
if (apiKey !== undefined && apiKey !== null) { if (apiKey !== undefined && apiKey !== null) {
headers['api_key'] String(apiKey); headers['api_key'] = String(apiKey);
} }
// authentication (petstore_auth) required // authentication (petstore_auth) required
@ -133,7 +132,6 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
@ -172,7 +170,7 @@ export class PetService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -183,7 +181,6 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`, return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`,
{ {
params: queryParameters, params: queryParameters,
@ -223,7 +220,7 @@ export class PetService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -234,7 +231,6 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`, return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`,
{ {
params: queryParameters, params: queryParameters,
@ -266,7 +262,7 @@ export class PetService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -277,7 +273,6 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
@ -311,7 +306,7 @@ export class PetService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -321,14 +316,13 @@ export class PetService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
'application/json' 'application/json',
'application/xml' 'application/xml'
]; ];
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return this.httpClient.put<Pet>(`${this.basePath}/pet`, return this.httpClient.put<Pet>(`${this.basePath}/pet`,
pet, pet,
{ {
@ -392,6 +386,7 @@ export class PetService {
if (name !== undefined) { if (name !== undefined) {
formParams.append('name', <any>name); formParams.append('name', <any>name);
} }
if (status !== undefined) { if (status !== undefined) {
formParams.append('status', <any>status); formParams.append('status', <any>status);
} }
@ -451,6 +446,7 @@ export class PetService {
let formParams: { append(param: string, value: any): void; }; let formParams: { append(param: string, value: any): void; };
let useForm = false; let useForm = false;
let convertFormParamsToString = false; let convertFormParamsToString = false;
// use FormData to transmit files using content-type "multipart/form-data" // use FormData to transmit files using content-type "multipart/form-data"
// see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data
useForm = canConsumeForm; useForm = canConsumeForm;
@ -463,6 +459,7 @@ export class PetService {
if (additionalMetadata !== undefined) { if (additionalMetadata !== undefined) {
formParams.append('additionalMetadata', <any>additionalMetadata); formParams.append('additionalMetadata', <any>additionalMetadata);
} }
if (file !== undefined) { if (file !== undefined) {
formParams.append('file', <any>file); formParams.append('file', <any>file);
} }

View File

@ -67,7 +67,6 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
@ -103,7 +102,6 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`, return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
@ -129,7 +127,7 @@ export class StoreService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -140,7 +138,6 @@ export class StoreService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
@ -166,7 +163,7 @@ export class StoreService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -182,7 +179,6 @@ export class StoreService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return this.httpClient.post<Order>(`${this.basePath}/store/order`, return this.httpClient.post<Order>(`${this.basePath}/store/order`,
order, order,
{ {

View File

@ -77,7 +77,6 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return this.httpClient.post<any>(`${this.basePath}/user`, return this.httpClient.post<any>(`${this.basePath}/user`,
user, user,
{ {
@ -123,7 +122,6 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`, return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`,
user, user,
{ {
@ -169,7 +167,6 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return this.httpClient.post<any>(`${this.basePath}/user/createWithList`, return this.httpClient.post<any>(`${this.basePath}/user/createWithList`,
user, user,
{ {
@ -210,7 +207,6 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
@ -236,7 +232,7 @@ export class UserService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -247,7 +243,6 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
@ -286,7 +281,7 @@ export class UserService {
// to determine the Accept header // to determine the Accept header
let httpHeaderAccepts: string[] = [ let httpHeaderAccepts: string[] = [
'application/xml' 'application/xml',
'application/json' 'application/json'
]; ];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@ -297,7 +292,6 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.get<string>(`${this.basePath}/user/login`, return this.httpClient.get<string>(`${this.basePath}/user/login`,
{ {
params: queryParameters, params: queryParameters,
@ -333,7 +327,6 @@ export class UserService {
// to determine the Content-Type header // to determine the Content-Type header
const consumes: string[] = [ const consumes: string[] = [
]; ];
return this.httpClient.get<any>(`${this.basePath}/user/logout`, return this.httpClient.get<any>(`${this.basePath}/user/logout`,
{ {
withCredentials: this.configuration.withCredentials, withCredentials: this.configuration.withCredentials,
@ -383,7 +376,6 @@ export class UserService {
if (httpContentTypeSelected != undefined) { if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected; headers['Content-Type'] = httpContentTypeSelected;
} }
return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`, return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
user, user,
{ {