From 1a9b474a000fd83e8ec5bdabb9749a08c141f5ad Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Thu, 13 Jun 2024 13:44:58 +0800 Subject: [PATCH 1/5] add namespace to model, enum and enum value --- .../typespec-client-generator-core/src/interfaces.ts | 3 +++ packages/typespec-client-generator-core/src/types.ts | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/typespec-client-generator-core/src/interfaces.ts b/packages/typespec-client-generator-core/src/interfaces.ts index 6f0c94818d..1b448175fd 100644 --- a/packages/typespec-client-generator-core/src/interfaces.ts +++ b/packages/typespec-client-generator-core/src/interfaces.ts @@ -247,6 +247,7 @@ export interface SdkNullableType extends SdkTypeBase { export interface SdkEnumType extends SdkTypeBase { kind: "enum"; name: string; + namespace?: string; isGeneratedName: boolean; valueType: SdkBuiltInType; values: SdkEnumValueType[]; @@ -262,6 +263,7 @@ export interface SdkEnumType extends SdkTypeBase { export interface SdkEnumValueType extends SdkTypeBase { kind: "enumvalue"; name: string; + namespace?: string; value: string | number; enumType: SdkEnumType; valueType: SdkBuiltInType; @@ -287,6 +289,7 @@ export interface SdkModelType extends SdkTypeBase { kind: "model"; properties: SdkModelPropertyType[]; name: string; + namespace?: string; /** * @deprecated This property is deprecated. Check the bitwise and value of UsageFlags.MultipartFormData and the `.usage` property on this model. */ diff --git a/packages/typespec-client-generator-core/src/types.ts b/packages/typespec-client-generator-core/src/types.ts index 64dbfe9e6d..12025089bb 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -10,6 +10,7 @@ import { IntrinsicType, Model, ModelProperty, + Namespace, NumericLiteral, Operation, Scalar, @@ -112,6 +113,13 @@ function getEncodeHelper(context: TCGCContext, type: Type, kind: string): string return kind; } +function getNamespaceHelper(ns: Namespace | undefined): string | undefined { + if (ns) { + return getNamespaceFullName(ns); + } + return undefined; +} + /** * Add format info onto an sdk type. Since the format decorator * decorates the ModelProperty, we add the format info onto the property's internal @@ -543,6 +551,7 @@ export function getSdkModelWithDiagnostics( sdkType = { ...getSdkTypeBaseHelper(context, type, "model"), name: name, + namespace: getNamespaceHelper(type.namespace), isGeneratedName: !type.name, description: docWrapper.description, details: docWrapper.details, @@ -663,6 +672,7 @@ export function getSdkEnum(context: TCGCContext, type: Enum, operation?: Operati sdkType = { ...getSdkTypeBaseHelper(context, type, "enum"), name: getLibraryName(context, type), + namespace: getNamespaceHelper(type.namespace), isGeneratedName: false, description: docWrapper.description, details: docWrapper.details, @@ -696,6 +706,7 @@ function getSdkUnionEnumValues( values.push({ kind: "enumvalue", name: name ? name : `${member.value}`, + namespace: enumType.namespace, description: docWrapper.description, details: docWrapper.details, value: member.value, From 80009831f65ae313f91f46b43b2771ae6579dc56 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Thu, 13 Jun 2024 17:07:53 +0800 Subject: [PATCH 2/5] fix and add test cases --- .../src/interfaces.ts | 1 + .../src/types.ts | 2 + .../test/types.test.ts | 74 ++++++++++++++----- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/packages/typespec-client-generator-core/src/interfaces.ts b/packages/typespec-client-generator-core/src/interfaces.ts index 1b448175fd..f09b38c144 100644 --- a/packages/typespec-client-generator-core/src/interfaces.ts +++ b/packages/typespec-client-generator-core/src/interfaces.ts @@ -278,6 +278,7 @@ export interface SdkConstantType extends SdkTypeBase { export interface SdkUnionType extends SdkTypeBase { name: string; + namespace?: string; isGeneratedName: boolean; kind: "union"; values: SdkType[]; diff --git a/packages/typespec-client-generator-core/src/types.ts b/packages/typespec-client-generator-core/src/types.ts index 12025089bb..c71ddddb33 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -369,6 +369,7 @@ export function getSdkUnionWithDiagnostics( retval = { ...getSdkTypeBaseHelper(context, type, "union"), name: getLibraryName(context, type) || getGeneratedName(context, type), + namespace: getNamespaceHelper(type.namespace), isGeneratedName: !type.name, values: nonNullOptions.map((x) => diagnostics.pipe(getClientTypeWithDiagnostics(context, x, operation)) @@ -727,6 +728,7 @@ export function getSdkUnionEnum(context: TCGCContext, type: UnionEnum, operation sdkType = { ...getSdkTypeBaseHelper(context, type.union, "enum"), name, + namespace: getNamespaceHelper(type.union.namespace), isGeneratedName: !type.union.name, description: docWrapper.description, details: docWrapper.details, diff --git a/packages/typespec-client-generator-core/test/types.test.ts b/packages/typespec-client-generator-core/test/types.test.ts index eb4c7a740a..f0c8e62d7c 100644 --- a/packages/typespec-client-generator-core/test/types.test.ts +++ b/packages/typespec-client-generator-core/test/types.test.ts @@ -1111,6 +1111,7 @@ describe("typespec-client-generator-core: types", () => { const sdkType = runner.context.experimental_sdkPackage.enums[0]; strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "DaysOfWeekExtensibleEnum"); + strictEqual(sdkType.namespace, "TestService"); strictEqual(sdkType.valueType.kind, "string"); strictEqual(sdkType.usage & UsageFlags.ApiVersionEnum, 0); // not a versioning enum strictEqual(sdkType.isUnionAsEnum, false); @@ -1163,6 +1164,7 @@ describe("typespec-client-generator-core: types", () => { const sdkType = runner.context.experimental_sdkPackage.enums[0]; strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "Integers"); + strictEqual(sdkType.namespace, "TestService"); strictEqual(sdkType.valueType.kind, "int32"); const values = sdkType.values; strictEqual(values.length, 5); @@ -1197,6 +1199,7 @@ describe("typespec-client-generator-core: types", () => { ok(sdkType); strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "Floats"); + strictEqual(sdkType.namespace, "TestService"); strictEqual(sdkType.valueType.kind, "float32"); const values = sdkType.values; strictEqual(values.length, 3); @@ -1231,6 +1234,7 @@ describe("typespec-client-generator-core: types", () => { const sdkType = runner.context.experimental_sdkPackage.enums[0]; strictEqual(sdkType.isFixed, false); strictEqual(sdkType.name, "Floats"); + strictEqual(sdkType.namespace, "TestService"); strictEqual(sdkType.valueType.kind, "float"); const values = sdkType.values; strictEqual(values.length, 3); @@ -1270,6 +1274,8 @@ describe("typespec-client-generator-core: types", () => { const sdkType = runner.context.experimental_sdkPackage.enums[0]; ok(sdkType); strictEqual(sdkType.isFixed, false); + strictEqual(sdkType.name, "ExtendedEnum"); + strictEqual(sdkType.namespace, "TestService"); strictEqual(sdkType.valueType.kind, "int32"); const values = sdkType.values; strictEqual(values.length, 3); @@ -1315,6 +1321,7 @@ describe("typespec-client-generator-core: types", () => { const sdkType = runnerWithCore.context.experimental_sdkPackage.enums[0]; strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "DaysOfWeekFixedEnum"); + strictEqual(sdkType.namespace, "My.Service"); strictEqual(sdkType.valueType.kind, "string"); const values = sdkType.values; strictEqual(values.length, 7); @@ -1340,6 +1347,7 @@ describe("typespec-client-generator-core: types", () => { deepStrictEqual(value.valueType, sdkType.valueType); } }); + it("enum access transitive closure", async () => { await runner.compileWithBuiltInService(` enum Integers { @@ -1357,6 +1365,7 @@ describe("typespec-client-generator-core: types", () => { strictEqual(runner.context.experimental_sdkPackage.enums[0].access, "internal"); }); + it("crossLanguageDefinitionId", async () => { await runner.compile(` @service({}) @@ -1497,6 +1506,7 @@ describe("typespec-client-generator-core: types", () => { const enumType = getClientType(runner.context, TestUnion); strictEqual(enumType.kind, "enum"); strictEqual(enumType.name, "TestUnionRename"); + strictEqual(enumType.namespace, "N"); strictEqual(enumType.isUnionAsEnum, true); strictEqual(enumType.values[0].name, "ARename"); strictEqual(enumType.values[1].name, "BRename"); @@ -1539,6 +1549,7 @@ describe("typespec-client-generator-core: types", () => { const enumType = nullableType.type; strictEqual(enumType.kind, "enum"); strictEqual(enumType.name, "Test"); + strictEqual(enumType.namespace, "N"); strictEqual(enumType.isUnionAsEnum, true); const values = enumType.values; strictEqual(values.length, 4); @@ -1591,12 +1602,14 @@ describe("typespec-client-generator-core: types", () => { strictEqual(unionType.kind, "union"); strictEqual(unionType.name, "Test"); + strictEqual(unionType.namespace, "N"); const values = unionType.values; strictEqual(values.length, 3); const a = values[0] as SdkEnumType; - strictEqual(a.name, "A"); strictEqual(a.kind, "enum"); + strictEqual(a.name, "A"); + strictEqual(a.namespace, "N"); strictEqual(a.isUnionAsEnum, true); strictEqual(a.values[0].name, "A1"); strictEqual(a.values[0].value, "A1"); @@ -1604,15 +1617,17 @@ describe("typespec-client-generator-core: types", () => { strictEqual(a.values[1].value, "A2"); const b = values[1] as SdkEnumType; - strictEqual(b.name, "B"); strictEqual(b.kind, "enum"); + strictEqual(b.name, "B"); + strictEqual(b.namespace, "N"); strictEqual(b.isUnionAsEnum, true); strictEqual(b.values[0].name, "B"); strictEqual(b.values[0].value, "B"); const c = values[2] as SdkEnumType; - strictEqual(c.name, "C"); strictEqual(c.kind, "enum"); + strictEqual(c.name, "C"); + strictEqual(c.namespace, "N"); strictEqual(c.isUnionAsEnum, false); strictEqual(c.values[0].name, "C"); strictEqual(c.values[0].value, "C"); @@ -1644,6 +1659,7 @@ describe("typespec-client-generator-core: types", () => { const modelType = getClientType(runner.context, Test) as SdkModelType; const enumType = modelType.properties[0].type as SdkEnumType; strictEqual(enumType.name, "TestColor"); + strictEqual(enumType.namespace, undefined); // implicitly defined union does not have a namespace strictEqual(enumType.isGeneratedName, true); strictEqual(enumType.isUnionAsEnum, true); // no cross language def id bc it's not a defined object in tsp @@ -1693,16 +1709,19 @@ describe("typespec-client-generator-core: types", () => { const modelType = getClientType(runner.context, Test) as SdkModelType; const unionType = modelType.properties[0].type as SdkUnionType; strictEqual(unionType.name, "TestColor"); + strictEqual(unionType.namespace, undefined); // implicitly defined union does not have a namespace strictEqual(unionType.isGeneratedName, true); const values = unionType.values; const lr = values[0] as SdkEnumType; strictEqual(lr.name, "LR"); + strictEqual(lr.namespace, "N"); strictEqual(lr.isUnionAsEnum, false); strictEqual(lr.values[0].name, "left"); strictEqual(lr.values[1].name, "right"); strictEqual(lr.isFixed, true); const ud = values[1] as SdkEnumType; strictEqual(ud.name, "UD"); + strictEqual(ud.namespace, "N"); strictEqual(ud.isUnionAsEnum, false); strictEqual(ud.values[0].name, "up"); strictEqual(ud.values[1].name, "down"); @@ -1725,6 +1744,7 @@ describe("typespec-client-generator-core: types", () => { const enums = runner.context.experimental_sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); + strictEqual(enums[0].namespace, "DemoService"); strictEqual(enums[0].usage, UsageFlags.ApiVersionEnum); deepStrictEqual( enums[0].values.map((x) => x.value), @@ -1753,6 +1773,7 @@ describe("typespec-client-generator-core: types", () => { const enums = runnerWithVersion.context.experimental_sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); + strictEqual(enums[0].namespace, "DemoService"); strictEqual(enums[0].usage, UsageFlags.ApiVersionEnum); deepStrictEqual( enums[0].values.map((x) => x.value), @@ -1781,6 +1802,7 @@ describe("typespec-client-generator-core: types", () => { const enums = runnerWithVersion.context.experimental_sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); + strictEqual(enums[0].namespace, "DemoService"); strictEqual(enums[0].usage, UsageFlags.ApiVersionEnum); deepStrictEqual( enums[0].values.map((x) => x.value), @@ -1809,6 +1831,7 @@ describe("typespec-client-generator-core: types", () => { const enums = runnerWithVersion.context.experimental_sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); + strictEqual(enums[0].namespace, "DemoService"); strictEqual(enums[0].usage, UsageFlags.ApiVersionEnum); deepStrictEqual( enums[0].values.map((x) => x.value), @@ -1842,8 +1865,10 @@ describe("typespec-client-generator-core: types", () => { const enums = runner.context.experimental_sdkPackage.enums; strictEqual(enums.length, 2); strictEqual(enums[0].name, "LR"); + strictEqual(enums[0].namespace, "N"); strictEqual(enums[0].usage, UsageFlags.Input); strictEqual(enums[1].name, "UD"); + strictEqual(enums[1].namespace, "N"); strictEqual(enums[1].usage, UsageFlags.Input); }); }); @@ -2206,6 +2231,7 @@ describe("typespec-client-generator-core: types", () => { strictEqual(models.length, 1); const recursiveModel = models[0]; strictEqual(recursiveModel.name, "RecursiveModel"); + strictEqual(recursiveModel.namespace, "TestService"); strictEqual(recursiveModel.kind, "model"); strictEqual(recursiveModel.properties.length, 1); const prop = recursiveModel.properties[0]; @@ -2755,6 +2781,7 @@ describe("typespec-client-generator-core: types", () => { const models = runnerWithCore.context.experimental_sdkPackage.models; strictEqual(models.length, 1); strictEqual(models[0].name, "User"); + strictEqual(models[0].namespace, "My.Service"); }); it("filterOutCoreModels false", async () => { @@ -2780,10 +2807,18 @@ describe("typespec-client-generator-core: types", () => { @doc("Creates or updates a User") op createOrUpdate is StandardResourceOperations.ResourceCreateOrUpdate; `); - const models = runnerWithCore.context.experimental_sdkPackage.models; + const models = runnerWithCore.context.experimental_sdkPackage.models.sort((a, b) => + a.name.localeCompare(b.name) + ); strictEqual(models.length, 4); - const modelNames = models.map((model) => model.name).sort(); - deepStrictEqual(modelNames, ["Error", "ErrorResponse", "InnerError", "User"].sort()); + strictEqual(models[0].name, "Error"); + strictEqual(models[0].namespace, "Azure.Core.Foundations"); + strictEqual(models[1].name, "ErrorResponse"); + strictEqual(models[1].namespace, "Azure.Core.Foundations"); + strictEqual(models[2].name, "InnerError"); + strictEqual(models[2].namespace, "Azure.Core.Foundations"); + strictEqual(models[3].name, "User"); + strictEqual(models[3].namespace, "My.Service"); }); it("lro core filterOutCoreModels true", async () => { @@ -2812,6 +2847,7 @@ describe("typespec-client-generator-core: types", () => { const models = runnerWithCore.context.experimental_sdkPackage.models; strictEqual(models.length, 1); strictEqual(models[0].name, "User"); + strictEqual(models[0].namespace, "My.Service"); }); it("lro core filterOutCoreModels false", async () => { @@ -2838,19 +2874,20 @@ describe("typespec-client-generator-core: types", () => { @pollingOperation(My.Service.getStatus) op createOrUpdateUser is StandardResourceOperations.LongRunningResourceCreateOrUpdate; `); - const models = runnerWithCore.context.experimental_sdkPackage.models; - strictEqual(models.length, 5); - const modelNames = models.map((model) => model.name).sort(); - deepStrictEqual( - modelNames, - [ - "Error", - "ErrorResponse", - "InnerError", - "User", - "ResourceOperationStatusUserUserError", - ].sort() + const models = runnerWithCore.context.experimental_sdkPackage.models.sort((a, b) => + a.name.localeCompare(b.name) ); + strictEqual(models.length, 5); + strictEqual(models[0].name, "Error"); + strictEqual(models[0].namespace, "Azure.Core.Foundations"); + strictEqual(models[1].name, "ErrorResponse"); + strictEqual(models[1].namespace, "Azure.Core.Foundations"); + strictEqual(models[2].name, "InnerError"); + strictEqual(models[2].namespace, "Azure.Core.Foundations"); + strictEqual(models[3].name, "ResourceOperationStatusUserUserError"); + strictEqual(models[3].namespace, "Azure.Core"); + strictEqual(models[4].name, "User"); + strictEqual(models[4].namespace, "My.Service"); strictEqual(runnerWithCore.context.experimental_sdkPackage.enums.length, 1); strictEqual(runnerWithCore.context.experimental_sdkPackage.enums[0].name, "OperationState"); }); @@ -3400,6 +3437,7 @@ describe("typespec-client-generator-core: types", () => { const models = runner.context.experimental_sdkPackage.models; strictEqual(models.length, 1); strictEqual(models[0].name, "Model1"); + strictEqual(models[0].namespace, "MyService"); strictEqual(models[0].usage, UsageFlags.Input | UsageFlags.Output); }); From 9d5f2ee818ac6fa5ce6b402fbde050a9a5587e30 Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Fri, 14 Jun 2024 10:26:25 +0800 Subject: [PATCH 3/5] Create add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md --- ...space-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md diff --git a/.chronus/changes/add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md b/.chronus/changes/add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md new file mode 100644 index 0000000000..52b8c5af9a --- /dev/null +++ b/.chronus/changes/add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +add namespace to `SdkModelType`, `SdkEnumType`, `SdkEnumValueType` and `SdkUnionType` From dcff6a463605c71781f9466b3211bb33c9fd3813 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Sat, 15 Jun 2024 17:57:32 +0800 Subject: [PATCH 4/5] revert core changes --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index 913aa03f78..216f423a8c 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 913aa03f78cf5b85b03c5efc5a8666b45f48d514 +Subproject commit 216f423a8c4330410a4a6352fc9d2be5f4ee8413 From 5e63b9630acb8f937ba71ee2f4d15a9ec2b13260 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Tue, 18 Jun 2024 14:15:02 +0800 Subject: [PATCH 5/5] renamed namespace to tspnamespace --- ...el-enum-and-enumvalue-2024-5-14-1-46-55.md | 2 +- .../src/interfaces.ts | 8 ++-- .../src/types.ts | 10 ++--- .../test/types/enum-types.test.ts | 44 +++++++++---------- .../test/types/model-types.test.ts | 26 +++++------ 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.chronus/changes/add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md b/.chronus/changes/add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md index 52b8c5af9a..5ff84746d8 100644 --- a/.chronus/changes/add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md +++ b/.chronus/changes/add-name-and-namespace-to-model-enum-and-enumvalue-2024-5-14-1-46-55.md @@ -5,4 +5,4 @@ packages: - "@azure-tools/typespec-client-generator-core" --- -add namespace to `SdkModelType`, `SdkEnumType`, `SdkEnumValueType` and `SdkUnionType` +add `tspNamespace` to `SdkModelType`, `SdkEnumType`, `SdkEnumValueType` and `SdkUnionType` diff --git a/packages/typespec-client-generator-core/src/interfaces.ts b/packages/typespec-client-generator-core/src/interfaces.ts index f09b38c144..0810f32b26 100644 --- a/packages/typespec-client-generator-core/src/interfaces.ts +++ b/packages/typespec-client-generator-core/src/interfaces.ts @@ -247,7 +247,7 @@ export interface SdkNullableType extends SdkTypeBase { export interface SdkEnumType extends SdkTypeBase { kind: "enum"; name: string; - namespace?: string; + tspNamespace?: string; isGeneratedName: boolean; valueType: SdkBuiltInType; values: SdkEnumValueType[]; @@ -263,7 +263,7 @@ export interface SdkEnumType extends SdkTypeBase { export interface SdkEnumValueType extends SdkTypeBase { kind: "enumvalue"; name: string; - namespace?: string; + tspNamespace?: string; value: string | number; enumType: SdkEnumType; valueType: SdkBuiltInType; @@ -278,7 +278,7 @@ export interface SdkConstantType extends SdkTypeBase { export interface SdkUnionType extends SdkTypeBase { name: string; - namespace?: string; + tspNamespace?: string; isGeneratedName: boolean; kind: "union"; values: SdkType[]; @@ -290,7 +290,7 @@ export interface SdkModelType extends SdkTypeBase { kind: "model"; properties: SdkModelPropertyType[]; name: string; - namespace?: string; + tspNamespace?: string; /** * @deprecated This property is deprecated. Check the bitwise and value of UsageFlags.MultipartFormData and the `.usage` property on this model. */ diff --git a/packages/typespec-client-generator-core/src/types.ts b/packages/typespec-client-generator-core/src/types.ts index c71ddddb33..18f9e7617f 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -369,7 +369,7 @@ export function getSdkUnionWithDiagnostics( retval = { ...getSdkTypeBaseHelper(context, type, "union"), name: getLibraryName(context, type) || getGeneratedName(context, type), - namespace: getNamespaceHelper(type.namespace), + tspNamespace: getNamespaceHelper(type.namespace), isGeneratedName: !type.name, values: nonNullOptions.map((x) => diagnostics.pipe(getClientTypeWithDiagnostics(context, x, operation)) @@ -552,7 +552,7 @@ export function getSdkModelWithDiagnostics( sdkType = { ...getSdkTypeBaseHelper(context, type, "model"), name: name, - namespace: getNamespaceHelper(type.namespace), + tspNamespace: getNamespaceHelper(type.namespace), isGeneratedName: !type.name, description: docWrapper.description, details: docWrapper.details, @@ -673,7 +673,7 @@ export function getSdkEnum(context: TCGCContext, type: Enum, operation?: Operati sdkType = { ...getSdkTypeBaseHelper(context, type, "enum"), name: getLibraryName(context, type), - namespace: getNamespaceHelper(type.namespace), + tspNamespace: getNamespaceHelper(type.namespace), isGeneratedName: false, description: docWrapper.description, details: docWrapper.details, @@ -707,7 +707,7 @@ function getSdkUnionEnumValues( values.push({ kind: "enumvalue", name: name ? name : `${member.value}`, - namespace: enumType.namespace, + tspNamespace: enumType.tspNamespace, description: docWrapper.description, details: docWrapper.details, value: member.value, @@ -728,7 +728,7 @@ export function getSdkUnionEnum(context: TCGCContext, type: UnionEnum, operation sdkType = { ...getSdkTypeBaseHelper(context, type.union, "enum"), name, - namespace: getNamespaceHelper(type.union.namespace), + tspNamespace: getNamespaceHelper(type.union.namespace), isGeneratedName: !type.union.name, description: docWrapper.description, details: docWrapper.details, diff --git a/packages/typespec-client-generator-core/test/types/enum-types.test.ts b/packages/typespec-client-generator-core/test/types/enum-types.test.ts index 672863b14a..93b0e88180 100644 --- a/packages/typespec-client-generator-core/test/types/enum-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/enum-types.test.ts @@ -43,7 +43,7 @@ describe("typespec-client-generator-core: enum types", () => { const sdkType = runner.context.experimental_sdkPackage.enums[0]; strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "DaysOfWeekExtensibleEnum"); - strictEqual(sdkType.namespace, "TestService"); + strictEqual(sdkType.tspNamespace, "TestService"); strictEqual(sdkType.valueType.kind, "string"); strictEqual(sdkType.usage & UsageFlags.ApiVersionEnum, 0); // not a versioning enum strictEqual(sdkType.isUnionAsEnum, false); @@ -88,7 +88,7 @@ describe("typespec-client-generator-core: enum types", () => { const sdkType = runner.context.experimental_sdkPackage.enums[0]; strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "Integers"); - strictEqual(sdkType.namespace, "TestService"); + strictEqual(sdkType.tspNamespace, "TestService"); strictEqual(sdkType.valueType.kind, "int32"); const values = sdkType.values; strictEqual(values.length, 5); @@ -123,7 +123,7 @@ describe("typespec-client-generator-core: enum types", () => { ok(sdkType); strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "Floats"); - strictEqual(sdkType.namespace, "TestService"); + strictEqual(sdkType.tspNamespace, "TestService"); strictEqual(sdkType.valueType.kind, "float32"); const values = sdkType.values; strictEqual(values.length, 3); @@ -158,7 +158,7 @@ describe("typespec-client-generator-core: enum types", () => { const sdkType = runner.context.experimental_sdkPackage.enums[0]; strictEqual(sdkType.isFixed, false); strictEqual(sdkType.name, "Floats"); - strictEqual(sdkType.namespace, "TestService"); + strictEqual(sdkType.tspNamespace, "TestService"); strictEqual(sdkType.valueType.kind, "float"); const values = sdkType.values; strictEqual(values.length, 3); @@ -199,7 +199,7 @@ describe("typespec-client-generator-core: enum types", () => { ok(sdkType); strictEqual(sdkType.isFixed, false); strictEqual(sdkType.name, "ExtendedEnum"); - strictEqual(sdkType.namespace, "TestService"); + strictEqual(sdkType.tspNamespace, "TestService"); strictEqual(sdkType.valueType.kind, "int32"); const values = sdkType.values; strictEqual(values.length, 3); @@ -245,7 +245,7 @@ describe("typespec-client-generator-core: enum types", () => { const sdkType = runnerWithCore.context.experimental_sdkPackage.enums[0]; strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "DaysOfWeekFixedEnum"); - strictEqual(sdkType.namespace, "My.Service"); + strictEqual(sdkType.tspNamespace, "My.Service"); strictEqual(sdkType.valueType.kind, "string"); const values = sdkType.values; strictEqual(values.length, 7); @@ -422,7 +422,7 @@ describe("typespec-client-generator-core: enum types", () => { const enumType = getClientType(runner.context, TestUnion); strictEqual(enumType.kind, "enum"); strictEqual(enumType.name, "TestUnionRename"); - strictEqual(enumType.namespace, "N"); + strictEqual(enumType.tspNamespace, "N"); strictEqual(enumType.isUnionAsEnum, true); strictEqual(enumType.values[0].name, "ARename"); strictEqual(enumType.values[1].name, "BRename"); @@ -465,7 +465,7 @@ describe("typespec-client-generator-core: enum types", () => { const enumType = nullableType.type; strictEqual(enumType.kind, "enum"); strictEqual(enumType.name, "Test"); - strictEqual(enumType.namespace, "N"); + strictEqual(enumType.tspNamespace, "N"); strictEqual(enumType.isUnionAsEnum, true); const values = enumType.values; strictEqual(values.length, 4); @@ -518,14 +518,14 @@ describe("typespec-client-generator-core: enum types", () => { strictEqual(unionType.kind, "union"); strictEqual(unionType.name, "Test"); - strictEqual(unionType.namespace, "N"); + strictEqual(unionType.tspNamespace, "N"); const values = unionType.values; strictEqual(values.length, 3); const a = values[0] as SdkEnumType; strictEqual(a.kind, "enum"); strictEqual(a.name, "A"); - strictEqual(a.namespace, "N"); + strictEqual(a.tspNamespace, "N"); strictEqual(a.isUnionAsEnum, true); strictEqual(a.values[0].name, "A1"); strictEqual(a.values[0].value, "A1"); @@ -535,7 +535,7 @@ describe("typespec-client-generator-core: enum types", () => { const b = values[1] as SdkEnumType; strictEqual(b.kind, "enum"); strictEqual(b.name, "B"); - strictEqual(b.namespace, "N"); + strictEqual(b.tspNamespace, "N"); strictEqual(b.isUnionAsEnum, true); strictEqual(b.values[0].name, "B"); strictEqual(b.values[0].value, "B"); @@ -543,7 +543,7 @@ describe("typespec-client-generator-core: enum types", () => { const c = values[2] as SdkEnumType; strictEqual(c.kind, "enum"); strictEqual(c.name, "C"); - strictEqual(c.namespace, "N"); + strictEqual(c.tspNamespace, "N"); strictEqual(c.isUnionAsEnum, false); strictEqual(c.values[0].name, "C"); strictEqual(c.values[0].value, "C"); @@ -575,7 +575,7 @@ describe("typespec-client-generator-core: enum types", () => { const modelType = getClientType(runner.context, Test) as SdkModelType; const enumType = modelType.properties[0].type as SdkEnumType; strictEqual(enumType.name, "TestColor"); - strictEqual(enumType.namespace, undefined); // implicitly defined union does not have a namespace + strictEqual(enumType.tspNamespace, undefined); // implicitly defined union does not have a namespace strictEqual(enumType.isGeneratedName, true); strictEqual(enumType.isUnionAsEnum, true); // no cross language def id bc it's not a defined object in tsp @@ -625,19 +625,19 @@ describe("typespec-client-generator-core: enum types", () => { const modelType = getClientType(runner.context, Test) as SdkModelType; const unionType = modelType.properties[0].type as SdkUnionType; strictEqual(unionType.name, "TestColor"); - strictEqual(unionType.namespace, undefined); // implicitly defined union does not have a namespace + strictEqual(unionType.tspNamespace, undefined); // implicitly defined union does not have a namespace strictEqual(unionType.isGeneratedName, true); const values = unionType.values; const lr = values[0] as SdkEnumType; strictEqual(lr.name, "LR"); - strictEqual(lr.namespace, "N"); + strictEqual(lr.tspNamespace, "N"); strictEqual(lr.isUnionAsEnum, false); strictEqual(lr.values[0].name, "left"); strictEqual(lr.values[1].name, "right"); strictEqual(lr.isFixed, true); const ud = values[1] as SdkEnumType; strictEqual(ud.name, "UD"); - strictEqual(ud.namespace, "N"); + strictEqual(ud.tspNamespace, "N"); strictEqual(ud.isUnionAsEnum, false); strictEqual(ud.values[0].name, "up"); strictEqual(ud.values[1].name, "down"); @@ -660,7 +660,7 @@ describe("typespec-client-generator-core: enum types", () => { const enums = runner.context.experimental_sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); - strictEqual(enums[0].namespace, "DemoService"); + strictEqual(enums[0].tspNamespace, "DemoService"); strictEqual(enums[0].usage, UsageFlags.ApiVersionEnum); deepStrictEqual( enums[0].values.map((x) => x.value), @@ -689,7 +689,7 @@ describe("typespec-client-generator-core: enum types", () => { const enums = runnerWithVersion.context.experimental_sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); - strictEqual(enums[0].namespace, "DemoService"); + strictEqual(enums[0].tspNamespace, "DemoService"); strictEqual(enums[0].usage, UsageFlags.ApiVersionEnum); deepStrictEqual( enums[0].values.map((x) => x.value), @@ -718,7 +718,7 @@ describe("typespec-client-generator-core: enum types", () => { const enums = runnerWithVersion.context.experimental_sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); - strictEqual(enums[0].namespace, "DemoService"); + strictEqual(enums[0].tspNamespace, "DemoService"); strictEqual(enums[0].usage, UsageFlags.ApiVersionEnum); deepStrictEqual( enums[0].values.map((x) => x.value), @@ -747,7 +747,7 @@ describe("typespec-client-generator-core: enum types", () => { const enums = runnerWithVersion.context.experimental_sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); - strictEqual(enums[0].namespace, "DemoService"); + strictEqual(enums[0].tspNamespace, "DemoService"); strictEqual(enums[0].usage, UsageFlags.ApiVersionEnum); deepStrictEqual( enums[0].values.map((x) => x.value), @@ -781,10 +781,10 @@ describe("typespec-client-generator-core: enum types", () => { const enums = runner.context.experimental_sdkPackage.enums; strictEqual(enums.length, 2); strictEqual(enums[0].name, "LR"); - strictEqual(enums[0].namespace, "N"); + strictEqual(enums[0].tspNamespace, "N"); strictEqual(enums[0].usage, UsageFlags.Input); strictEqual(enums[1].name, "UD"); - strictEqual(enums[1].namespace, "N"); + strictEqual(enums[1].tspNamespace, "N"); strictEqual(enums[1].usage, UsageFlags.Input); }); }); diff --git a/packages/typespec-client-generator-core/test/types/model-types.test.ts b/packages/typespec-client-generator-core/test/types/model-types.test.ts index 7847fb739b..bcd952ff53 100644 --- a/packages/typespec-client-generator-core/test/types/model-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/model-types.test.ts @@ -142,7 +142,7 @@ describe("typespec-client-generator-core: model types", () => { const recursiveModel = models[0]; strictEqual(recursiveModel.name, "RecursiveModel"); strictEqual(recursiveModel.kind, "model"); - strictEqual(recursiveModel.namespace, "TestService"); + strictEqual(recursiveModel.tspNamespace, "TestService"); strictEqual(recursiveModel.properties.length, 1); const prop = recursiveModel.properties[0]; strictEqual(prop.kind, "property"); @@ -691,7 +691,7 @@ describe("typespec-client-generator-core: model types", () => { const models = runnerWithCore.context.experimental_sdkPackage.models; strictEqual(models.length, 1); strictEqual(models[0].name, "User"); - strictEqual(models[0].namespace, "My.Service"); + strictEqual(models[0].tspNamespace, "My.Service"); }); it("filterOutCoreModels false", async () => { @@ -722,13 +722,13 @@ describe("typespec-client-generator-core: model types", () => { ); strictEqual(models.length, 4); strictEqual(models[0].name, "Error"); - strictEqual(models[0].namespace, "Azure.Core.Foundations"); + strictEqual(models[0].tspNamespace, "Azure.Core.Foundations"); strictEqual(models[1].name, "ErrorResponse"); - strictEqual(models[1].namespace, "Azure.Core.Foundations"); + strictEqual(models[1].tspNamespace, "Azure.Core.Foundations"); strictEqual(models[2].name, "InnerError"); - strictEqual(models[2].namespace, "Azure.Core.Foundations"); + strictEqual(models[2].tspNamespace, "Azure.Core.Foundations"); strictEqual(models[3].name, "User"); - strictEqual(models[3].namespace, "My.Service"); + strictEqual(models[3].tspNamespace, "My.Service"); }); it("lro core filterOutCoreModels true", async () => { @@ -757,7 +757,7 @@ describe("typespec-client-generator-core: model types", () => { const models = runnerWithCore.context.experimental_sdkPackage.models; strictEqual(models.length, 1); strictEqual(models[0].name, "User"); - strictEqual(models[0].namespace, "My.Service"); + strictEqual(models[0].tspNamespace, "My.Service"); }); it("lro core filterOutCoreModels false", async () => { @@ -789,15 +789,15 @@ describe("typespec-client-generator-core: model types", () => { ); strictEqual(models.length, 5); strictEqual(models[0].name, "Error"); - strictEqual(models[0].namespace, "Azure.Core.Foundations"); + strictEqual(models[0].tspNamespace, "Azure.Core.Foundations"); strictEqual(models[1].name, "ErrorResponse"); - strictEqual(models[1].namespace, "Azure.Core.Foundations"); + strictEqual(models[1].tspNamespace, "Azure.Core.Foundations"); strictEqual(models[2].name, "InnerError"); - strictEqual(models[2].namespace, "Azure.Core.Foundations"); + strictEqual(models[2].tspNamespace, "Azure.Core.Foundations"); strictEqual(models[3].name, "ResourceOperationStatusUserUserError"); - strictEqual(models[3].namespace, "Azure.Core"); + strictEqual(models[3].tspNamespace, "Azure.Core"); strictEqual(models[4].name, "User"); - strictEqual(models[4].namespace, "My.Service"); + strictEqual(models[4].tspNamespace, "My.Service"); strictEqual(runnerWithCore.context.experimental_sdkPackage.enums.length, 1); strictEqual(runnerWithCore.context.experimental_sdkPackage.enums[0].name, "OperationState"); }); @@ -1337,7 +1337,7 @@ describe("typespec-client-generator-core: model types", () => { const models = runner.context.experimental_sdkPackage.models; strictEqual(models.length, 1); strictEqual(models[0].name, "Model1"); - strictEqual(models[0].namespace, "MyService"); + strictEqual(models[0].tspNamespace, "MyService"); strictEqual(models[0].usage, UsageFlags.Input | UsageFlags.Output); });