Skip to content

Commit

Permalink
[tcgc] add description for created discriminator property (#873)
Browse files Browse the repository at this point in the history
fix: #872
  • Loading branch information
tadelesh authored May 21, 2024
1 parent daa3b15 commit ce15072
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/discriminator_doc-2024-4-21-11-13-50.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

add description for created discriminator property
1 change: 1 addition & 0 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions packages/typespec-client-generator-core/test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit ce15072

Please sign in to comment.