Skip to content

Commit

Permalink
minor fixes to ts nestjs generator (#8622)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored Feb 5, 2021
1 parent e6cee8e commit c33b5a6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 35 deletions.
1 change: 1 addition & 0 deletions bin/configs/typescript-nestjs-v6-provided-in-root.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
generatorName: typescript-nestjs
outputDir: samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-nestjs
additionalProperties:
nestVersion: 6.0.0
"npmName": "@openapitools/typescript-nestjs-petstore"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class {{classname}} {
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined && {{paramName}} !== null) {
headers['{{baseName}}'] String({{paramName}});
headers['{{baseName}}'] = String({{paramName}});
}
{{/isListContainer}}
{{/headerParams}}
Expand Down Expand Up @@ -147,7 +147,7 @@ export class {{classname}} {
// to determine the Accept header
let httpHeaderAccepts: string[] = [
{{#produces}}
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
'{{{mediaType}}}'{{^-last}},{{/-last}}
{{/produces}}
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -158,7 +158,7 @@ export class {{classname}} {
// to determine the Content-Type header
const consumes: string[] = [
{{#consumes}}
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
'{{{mediaType}}}'{{^-last}},{{/-last}}
{{/consumes}}
];
{{#bodyParam}}
Expand All @@ -167,15 +167,16 @@ export class {{classname}} {
headers['Content-Type'] = httpContentTypeSelected;
}
{{/bodyParam}}

{{#hasFormParams}}

const canConsumeForm = this.canConsumeForm(consumes);

let formParams: { append(param: string, value: any): void; };
let useForm = false;
let convertFormParamsToString = false;
{{#formParams}}
{{#isFile}}

// 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
useForm = canConsumeForm;
Expand All @@ -186,8 +187,8 @@ export class {{classname}} {
} else {
// formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
}

{{#formParams}}

{{#isListContainer}}
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class PetService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -77,14 +77,13 @@ export class PetService {

// to determine the Content-Type header
const consumes: string[] = [
'application/json'
'application/json',
'application/xml'
];
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected;
}

return this.httpClient.post<Pet>(`${this.basePath}/pet`,
pet,
{
Expand All @@ -111,7 +110,7 @@ export class PetService {

let headers = this.defaultHeaders;
if (apiKey !== undefined && apiKey !== null) {
headers['api_key'] String(apiKey);
headers['api_key'] = String(apiKey);
}

// authentication (petstore_auth) required
Expand All @@ -133,7 +132,6 @@ export class PetService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
{
withCredentials: this.configuration.withCredentials,
Expand Down Expand Up @@ -172,7 +170,7 @@ export class PetService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -183,7 +181,6 @@ export class PetService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`,
{
params: queryParameters,
Expand Down Expand Up @@ -223,7 +220,7 @@ export class PetService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -234,7 +231,6 @@ export class PetService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`,
{
params: queryParameters,
Expand Down Expand Up @@ -266,7 +262,7 @@ export class PetService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -277,7 +273,6 @@ export class PetService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
{
withCredentials: this.configuration.withCredentials,
Expand Down Expand Up @@ -311,7 +306,7 @@ export class PetService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -321,14 +316,13 @@ export class PetService {

// to determine the Content-Type header
const consumes: string[] = [
'application/json'
'application/json',
'application/xml'
];
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected;
}

return this.httpClient.put<Pet>(`${this.basePath}/pet`,
pet,
{
Expand Down Expand Up @@ -392,6 +386,7 @@ export class PetService {
if (name !== undefined) {
formParams.append('name', <any>name);
}

if (status !== undefined) {
formParams.append('status', <any>status);
}
Expand Down Expand Up @@ -451,6 +446,7 @@ export class PetService {
let formParams: { append(param: string, value: any): void; };
let useForm = false;
let convertFormParamsToString = false;

// 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
useForm = canConsumeForm;
Expand All @@ -463,6 +459,7 @@ export class PetService {
if (additionalMetadata !== undefined) {
formParams.append('additionalMetadata', <any>additionalMetadata);
}

if (file !== undefined) {
formParams.append('file', <any>file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class StoreService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
{
withCredentials: this.configuration.withCredentials,
Expand Down Expand Up @@ -103,7 +102,6 @@ export class StoreService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`,
{
withCredentials: this.configuration.withCredentials,
Expand All @@ -129,7 +127,7 @@ export class StoreService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -140,7 +138,6 @@ export class StoreService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
{
withCredentials: this.configuration.withCredentials,
Expand All @@ -166,7 +163,7 @@ export class StoreService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -182,7 +179,6 @@ export class StoreService {
if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected;
}

return this.httpClient.post<Order>(`${this.basePath}/store/order`,
order,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class UserService {
if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected;
}

return this.httpClient.post<any>(`${this.basePath}/user`,
user,
{
Expand Down Expand Up @@ -123,7 +122,6 @@ export class UserService {
if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected;
}

return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`,
user,
{
Expand Down Expand Up @@ -169,7 +167,6 @@ export class UserService {
if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected;
}

return this.httpClient.post<any>(`${this.basePath}/user/createWithList`,
user,
{
Expand Down Expand Up @@ -210,7 +207,6 @@ export class UserService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
{
withCredentials: this.configuration.withCredentials,
Expand All @@ -236,7 +232,7 @@ export class UserService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -247,7 +243,6 @@ export class UserService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
{
withCredentials: this.configuration.withCredentials,
Expand Down Expand Up @@ -286,7 +281,7 @@ export class UserService {

// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml'
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
Expand All @@ -297,7 +292,6 @@ export class UserService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.get<string>(`${this.basePath}/user/login`,
{
params: queryParameters,
Expand Down Expand Up @@ -333,7 +327,6 @@ export class UserService {
// to determine the Content-Type header
const consumes: string[] = [
];

return this.httpClient.get<any>(`${this.basePath}/user/logout`,
{
withCredentials: this.configuration.withCredentials,
Expand Down Expand Up @@ -383,7 +376,6 @@ export class UserService {
if (httpContentTypeSelected != undefined) {
headers['Content-Type'] = httpContentTypeSelected;
}

return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
user,
{
Expand Down

0 comments on commit c33b5a6

Please sign in to comment.