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

Function mergeGoFlattenedPropertySchema

scripts/codegen/go.ts:2293–2325  ·  view source on GitHub ↗
(
    typeName: string,
    propName: string,
    schemas: JSONSchema7[],
    ctx: GoCodegenCtx
)

Source from the content-addressed store, hash-verified

2291}
2292
2293function mergeGoFlattenedPropertySchema(
2294 typeName: string,
2295 propName: string,
2296 schemas: JSONSchema7[],
2297 ctx: GoCodegenCtx
2298): JSONSchema7 {
2299 if (schemas.length === 1) return schemas[0];
2300
2301 const enumValues = schemas.map((schema) => goStringEnumValues(schema, ctx));
2302 if (enumValues.every((values): values is string[] => values !== undefined)) {
2303 return {
2304 type: "string",
2305 enum: [...new Set(enumValues.flat())],
2306 title: typeName + toGoFieldName(propName),
2307 };
2308 }
2309
2310 const booleanValues = schemas.map((schema) => goBooleanValues(schema, ctx));
2311 if (booleanValues.every((values): values is boolean[] => values !== undefined)) {
2312 return { type: "boolean" };
2313 }
2314
2315 const firstSchemaKey = stableStringify(resolveSchema(schemas[0], ctx.definitions) ?? schemas[0]);
2316 if (schemas.every((schema) => stableStringify(resolveSchema(schema, ctx.definitions) ?? schema) === firstSchemaKey)) {
2317 return schemas[0];
2318 }
2319
2320 const unionSchema = { anyOf: dedupeGoSchemasForMatch(schemas, ctx) };
2321 const definitionRef = goDefinitionRefForEquivalentSchema(unionSchema, ctx);
2322 if (definitionRef) return { $ref: definitionRef };
2323
2324 return unionSchema;
2325}
2326
2327function emitGoFlattenedObjectUnion(
2328 typeName: string,

Callers 1

Calls 7

goStringEnumValuesFunction · 0.85
toGoFieldNameFunction · 0.85
goBooleanValuesFunction · 0.85
resolveSchemaFunction · 0.85
dedupeGoSchemasForMatchFunction · 0.85
stableStringifyFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…