diff --git a/.chronus/changes/remove_unionenumvariant-2024-7-20-10-17-16.md b/.chronus/changes/remove_unionenumvariant-2024-7-20-10-17-16.md new file mode 100644 index 0000000000..0424e7a7fb --- /dev/null +++ b/.chronus/changes/remove_unionenumvariant-2024-7-20-10-17-16.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +remove import of `UnionEnumVariant` \ 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 66edc2fdcc..1a632da210 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -113,7 +113,6 @@ import { } from "./public-utils.js"; import { getVersions } from "@typespec/versioning"; -import { UnionEnumVariant } from "../../typespec-azure-core/dist/src/helpers/union-enums.js"; import { getSdkHttpParameter, isSdkHttpParameter } from "./http.js"; export function getTypeSpecBuiltInType( @@ -790,20 +789,17 @@ export function getSdkModelWithDiagnostics( function getSdkEnumValueType( context: TCGCContext, - values: - | IterableIterator - | IterableIterator> - | IterableIterator> + values: (string | number | undefined)[] ): [SdkBuiltInType, readonly Diagnostic[]] { const diagnostics = createDiagnosticCollector(); let kind: "string" | "int32" | "float32" = "string"; for (const value of values) { - if (typeof value.value === "number") { - kind = intOrFloat(value.value); + if (typeof value === "number") { + kind = intOrFloat(value); if (kind === "float32") { break; } - } else if (typeof value.value === "string") { + } else if (typeof value === "string") { kind = "string"; break; } @@ -880,7 +876,12 @@ function getSdkEnumWithDiagnostics( details: docWrapper.details, doc: getDoc(context.program, type), summary: getSummary(context.program, type), - valueType: diagnostics.pipe(getSdkEnumValueType(context, type.members.values())), + valueType: diagnostics.pipe( + getSdkEnumValueType( + context, + [...type.members.values()].map((v) => v.value) + ) + ), values: [], isFixed: true, // enums are always fixed after we switch to use union to represent extensible enum isFlags: false, @@ -950,7 +951,12 @@ export function getSdkUnionEnumWithDiagnostics( summary: getSummary(context.program, union), valueType: diagnostics.pipe(getUnionAsEnumValueType(context, type.union)) ?? - diagnostics.pipe(getSdkEnumValueType(context, type.flattenedMembers.values())), + diagnostics.pipe( + getSdkEnumValueType( + context, + [...type.flattenedMembers.values()].map((v) => v.value) + ) + ), values: [], isFixed: !type.open, isFlags: false, @@ -991,7 +997,12 @@ function getKnownValuesEnum( details: docWrapper.details, doc: getDoc(context.program, type), summary: getSummary(context.program, type), - valueType: diagnostics.pipe(getSdkEnumValueType(context, knownValues.members.values())), + valueType: diagnostics.pipe( + getSdkEnumValueType( + context, + [...knownValues.members.values()].map((v) => v.value) + ) + ), values: [], isFixed: false, isFlags: false,