From 9cdee567b1e856269e7351d2e947c35f3676762c Mon Sep 17 00:00:00 2001 From: AllyW Date: Sun, 26 Jan 2025 15:41:03 +0800 Subject: [PATCH] set optional for readyonly property --- src/typespec-aaz/src/convertor.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/typespec-aaz/src/convertor.ts b/src/typespec-aaz/src/convertor.ts index 5651ffb8..5fc33960 100644 --- a/src/typespec-aaz/src/convertor.ts +++ b/src/typespec-aaz/src/convertor.ts @@ -667,12 +667,17 @@ function convertModel2CMDObjectSchemaBase(context: AAZSchemaEmitterContext, mode supportClsSchema: true, }, prop, jsonName); if (schema) { - if (isReadonlyProperty(context.program, prop)) { - schema.readOnly = true; - } if (!context.metadateInfo.isOptional(prop, context.visibility) || prop.name === discriminator?.propertyName) { schema.required = true; } + if (isReadonlyProperty(context.program, prop)) { + schema.readOnly = true; + if (schema.required) { + // read_only property is not required + // console.log("Ignore requirement of the read only property: ", schema.name) + schema.required = false; + } + } if (shouldClientFlatten(context, prop)) { if (schema.type === "object") { schema = {