From ed5eea2926f64dc4c08fef7b702edce690231388 Mon Sep 17 00:00:00 2001 From: Xiaogang Date: Tue, 23 Apr 2024 15:02:24 +0800 Subject: [PATCH] Update property.ts Create object only if it is required. --- powershell/llcsharp/model/property.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powershell/llcsharp/model/property.ts b/powershell/llcsharp/model/property.ts index ea43893f817..0288dbb82b1 100644 --- a/powershell/llcsharp/model/property.ts +++ b/powershell/llcsharp/model/property.ts @@ -74,11 +74,11 @@ export class ModelProperty extends BackedProperty implements EnhancedVariable { this.apply(objectInitializer); this.description = description; this.required = isRequired; - if ((this.schema.type === SchemaType.Object || this.schema.type === SchemaType.Dictionary || this.schema.type === SchemaType.Any) && isAnExpression(this.get) && schema.language.csharp?.classImplementation) { + if (this.required && (this.schema.type === SchemaType.Object || this.schema.type === SchemaType.Dictionary || this.schema.type === SchemaType.Any) && isAnExpression(this.get) && schema.language.csharp?.classImplementation) { // for objects, the getter should auto-create a new object this.get = toExpression(`(${this.get.value} = ${this.get.value} ?? new ${schema.language.csharp?.fullname}())`); } } -} \ No newline at end of file +}