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

Function registerGoExternalUnionUnmarshalers

scripts/codegen/go.ts:1070–1119  ·  view source on GitHub ↗
(
    schema: JSONSchema7,
    ctx: GoCodegenCtx,
    externalSchemas?: Record<string, JSONSchema7>
)

Source from the content-addressed store, hash-verified

1068}
1069
1070function registerGoExternalUnionUnmarshalers(
1071 schema: JSONSchema7,
1072 ctx: GoCodegenCtx,
1073 externalSchemas?: Record<string, JSONSchema7>
1074): void {
1075 if (!externalSchemas) return;
1076
1077 const externalRefs = collectExternalSchemaRefNames(schema);
1078 for (const [schemaFile, refNames] of externalRefs) {
1079 const externalSchema = externalSchemas[schemaFile];
1080 const externalImport = EXTERNAL_SCHEMA_GO_IMPORT[schemaFile];
1081 if (!externalSchema || !externalImport || externalImport.packageName !== ctx.packageName) continue;
1082
1083 const externalDefinitions = collectDefinitionCollections(externalSchema as Record<string, unknown>);
1084 const definitions: Record<string, JSONSchema7> = {
1085 ...Object.fromEntries(
1086 Object.entries(externalDefinitions.$defs ?? {}).filter(([, value]) => typeof value === "object" && value !== null)
1087 ) as Record<string, JSONSchema7>,
1088 ...Object.fromEntries(
1089 Object.entries(externalDefinitions.definitions ?? {}).filter(([, value]) => typeof value === "object" && value !== null)
1090 ) as Record<string, JSONSchema7>,
1091 };
1092 const planningCtx: GoCodegenCtx = {
1093 structs: [],
1094 encoding: [],
1095 enums: [],
1096 enumsByName: new Map(),
1097 discriminatedUnions: new Map(),
1098 generatedNames: new Set(),
1099 definitions: externalDefinitions,
1100 wrapComments: ctx.wrapComments,
1101 discriminatedUnionRawVariantSuffix: ctx.discriminatedUnionRawVariantSuffix,
1102 packageName: ctx.packageName,
1103 };
1104
1105 for (const refName of refNames) {
1106 const definition = definitions[refName];
1107 if (!definition) continue;
1108
1109 const typeName = goDefinitionName(refName);
1110 const plan = planGoUnion(typeName, definition, planningCtx, true);
1111 if (!plan || plan.kind === "flattenedObject" || plan.kind === "wrapper") continue;
1112
1113 ctx.discriminatedUnions.set(typeName, {
1114 typeName,
1115 unmarshalFuncName: goUnexportedFunctionName("unmarshal", typeName),
1116 });
1117 }
1118 }
1119}
1120
1121function pushGoStructUnmarshalJSON(lines: string[], typeName: string, fields: GoStructField[], ctx: GoCodegenCtx): void {
1122 const unionFields = fields

Callers 1

Calls 6

goDefinitionNameFunction · 0.85
planGoUnionFunction · 0.85
goUnexportedFunctionNameFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…