From ce1507237765e621051110dc123d3b65f8440dd1 Mon Sep 17 00:00:00 2001 From: Chenjie Shi Date: Tue, 21 May 2024 23:24:37 +0800 Subject: [PATCH] [tcgc] add description for created discriminator property (#873) fix: https://github.com/Azure/typespec-azure/issues/872 --- .chronus/changes/discriminator_doc-2024-4-21-11-13-50.md | 7 +++++++ packages/typespec-client-generator-core/src/types.ts | 1 + packages/typespec-client-generator-core/test/types.test.ts | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 .chronus/changes/discriminator_doc-2024-4-21-11-13-50.md diff --git a/.chronus/changes/discriminator_doc-2024-4-21-11-13-50.md b/.chronus/changes/discriminator_doc-2024-4-21-11-13-50.md new file mode 100644 index 0000000000..bda2efe7eb --- /dev/null +++ b/.chronus/changes/discriminator_doc-2024-4-21-11-13-50.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +add description for created discriminator property \ No newline at end of file diff --git a/packages/typespec-client-generator-core/src/types.ts b/packages/typespec-client-generator-core/src/types.ts index ce1cdc9874..34e2bdc55e 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -503,6 +503,7 @@ function addDiscriminatorToModelType( const name = discriminatorProperty ? discriminatorProperty.name : discriminator.propertyName; model.properties.splice(0, 0, { kind: "property", + description: `Discriminator property for ${model.name}.`, optional: false, discriminator: true, serializedName: discriminatorProperty diff --git a/packages/typespec-client-generator-core/test/types.test.ts b/packages/typespec-client-generator-core/test/types.test.ts index 62983aee26..d46864c639 100644 --- a/packages/typespec-client-generator-core/test/types.test.ts +++ b/packages/typespec-client-generator-core/test/types.test.ts @@ -2241,6 +2241,7 @@ describe("typespec-client-generator-core: types", () => { const kindProperty = fish.properties[0]; ok(kindProperty); strictEqual(kindProperty.name, "kind"); + strictEqual(kindProperty.description, "Discriminator property for Fish."); strictEqual(kindProperty.kind, "property"); strictEqual(kindProperty.discriminator, true); strictEqual(kindProperty.type.kind, "string"); @@ -2252,6 +2253,7 @@ describe("typespec-client-generator-core: types", () => { const sharktypeProperty = shark.properties[0]; ok(sharktypeProperty); strictEqual(sharktypeProperty.name, "sharktype"); + strictEqual(sharktypeProperty.description, "Discriminator property for Shark."); strictEqual(sharktypeProperty.kind, "property"); strictEqual(sharktypeProperty.discriminator, true); strictEqual(sharktypeProperty.type.kind, "string"); @@ -2282,6 +2284,7 @@ describe("typespec-client-generator-core: types", () => { const kindProperty = fish.properties[0]; ok(kindProperty); strictEqual(kindProperty.name, "kind"); + strictEqual(kindProperty.description, "Discriminator property for Fish."); strictEqual(kindProperty.kind, "property"); strictEqual(kindProperty.discriminator, true); strictEqual(kindProperty.type.kind, "string"); @@ -2313,6 +2316,7 @@ describe("typespec-client-generator-core: types", () => { const kindProperty = fish.properties[0]; ok(kindProperty); strictEqual(kindProperty.name, "kind"); + strictEqual(kindProperty.description, "Discriminator property for Fish."); strictEqual(kindProperty.kind, "property"); strictEqual(kindProperty.discriminator, true); strictEqual(kindProperty.type.kind, "string"); @@ -2498,6 +2502,7 @@ describe("typespec-client-generator-core: types", () => { const dogKindProperty = dog.properties[0]; ok(dogKindProperty); strictEqual(dogKindProperty.type, dogKind); + strictEqual(dogKindProperty.description, "Discriminator property for Dog."); }); it("discriminator", async () => {