diff --git a/powershell/llcsharp/model/property.ts b/powershell/llcsharp/model/property.ts index 94a82a74ee4..c4e8f16e6a1 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 +}