Skip to content

Commit

Permalink
[tcgc] remove import of UnionEnumVariant (#1399)
Browse files Browse the repository at this point in the history
resolve: #1360

---------

Co-authored-by: iscai-msft <[email protected]>
  • Loading branch information
tadelesh and iscai-msft committed Aug 21, 2024
1 parent ff0dfe0 commit e7972e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

remove import of `UnionEnumVariant`
33 changes: 22 additions & 11 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -790,20 +789,17 @@ export function getSdkModelWithDiagnostics(

function getSdkEnumValueType(
context: TCGCContext,
values:
| IterableIterator<EnumMember>
| IterableIterator<UnionEnumVariant<string>>
| IterableIterator<UnionEnumVariant<number>>
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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e7972e8

Please sign in to comment.