From 5867842d4a84a7ad87043e67e68aae03fc0cfc47 Mon Sep 17 00:00:00 2001 From: sumeyye Date: Tue, 11 Feb 2025 11:30:29 +0300 Subject: [PATCH 1/3] update: nullability and type checks on models --- npm/ng-packs/packages/schematics/src/utils/model.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index 119323e95d..a46eff612d 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -148,7 +148,12 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP typeDef.properties?.forEach(prop => { let name = prop.jsonName || camel(prop.name); name = shouldQuote(name) ? `'${name}'` : name; - const type = simplifyType(prop.type); + + let type = simplifyType(prop.typeSimple); + if (prop.typeSimple.includes('enum')) { + type = simplifyType(prop.type); + } + const refs = parseType(prop.type).reduce( (acc: string[], r) => acc.concat(parseGenerics(r).toGenerics()), [], @@ -182,7 +187,10 @@ export function createRefToImportReducerCreator(params: ModelGeneratorParams) { } function isOptionalProperty(prop: PropertyDef) { - return prop.typeSimple.endsWith('?') || (prop.typeSimple === 'string' && !prop.isRequired); + return ( + prop.typeSimple.endsWith('?') || + ((prop.typeSimple === 'string' || prop.typeSimple.includes('enum')) && !prop.isRequired) + ); } export function parseBaseTypeWithGenericTypes(type: string): string[] { From afc6454ea7b9acca3154b8554924fb84e8bc14c9 Mon Sep 17 00:00:00 2001 From: sumeyye Date: Tue, 11 Feb 2025 11:40:42 +0300 Subject: [PATCH 2/3] update: readability --- npm/ng-packs/packages/schematics/src/utils/model.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index a46eff612d..c1d8423c58 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -187,10 +187,12 @@ export function createRefToImportReducerCreator(params: ModelGeneratorParams) { } function isOptionalProperty(prop: PropertyDef) { - return ( - prop.typeSimple.endsWith('?') || - ((prop.typeSimple === 'string' || prop.typeSimple.includes('enum')) && !prop.isRequired) - ); + const { isRequired, typeSimple } = prop; + if (typeSimple === 'string' || typeSimple.includes('enum')) { + return !isRequired; + } else { + return typeSimple.endsWith('?'); + } } export function parseBaseTypeWithGenericTypes(type: string): string[] { From e996cf907e8d98ea15b44793abd001d0b9528338 Mon Sep 17 00:00:00 2001 From: sumeyye Date: Tue, 11 Feb 2025 11:44:14 +0300 Subject: [PATCH 3/3] rollback: readability --- npm/ng-packs/packages/schematics/src/utils/model.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index c1d8423c58..a46eff612d 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -187,12 +187,10 @@ export function createRefToImportReducerCreator(params: ModelGeneratorParams) { } function isOptionalProperty(prop: PropertyDef) { - const { isRequired, typeSimple } = prop; - if (typeSimple === 'string' || typeSimple.includes('enum')) { - return !isRequired; - } else { - return typeSimple.endsWith('?'); - } + return ( + prop.typeSimple.endsWith('?') || + ((prop.typeSimple === 'string' || prop.typeSimple.includes('enum')) && !prop.isRequired) + ); } export function parseBaseTypeWithGenericTypes(type: string): string[] {