From 544a01b09db394fc29cb319e5a052670f7934805 Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Mon, 30 Aug 2021 15:33:53 +0200 Subject: [PATCH 1/9] add quotes string fallback to when is an an empty string --- src/templates/template.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/template.ts b/src/templates/template.ts index 64b2f61..9c186e9 100644 --- a/src/templates/template.ts +++ b/src/templates/template.ts @@ -172,7 +172,7 @@ export function enumTemplate(name: string, enumString: string, prefix?: string) export function typeTemplate(name: string, typeString: string, prefix?: string) { return ` - export type ${name} = ${typeString}; + export type ${name} = ${typeString || '""'}; ` } From 5ec9420dcd913e0086eb114d252c881793b1cc55 Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Mon, 13 Sep 2021 15:35:02 +0200 Subject: [PATCH 2/9] added field props to identify if a field is nullable, readonly and/or required --- src/swaggerInterfaces.ts | 2 ++ src/templates/template.ts | 50 +++++++++++++++++++++++---------------- src/utils.ts | 8 +++++++ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/swaggerInterfaces.ts b/src/swaggerInterfaces.ts index 737f6f0..479ffba 100644 --- a/src/swaggerInterfaces.ts +++ b/src/swaggerInterfaces.ts @@ -107,6 +107,8 @@ export interface IDefinitionProperty { type: string enum: any[] format: string + readOnly: boolean + nullable: boolean maxLength: number $ref: string allOf: IDefinitionProperty[] diff --git a/src/templates/template.ts b/src/templates/template.ts index 9c186e9..e7e4901 100644 --- a/src/templates/template.ts +++ b/src/templates/template.ts @@ -29,15 +29,19 @@ export function interfaceTemplate( export interface ${name} { - ${props.map(p => classPropsTemplate( - p.name, - p.type, - p.format, - p.desc, - (!strictNullChecks || !(p.validationModel as any)?.required) && !isAdditionalProperties(p.name), - false, - false - )).join('')} + ${props.map(p => { + const validationModel = p.validationModel as any; + return classPropsTemplate( + p.name, + p.type, + p.format, + p.desc, + (validationModel?.required && !validationModel?.readOnly) && !isAdditionalProperties(p.name), + (!strictNullChecks || validationModel?.nullable) && !isAdditionalProperties(p.name), + false, + false + ) + }).join('')} } ` } @@ -67,16 +71,19 @@ export function classTemplate( export class ${name} { ${props - .map(p => - classPropsTemplate( - p.name, - p.type, - p.format, - p.desc, - !strictNullChecks || !(p.validationModel as any)?.required, - useClassTransformer, - p.isEnum || p.isType, - ) + .map(p => { + const validationModel = p.validationModel as any; + return classPropsTemplate( + p.name, + p.type, + p.format, + p.desc, + (validationModel?.required && !validationModel?.readOnly) && !isAdditionalProperties(p.name), + (!strictNullChecks || validationModel?.nullable) && !isAdditionalProperties(p.name), + false, + false + ) + } ) .join('')} @@ -94,6 +101,7 @@ export function classPropsTemplate( type: string, format: string, description: string, + isRequired: boolean, canNull: boolean, useClassTransformer: boolean, isType: boolean @@ -113,12 +121,12 @@ export function classPropsTemplate( return ` /** ${description || ''} */ ${decorators} - ${filedName}${canNull ? '?' : ''}:${type}; + ${filedName}${!isRequired ? '?' : ''}:${type}${canNull === true ? ' | null' : ''}; ` } else { return ` /** ${description || ''} */ - ${filedName}${canNull ? '?' : ''}:${type}; + ${filedName}${!isRequired ? '?' : ''}:${type}${canNull === true ? ' | null' : ''}; ` } } diff --git a/src/utils.ts b/src/utils.ts index 45420ea..a411031 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -280,5 +280,13 @@ export function getValidationModel(propName: string, prop: IDefinitionProperty, validationModel.maxLength = prop.maxLength hasValidationRules = true } + if (prop.nullable) { + validationModel.nullable = prop.nullable + hasValidationRules = true + } + if (prop.readOnly) { + validationModel.readOnly = prop.readOnly + hasValidationRules = true + } return hasValidationRules ? validationModel : null } \ No newline at end of file From 79ae7d4e2d0cdcc1bc7ea900727b0695f34d5d99 Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Mon, 13 Sep 2021 16:13:42 +0200 Subject: [PATCH 3/9] added to enable previous behavior instead of --- README.md | 3 +++ example/swagger/codegen-customMethodNameMode.js | 5 +++-- example/swagger/codegen-shortOperationId.js | 5 +++-- example/swagger/codegen.generic.js | 5 +++-- example/swagger/codegen.include.js | 7 ++++--- example/swagger/codegen.js | 5 +++-- example/swagger/codegen.v3.js | 5 +++-- src/baseInterfaces.ts | 2 ++ src/index.filter.ts | 6 ++++-- src/index.ts | 13 +++++++++---- src/templates/template.ts | 6 ++++-- src/tsconfig.json | 1 + tsconfig.json | 1 + 13 files changed, 43 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 082131b..742d993 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ export interface ISwaggerOptions { /** custom function to format the output file (default: prettier.format()) **/ format?: (s: string) => string /** match with tsconfig */ + strictRequiredChecks?: boolean | undefined + /** match with tsconfig */ strictNullChecks?: boolean | undefined /** definition Class mode */ modelMode?: 'class' | 'interface' @@ -86,6 +88,7 @@ const defaultOptions: ISwaggerOptions = { useStaticMethod: true, useCustomerRequestInstance: false, include: [], + strictRequiredChecks: true, strictNullChecks: true, /** definition Class mode ,auto use interface mode to streamlined code*/ modelMode?: 'interface' diff --git a/example/swagger/codegen-customMethodNameMode.js b/example/swagger/codegen-customMethodNameMode.js index 6735590..e6e80c2 100644 --- a/example/swagger/codegen-customMethodNameMode.js +++ b/example/swagger/codegen-customMethodNameMode.js @@ -1,4 +1,4 @@ -const { codegen } = require('../../dist/index.js') +const { codegen } = require('../../dist/index.js'); codegen({ methodNameMode: (reqProps) => { @@ -9,9 +9,10 @@ codegen({ }, source: require('../swagger-operationId.json'), outputDir: './swagger/services', + strictRequiredChecks: false, strictNullChecks: false, modelMode: 'interface', extendDefinitionFile: './swagger/customerDefinition.ts', extendGenericType: ['JsonResult'], sharedServiceOptions: true -}) +}); diff --git a/example/swagger/codegen-shortOperationId.js b/example/swagger/codegen-shortOperationId.js index 13f1e8c..ad8bad3 100644 --- a/example/swagger/codegen-shortOperationId.js +++ b/example/swagger/codegen-shortOperationId.js @@ -1,12 +1,13 @@ -const { codegen } = require('../../dist/index.js') +const { codegen } = require('../../dist/index.js'); codegen({ methodNameMode: 'shortOperationId', source: require('../swagger-operationId.json'), outputDir: './swagger/services', + strictRequiredChecks: false, strictNullChecks: false, modelMode: 'interface', extendDefinitionFile: './swagger/customerDefinition.ts', extendGenericType: ['JsonResult'], sharedServiceOptions: true -}) +}); diff --git a/example/swagger/codegen.generic.js b/example/swagger/codegen.generic.js index 16d5032..499ab9e 100644 --- a/example/swagger/codegen.generic.js +++ b/example/swagger/codegen.generic.js @@ -1,5 +1,5 @@ // const { codegen } = require('swagger-axios-codegen') -const { codegen } = require('../../dist/index.js') +const { codegen } = require('../../dist/index.js'); codegen({ methodNameMode: 'path', @@ -7,6 +7,7 @@ codegen({ // remoteUrl: 'http://localhost:44307/swagger/v1/swagger.json', outputDir: './swagger/services', fileName: 'indexGeneric.ts', + strictRequiredChecks: false, strictNullChecks: false, modelMode: 'interface' -}) +}); diff --git a/example/swagger/codegen.include.js b/example/swagger/codegen.include.js index 058b050..39ba5fb 100644 --- a/example/swagger/codegen.include.js +++ b/example/swagger/codegen.include.js @@ -1,5 +1,5 @@ // const { codegen } = require('swagger-axios-codegen') -const { codegen } = require('../../dist/index.js') +const { codegen } = require('../../dist/index.js'); let include = [ // "products-test", @@ -11,12 +11,13 @@ let include = [ // 'Products*', '!Products', { 'User': ['*', '!history'] }, -] +]; codegen({ methodNameMode: 'path', + strictRequiredChecks: false, strictNullChecks: false, modelMode: 'interface', source: require('../swagger.json'), outputDir: './swagger/services', include -}) +}); diff --git a/example/swagger/codegen.js b/example/swagger/codegen.js index a052f31..7ee43f9 100644 --- a/example/swagger/codegen.js +++ b/example/swagger/codegen.js @@ -1,15 +1,16 @@ // const { codegen } = require('swagger-axios-codegen') -const { codegen } = require('../../dist/index.js') +const { codegen } = require('../../dist/index.js'); codegen({ methodNameMode: 'path', source: require('../swagger.json'), // remoteUrl: 'http://localhost:44307/swagger/v1/swagger.json', outputDir: './swagger/services', + strictRequiredChecks: false, strictNullChecks: false, // useCustomerRequestInstance: true, modelMode: 'interface', extendDefinitionFile: './swagger/customerDefinition.ts', extendGenericType: ['JsonResult'], sharedServiceOptions: true -}) +}); diff --git a/example/swagger/codegen.v3.js b/example/swagger/codegen.v3.js index 6722584..d8b3de6 100644 --- a/example/swagger/codegen.v3.js +++ b/example/swagger/codegen.v3.js @@ -1,5 +1,5 @@ // const { codegen } = require('swagger-axios-codegen') -const { codegen } = require('../../dist/index.js') +const { codegen } = require('../../dist/index.js'); codegen({ methodNameMode: 'path', @@ -7,6 +7,7 @@ codegen({ // remoteUrl: 'http://localhost:44307/swagger/v1/swagger.json', outputDir: './swagger/services', fileName: 'indexv3.ts', + strictRequiredChecks: false, strictNullChecks: false, modelMode: 'interface' -}) +}); diff --git a/src/baseInterfaces.ts b/src/baseInterfaces.ts index bb7f1df..9de5247 100644 --- a/src/baseInterfaces.ts +++ b/src/baseInterfaces.ts @@ -15,6 +15,8 @@ export interface ISwaggerOptions { includeTypes?: Array format?: (s: string) => string /** match with tsconfig */ + strictRequiredChecks?: boolean | undefined + /** match with tsconfig */ strictNullChecks?: boolean | undefined /** definition Class mode */ modelMode?: 'class' | 'interface' diff --git a/src/index.filter.ts b/src/index.filter.ts index fd6eddd..773e021 100644 --- a/src/index.filter.ts +++ b/src/index.filter.ts @@ -79,11 +79,12 @@ function codegenInclude( if (allImport.includes(item.name)) { const text = options.modelMode === 'interface' - ? interfaceTemplate(item.value.name, item.value.props, [], options.strictNullChecks) + ? interfaceTemplate(item.value.name, item.value.props, [], options.strictRequiredChecks, options.strictNullChecks) : classTemplate( item.value.name, item.value.props, [], + options.strictRequiredChecks, options.strictNullChecks, options.useClassTransformer, options.generateValidationModel @@ -225,11 +226,12 @@ function codegenMultimatchInclude( if (allImport.includes(item.name)) { const text = options.modelMode === 'interface' - ? interfaceTemplate(item.value.name, item.value.props, [], options.strictNullChecks) + ? interfaceTemplate(item.value.name, item.value.props, [], options.strictRequiredChecks, options.strictNullChecks) : classTemplate( item.value.name, item.value.props, [], + options.strictRequiredChecks, options.strictNullChecks, options.useClassTransformer, options.generateValidationModel diff --git a/src/index.ts b/src/index.ts index ac0b25b..c21a84a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,7 @@ const defaultOptions: ISwaggerOptions = { modelMode: 'interface', include: [], includeTypes: [], + strictRequiredChecks: true, strictNullChecks: true, useClassTransformer: false, extendGenericType: [], @@ -139,11 +140,12 @@ export async function codegen(params: ISwaggerOptions) { Object.values(models).forEach(item => { const text = params.modelMode === 'interface' - ? interfaceTemplate(item.value.name, item.value.props, [], params.strictNullChecks) + ? interfaceTemplate(item.value.name, item.value.props, [], params.strictRequiredChecks, params.strictNullChecks) : classTemplate( item.value.name, item.value.props, [], + params.strictRequiredChecks, params.strictNullChecks, options.useClassTransformer, options.generateValidationModel @@ -219,11 +221,12 @@ function codegenAll( Object.values(models).forEach(item => { const text = options.modelMode === 'interface' - ? interfaceTemplate(item.value.name, item.value.props, [], options.strictNullChecks) + ? interfaceTemplate(item.value.name, item.value.props, [], options.strictRequiredChecks, options.strictNullChecks) : classTemplate( item.value.name, item.value.props, [], + options.strictRequiredChecks, options.strictNullChecks, options.useClassTransformer, options.generateValidationModel @@ -313,11 +316,12 @@ function codegenInclude( if (allImport.includes(item.name) || options.includeTypes.includes(item.name)) { const text = options.modelMode === 'interface' - ? interfaceTemplate(item.value.name, item.value.props, [], options.strictNullChecks) + ? interfaceTemplate(item.value.name, item.value.props, [], options.strictRequiredChecks, options.strictNullChecks) : classTemplate( item.value.name, item.value.props, [], + options.strictRequiredChecks, options.strictNullChecks, options.useClassTransformer, options.generateValidationModel @@ -459,11 +463,12 @@ function codegenMultimatchInclude( if (allImport.includes(item.name) || options.includeTypes.includes(item.name)) { const text = options.modelMode === 'interface' - ? interfaceTemplate(item.value.name, item.value.props, [], options.strictNullChecks) + ? interfaceTemplate(item.value.name, item.value.props, [], options.strictRequiredChecks, options.strictNullChecks) : classTemplate( item.value.name, item.value.props, [], + options.strictRequiredChecks, options.strictNullChecks, options.useClassTransformer, options.generateValidationModel diff --git a/src/templates/template.ts b/src/templates/template.ts index e7e4901..250635f 100644 --- a/src/templates/template.ts +++ b/src/templates/template.ts @@ -11,6 +11,7 @@ export function interfaceTemplate( name: string, props: IPropDef[], imports: string[], + strictRequiredChecks: boolean = true, strictNullChecks: boolean = true ) { if (isDefinedGenericTypes(name)) { @@ -36,7 +37,7 @@ export function interfaceTemplate( p.type, p.format, p.desc, - (validationModel?.required && !validationModel?.readOnly) && !isAdditionalProperties(p.name), + ((!strictRequiredChecks) || validationModel?.required && !validationModel?.readOnly) && !isAdditionalProperties(p.name), (!strictNullChecks || validationModel?.nullable) && !isAdditionalProperties(p.name), false, false @@ -51,6 +52,7 @@ export function classTemplate( name: string, props: IPropDef[], imports: string[], + strictRequiredChecks: boolean = true, strictNullChecks: boolean = true, useClassTransformer: boolean, generateValidationModel: boolean @@ -78,7 +80,7 @@ export function classTemplate( p.type, p.format, p.desc, - (validationModel?.required && !validationModel?.readOnly) && !isAdditionalProperties(p.name), + ((!strictRequiredChecks) || validationModel?.required && !validationModel?.readOnly) && !isAdditionalProperties(p.name), (!strictNullChecks || validationModel?.nullable) && !isAdditionalProperties(p.name), false, false diff --git a/src/tsconfig.json b/src/tsconfig.json index ab179b4..9142174 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -27,6 +27,7 @@ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictRequiredChecks": false, /* Enable strict required checks. */ "strictNullChecks": false, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ diff --git a/tsconfig.json b/tsconfig.json index 440175c..5617f82 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -32,6 +32,7 @@ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictRequiredChecks": false, /* Enable strict null checks. */ "strictNullChecks": false, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ From bdd85f20c958da307919bc0ed32f4989fbbaf48e Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Mon, 13 Sep 2021 16:21:35 +0200 Subject: [PATCH 4/9] remove faulty compiler option --- src/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tsconfig.json b/src/tsconfig.json index 9142174..ab179b4 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -27,7 +27,6 @@ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - "strictRequiredChecks": false, /* Enable strict required checks. */ "strictNullChecks": false, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ From 0c22c1c643526fdc9fc924d6c18e73bee4f74890 Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Mon, 13 Sep 2021 16:42:03 +0200 Subject: [PATCH 5/9] fixed strictRecquiredChecks evaluation --- src/templates/template.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/templates/template.ts b/src/templates/template.ts index 250635f..cbdb88e 100644 --- a/src/templates/template.ts +++ b/src/templates/template.ts @@ -32,12 +32,13 @@ export function interfaceTemplate( ${props.map(p => { const validationModel = p.validationModel as any; + const isRequired = !strictRequiredChecks ? false : (validationModel?.required && !validationModel?.readOnly); return classPropsTemplate( p.name, p.type, p.format, p.desc, - ((!strictRequiredChecks) || validationModel?.required && !validationModel?.readOnly) && !isAdditionalProperties(p.name), + isRequired && !isAdditionalProperties(p.name), (!strictNullChecks || validationModel?.nullable) && !isAdditionalProperties(p.name), false, false @@ -75,12 +76,19 @@ export function classTemplate( ${props .map(p => { const validationModel = p.validationModel as any; + if (p.name === 'dimensions') { + console.log("dimensions.strictRequiredChecks", strictRequiredChecks); + console.log("dimensions.required", validationModel?.required); + console.log("dimensions.readOnly", validationModel?.readOnly); + console.log(""); + } + const isRequired = !strictRequiredChecks ? false : (validationModel?.required && !validationModel?.readOnly); return classPropsTemplate( p.name, p.type, p.format, p.desc, - ((!strictRequiredChecks) || validationModel?.required && !validationModel?.readOnly) && !isAdditionalProperties(p.name), + isRequired && !isAdditionalProperties(p.name), (!strictNullChecks || validationModel?.nullable) && !isAdditionalProperties(p.name), false, false From 98231c30fe46702e6903049b5116d70713bee1ea Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Mon, 13 Sep 2021 16:52:00 +0200 Subject: [PATCH 6/9] removed duplicate serviceheader comments --- src/index.ts | 7 +------ src/templates/serviceHeader.ts | 7 ------- src/templates/template.ts | 6 ------ 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/index.ts b/src/index.ts index c21a84a..9116527 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ import { classTemplate, typeTemplate } from './templates/template' -import { customerServiceHeader, serviceHeader, definitionHeader, disableLint } from './templates/serviceHeader' +import { customerServiceHeader, serviceHeader, definitionHeader } from './templates/serviceHeader' import { isOpenApi3, findDeepRefs, setDefinedGenericTypes, getDefinedGenericTypes, trimString } from './utils' import { requestCodegen, IRequestClass, IRequestMethods } from './requestCodegen' import { componentsCodegen } from './componentsCodegen' @@ -126,9 +126,7 @@ export async function codegen(params: ISwaggerOptions) { for (const item of allImport) { if (!uniqueImports.includes(item)) uniqueImports.push(item) } - console.log(disableLint()); - text = disableLint() + text text = serviceTemplate(className + options.serviceNameSuffix, text, uniqueImports) writeFile(options.outputDir || '', className + 'Service.ts', format(text, options)) }) @@ -247,9 +245,7 @@ function codegenAll( } apiSource += text }) - // console.log(disableLint()); - apiSource = disableLint() + apiSource writeFile(options.outputDir || '', options.fileName || '', format(apiSource, options)) } catch (error) { console.log('error', error) @@ -494,7 +490,6 @@ function codegenMultimatchInclude( } }) - apiSource = disableLint() + apiSource apiSource += reqSource + defSource writeFile(options.outputDir || '', options.fileName || '', format(apiSource, options)) } diff --git a/src/templates/serviceHeader.ts b/src/templates/serviceHeader.ts index a61720f..f49f822 100644 --- a/src/templates/serviceHeader.ts +++ b/src/templates/serviceHeader.ts @@ -35,13 +35,6 @@ export function serviceHeader(options: ISwaggerOptions) { `; } -export function disableLint() { - return `/** Generate by swagger-axios-codegen */ - // @ts-nocheck -/* eslint-disable */ - -`} - export function customerServiceHeader(options: ISwaggerOptions) { diff --git a/src/templates/template.ts b/src/templates/template.ts index cbdb88e..5c990ad 100644 --- a/src/templates/template.ts +++ b/src/templates/template.ts @@ -76,12 +76,6 @@ export function classTemplate( ${props .map(p => { const validationModel = p.validationModel as any; - if (p.name === 'dimensions') { - console.log("dimensions.strictRequiredChecks", strictRequiredChecks); - console.log("dimensions.required", validationModel?.required); - console.log("dimensions.readOnly", validationModel?.readOnly); - console.log(""); - } const isRequired = !strictRequiredChecks ? false : (validationModel?.required && !validationModel?.readOnly); return classPropsTemplate( p.name, From 92e37ed2ed93b6d2a76bb34210284abe3303942e Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Tue, 14 Sep 2021 13:20:49 +0200 Subject: [PATCH 7/9] changed readme description for strict required and null options --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 742d993..2bd23ef 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,9 @@ export interface ISwaggerOptions { urlFilters?: Array /** custom function to format the output file (default: prettier.format()) **/ format?: (s: string) => string - /** match with tsconfig */ + /** force required option for fields */ strictRequiredChecks?: boolean | undefined - /** match with tsconfig */ + /** force nullable option for fields */ strictNullChecks?: boolean | undefined /** definition Class mode */ modelMode?: 'class' | 'interface' From da1b296719ad2d976bbceb5eff47238f2af924eb Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Tue, 14 Sep 2021 13:21:29 +0200 Subject: [PATCH 8/9] simplified classPropsTemplate text output --- src/templates/template.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/templates/template.ts b/src/templates/template.ts index 5c990ad..acc4eeb 100644 --- a/src/templates/template.ts +++ b/src/templates/template.ts @@ -106,7 +106,7 @@ export function classPropsTemplate( format: string, description: string, isRequired: boolean, - canNull: boolean, + isNullable: boolean, useClassTransformer: boolean, isType: boolean ) { @@ -125,12 +125,12 @@ export function classPropsTemplate( return ` /** ${description || ''} */ ${decorators} - ${filedName}${!isRequired ? '?' : ''}:${type}${canNull === true ? ' | null' : ''}; + ${filedName}${!isRequired && '?'}:${type}${isNullable && ' | null'}; ` } else { return ` /** ${description || ''} */ - ${filedName}${!isRequired ? '?' : ''}:${type}${canNull === true ? ' | null' : ''}; + ${filedName}${!isRequired && '?'}:${type}${isNullable && ' | null'}; ` } } From 27a0b24061918753985954c35042ff2c0d3fe317 Mon Sep 17 00:00:00 2001 From: Domenik Jones Date: Tue, 14 Sep 2021 13:26:55 +0200 Subject: [PATCH 9/9] fixed some comments for required and nullable checks options --- src/baseInterfaces.ts | 4 ++-- tsconfig.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/baseInterfaces.ts b/src/baseInterfaces.ts index 9de5247..3876d9a 100644 --- a/src/baseInterfaces.ts +++ b/src/baseInterfaces.ts @@ -14,9 +14,9 @@ export interface ISwaggerOptions { /** include types which are not included during the filtering **/ includeTypes?: Array format?: (s: string) => string - /** match with tsconfig */ + /** force required option for fields */ strictRequiredChecks?: boolean | undefined - /** match with tsconfig */ + /** force required option for fields */ strictNullChecks?: boolean | undefined /** definition Class mode */ modelMode?: 'class' | 'interface' diff --git a/tsconfig.json b/tsconfig.json index 5617f82..b3ff7cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -32,7 +32,7 @@ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - "strictRequiredChecks": false, /* Enable strict null checks. */ + "strictRequiredChecks": false, /* Enable strict required checks. */ "strictNullChecks": false, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */