Skip to content

Commit d634f64

Browse files
Don't dedupe enums structurally for C# (can't totally fix for Python/Go until we remove Quicktype)
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cd71ba1 commit d634f64

File tree

5 files changed

+113
-20
lines changed

5 files changed

+113
-20
lines changed

dotnet/src/Generated/Rpc.cs

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dotnet/src/Generated/SessionEvents.cs

Lines changed: 51 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/generated_session_events.go

Lines changed: 31 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/codegen/csharp.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,9 @@ interface EventVariant {
302302
let generatedEnums = new Map<string, { enumName: string; values: string[] }>();
303303

304304
function getOrCreateEnum(parentClassName: string, propName: string, values: string[], enumOutput: string[], description?: string, explicitName?: string): string {
305-
const valuesKey = [...values].sort().join("|");
306-
for (const [, existing] of generatedEnums) {
307-
if ([...existing.values].sort().join("|") === valuesKey) return existing.enumName;
308-
}
309305
const enumName = explicitName ?? `${parentClassName}${propName}`;
306+
const existing = generatedEnums.get(enumName);
307+
if (existing) return existing.enumName;
310308
generatedEnums.set(enumName, { enumName, values });
311309

312310
const lines: string[] = [];
@@ -992,10 +990,10 @@ function emitServerInstanceMethod(
992990
const isReq = requiredSet.has(pName);
993991
const jsonSchema = pSchema as JSONSchema7;
994992
let csType: string;
995-
// If the property has an enum, resolve to the generated enum type
993+
// If the property has an enum, resolve to the generated enum type by title
996994
if (jsonSchema.enum && Array.isArray(jsonSchema.enum) && requestClassName) {
997-
const valuesKey = [...jsonSchema.enum].sort().join("|");
998-
const match = [...generatedEnums.values()].find((e) => [...e.values].sort().join("|") === valuesKey);
995+
const enumTitle = (jsonSchema.title as string) ?? `${requestClassName}${toPascalCase(pName)}`;
996+
const match = generatedEnums.get(enumTitle);
999997
csType = match ? (isReq ? match.enumName : `${match.enumName}?`) : schemaTypeToCSharp(jsonSchema, isReq, rpcKnownTypes);
1000998
} else {
1001999
csType = schemaTypeToCSharp(jsonSchema, isReq, rpcKnownTypes);

scripts/codegen/go.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ interface GoEventVariant {
214214
interface GoCodegenCtx {
215215
structs: string[];
216216
enums: string[];
217-
enumsByValues: Map<string, string>; // sorted-values-key → enumName
217+
enumsByName: Map<string, string>; // enumName → enumName (dedup by type name, not values)
218218
generatedNames: Set<string>;
219219
}
220220

@@ -268,16 +268,16 @@ function findGoDiscriminator(
268268
}
269269

270270
/**
271-
* Get or create a Go enum type, deduplicating by value set.
271+
* Get or create a Go enum type, deduplicating by type name (not by value set).
272+
* Two enums with the same values but different names are distinct types.
272273
*/
273274
function getOrCreateGoEnum(
274275
enumName: string,
275276
values: string[],
276277
ctx: GoCodegenCtx,
277278
description?: string
278279
): string {
279-
const valuesKey = [...values].sort().join("|");
280-
const existing = ctx.enumsByValues.get(valuesKey);
280+
const existing = ctx.enumsByName.get(enumName);
281281
if (existing) return existing;
282282

283283
const lines: string[] = [];
@@ -302,7 +302,7 @@ function getOrCreateGoEnum(
302302
}
303303
lines.push(`)`);
304304

305-
ctx.enumsByValues.set(valuesKey, enumName);
305+
ctx.enumsByName.set(enumName, enumName);
306306
ctx.enums.push(lines.join("\n"));
307307
return enumName;
308308
}
@@ -578,7 +578,7 @@ function generateGoSessionEventsCode(schema: JSONSchema7): string {
578578
const ctx: GoCodegenCtx = {
579579
structs: [],
580580
enums: [],
581-
enumsByValues: new Map(),
581+
enumsByName: new Map(),
582582
generatedNames: new Set(),
583583
};
584584

0 commit comments

Comments
 (0)