Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tcgc] add description for created discriminator property #873

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading