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

Function getPyNamedSchemaType

scripts/codegen/python.ts:1742–1791  ·  view source on GitHub ↗
(
    schema: JSONSchema7,
    ctx: PyCodegenCtx
)

Source from the content-addressed store, hash-verified

1740}
1741
1742function getPyNamedSchemaType(
1743 schema: JSONSchema7,
1744 ctx: PyCodegenCtx
1745): { typeName: string; resolved: PyResolvedType } | undefined {
1746 const resolved = resolveSchema(schema, ctx.definitions) ?? schema;
1747 const typeName = schema.$ref
1748 ? toPascalCase(refTypeName(schema.$ref, ctx.definitions))
1749 : typeof resolved.title === "string"
1750 ? resolved.title
1751 : undefined;
1752
1753 if (!typeName) {
1754 return undefined;
1755 }
1756
1757 if (resolved.enum && Array.isArray(resolved.enum) && resolved.enum.every((value) => typeof value === "string")) {
1758 const enumType = getOrCreatePyEnum(
1759 typeName,
1760 resolved.enum as string[],
1761 ctx,
1762 resolved.description,
1763 getEnumValueDescriptions(resolved),
1764 isSchemaDeprecated(resolved),
1765 isSchemaExperimental(resolved)
1766 );
1767 return {
1768 typeName: enumType,
1769 resolved: {
1770 annotation: enumType,
1771 fromExpr: (expr) => `parse_enum(${enumType}, ${expr})`,
1772 toExpr: (expr) => `to_enum(${enumType}, ${expr})`,
1773 },
1774 };
1775 }
1776
1777 const resolvedObject = resolveObjectSchema(schema, ctx.definitions) ?? resolveObjectSchema(resolved, ctx.definitions);
1778 if (isNamedPyObjectSchema(resolvedObject)) {
1779 emitPyClass(typeName, resolvedObject, ctx, resolvedObject.description);
1780 return {
1781 typeName,
1782 resolved: {
1783 annotation: typeName,
1784 fromExpr: (expr) => `${typeName}.from_dict(${expr})`,
1785 toExpr: (expr) => `to_class(${typeName}, ${expr})`,
1786 },
1787 };
1788 }
1789
1790 return undefined;
1791}
1792
1793function getOrCreatePyUnionAlias(
1794 aliasName: string,

Callers 1

resolvePyNamedUnionFunction · 0.85

Calls 10

resolveSchemaFunction · 0.85
refTypeNameFunction · 0.85
getOrCreatePyEnumFunction · 0.85
getEnumValueDescriptionsFunction · 0.85
isSchemaDeprecatedFunction · 0.85
isSchemaExperimentalFunction · 0.85
resolveObjectSchemaFunction · 0.85
isNamedPyObjectSchemaFunction · 0.85
emitPyClassFunction · 0.85
toPascalCaseFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…