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

Function findPyDiscriminator

scripts/codegen/python.ts:1692–1735  ·  view source on GitHub ↗
(
    variants: JSONSchema7[]
)

Source from the content-addressed store, hash-verified

1690}
1691
1692function findPyDiscriminator(
1693 variants: JSONSchema7[]
1694): { property: string; mapping: Map<string, JSONSchema7> } | null {
1695 if (variants.length === 0) {
1696 return null;
1697 }
1698
1699 const firstVariant = variants[0];
1700 if (!firstVariant.properties) {
1701 return null;
1702 }
1703
1704 for (const [propName, propSchema] of Object.entries(firstVariant.properties)) {
1705 if (typeof propSchema !== "object") {
1706 continue;
1707 }
1708 if ((propSchema as JSONSchema7).const === undefined) {
1709 continue;
1710 }
1711
1712 const mapping = new Map<string, JSONSchema7>();
1713 let valid = true;
1714 for (const variant of variants) {
1715 if (!variant.properties) {
1716 valid = false;
1717 break;
1718 }
1719
1720 const variantProp = variant.properties[propName];
1721 if (typeof variantProp !== "object" || (variantProp as JSONSchema7).const === undefined) {
1722 valid = false;
1723 break;
1724 }
1725
1726 mapping.set(String((variantProp as JSONSchema7).const), variant);
1727 }
1728
1729 if (valid && mapping.size === variants.length) {
1730 return { property: propName, mapping };
1731 }
1732 }
1733
1734 return null;
1735}
1736
1737function isPyNullLikeSchema(schema: JSONSchema7): boolean {
1738 return schema.type === "null" ||

Calls 2

StringFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…