MCPcopy Index your code
hub / github.com/github/copilot-sdk / goDiscriminatorMethodName

Function goDiscriminatorMethodName

scripts/codegen/go.ts:1734–1762  ·  view source on GitHub ↗
(
    typeName: string,
    discriminatorProp: string,
    discGoName: string,
    variants: GoDiscriminatedUnionVariant[],
    ctx: GoCodegenCtx
)

Source from the content-addressed store, hash-verified

1732}
1733
1734function goDiscriminatorMethodName(
1735 typeName: string,
1736 discriminatorProp: string,
1737 discGoName: string,
1738 variants: GoDiscriminatedUnionVariant[],
1739 ctx: GoCodegenCtx
1740): string {
1741 const collidesWithVariantField = variants.some((variant) => {
1742 const resolved = resolveSchema(variant.schema, ctx.definitions) ?? variant.schema;
1743 const objectSchema = resolveObjectSchema(resolved, ctx.definitions) ?? resolved;
1744 const variantPreExisting = ctx.generatedNames.has(variant.typeName);
1745 return Object.keys(objectSchema.properties ?? {}).some((propName) => {
1746 const propGoName = toGoFieldName(propName);
1747 if (propName === discriminatorProp) {
1748 // The flat-union variant emission elides single-value discriminators
1749 // and renames multi-value ones to ``Discriminator``, so a natural-name
1750 // collision is only possible when the variant struct is a pre-existing
1751 // type (already in ``ctx.generatedNames``) that retained the discriminator
1752 // as a struct field with its natural Go name. The ``Discriminator``-rename
1753 // collision case is independent and detected by the second clause.
1754 return (variantPreExisting && propGoName === discGoName)
1755 || (variant.discriminatorValues.length > 1 && discGoName === "Discriminator");
1756 }
1757 return propGoName === discGoName;
1758 });
1759 });
1760
1761 return collidesWithVariantField ? `${toGoUnexportedIdentifier(typeName)}${discGoName}` : discGoName;
1762}
1763
1764/**
1765 * Emit a Go interface for a discriminated union (anyOf with const discriminator).

Callers 1

Calls 4

resolveSchemaFunction · 0.85
resolveObjectSchemaFunction · 0.85
toGoFieldNameFunction · 0.85
toGoUnexportedIdentifierFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…