Skip to content

Commit

Permalink
[tcgc] don't add constant value to generated name (#904)
Browse files Browse the repository at this point in the history
fixes #900

---------

Co-authored-by: iscai-msft <[email protected]>
  • Loading branch information
iscai-msft and iscai-msft committed May 23, 2024
1 parent 4be1916 commit 1eb054c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/constant_generated_name-2024-4-22-16-8-23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

don't add constant value to generated name
4 changes: 2 additions & 2 deletions packages/typespec-client-generator-core/src/public-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
isStatusCode,
} from "@typespec/http";
import { Version, getVersions } from "@typespec/versioning";
import { capitalCase, pascalCase } from "change-case";
import { pascalCase } from "change-case";
import pluralize from "pluralize";
import {
getClientNameOverride,
Expand Down Expand Up @@ -551,7 +551,7 @@ function buildNameFromContextPaths(
currContextPathType?.kind === "Number" ||
currContextPathType?.kind === "Boolean"
) {
createName = `${createName}${contextPath[j].displayName}${capitalCase(String(currContextPathType.value))}`;
createName = `${createName}${contextPath[j].displayName}`;
} else if (!currContextPathType?.name) {
// is anonymous model node
createName = `${createName}${contextPath[j].displayName}`;
Expand Down
6 changes: 3 additions & 3 deletions packages/typespec-client-generator-core/test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ describe("typespec-client-generator-core: types", () => {
strictEqual(sdkType.kind, "constant");
strictEqual(sdkType.valueType.kind, "string");
strictEqual(sdkType.value, "json");
strictEqual(sdkType.name, "TestPropJson");
strictEqual(sdkType.name, "TestProp");
strictEqual(sdkType.isGeneratedName, true);
});
it("boolean", async function () {
Expand All @@ -2045,7 +2045,7 @@ describe("typespec-client-generator-core: types", () => {
strictEqual(sdkType.kind, "constant");
strictEqual(sdkType.valueType.kind, "boolean");
strictEqual(sdkType.value, true);
strictEqual(sdkType.name, "TestPropTrue");
strictEqual(sdkType.name, "TestProp");
strictEqual(sdkType.isGeneratedName, true);
});
it("number", async function () {
Expand All @@ -2061,7 +2061,7 @@ describe("typespec-client-generator-core: types", () => {
strictEqual(sdkType.kind, "constant");
strictEqual(sdkType.valueType.kind, "int32");
strictEqual(sdkType.value, 4);
strictEqual(sdkType.name, "TestProp4");
strictEqual(sdkType.name, "TestProp");
strictEqual(sdkType.isGeneratedName, true);
});
});
Expand Down

0 comments on commit 1eb054c

Please sign in to comment.