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

Function emitPyFlatDiscriminatedUnion

scripts/codegen/python.ts:2303–2441  ·  view source on GitHub ↗
(
    typeName: string,
    discriminatorProp: string,
    mapping: Map<string, JSONSchema7>,
    ctx: PyCodegenCtx,
    description?: string,
    experimental = false
)

Source from the content-addressed store, hash-verified

2301}
2302
2303function emitPyFlatDiscriminatedUnion(
2304 typeName: string,
2305 discriminatorProp: string,
2306 mapping: Map<string, JSONSchema7>,
2307 ctx: PyCodegenCtx,
2308 description?: string,
2309 experimental = false
2310): void {
2311 if (ctx.generatedNames.has(typeName)) {
2312 return;
2313 }
2314 ctx.generatedNames.add(typeName);
2315
2316 const allProps = new Map<string, { schema: JSONSchema7; requiredInAll: boolean }>();
2317 for (const [, variant] of mapping) {
2318 const required = new Set(variant.required || []);
2319 for (const [propName, propSchema] of Object.entries(variant.properties || {})) {
2320 if (typeof propSchema !== "object") {
2321 continue;
2322 }
2323 if (!allProps.has(propName)) {
2324 allProps.set(propName, {
2325 schema: propSchema as JSONSchema7,
2326 requiredInAll: required.has(propName),
2327 });
2328 } else if (!required.has(propName)) {
2329 allProps.get(propName)!.requiredInAll = false;
2330 }
2331 }
2332 }
2333
2334 const variantCount = mapping.size;
2335 for (const [propName, info] of allProps) {
2336 let presentCount = 0;
2337 for (const [, variant] of mapping) {
2338 if (variant.properties && propName in variant.properties) {
2339 presentCount++;
2340 }
2341 }
2342 if (presentCount < variantCount) {
2343 info.requiredInAll = false;
2344 }
2345 }
2346
2347 const discriminatorEnumName = getOrCreatePyEnum(
2348 typeName + toPascalCase(discriminatorProp),
2349 [...mapping.keys()],
2350 ctx,
2351 description ? `${description} discriminator` : `${typeName} discriminator`,
2352 undefined,
2353 false,
2354 experimental
2355 );
2356
2357 const fieldEntries: Array<[string, JSONSchema7, boolean]> = [
2358 [
2359 discriminatorProp,
2360 {

Callers 1

resolvePyPropertyTypeFunction · 0.85

Calls 13

getOrCreatePyEnumFunction · 0.85
resolvePyPropertyTypeFunction · 0.85
isSchemaInternalFunction · 0.85
toPyFieldNameFunction · 0.85
pyDocstringLiteralFunction · 0.85
pushPyFieldMarkersFunction · 0.85
joinMethod · 0.80
toPascalCaseFunction · 0.70
addMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…