From 8fee4a8a10b7e7352cd1ad8aee0ef9e3de76487d Mon Sep 17 00:00:00 2001 From: Fahri Gedik Date: Mon, 8 Dec 2025 13:48:18 +0300 Subject: [PATCH] Handle nullable properties in model generator Adds support for marking properties as nullable by appending '| null' to their type in the model generator. Also refines the logic for determining optional properties to better align with 'isRequired' and 'isNullable' flags. --- npm/ng-packs/packages/schematics/src/utils/model.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index 40dacbdfa4..e2213cb37c 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -153,6 +153,10 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP type = simplifyType(prop.type); } + if (prop.isNullable) { + type = `${type} | null`; + } + const refs = parseType(prop.type).reduce( (acc: string[], r) => acc.concat(parseGenerics(r).toGenerics()), [], @@ -186,11 +190,7 @@ export function createRefToImportReducerCreator(params: ModelGeneratorParams) { } function isOptionalProperty(prop: PropertyDef) { - return ( - prop.isNullable || - prop.typeSimple.endsWith('?') || - ((prop.typeSimple === 'string' || prop.typeSimple.includes('enum')) && !prop.isRequired) - ); + return !prop.isRequired && prop.isNullable; } export function parseBaseTypeWithGenericTypes(type: string): string[] {