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

Function resolvePyPropertyType

scripts/codegen/python.ts:1881–2203  ·  view source on GitHub ↗
(
    propSchema: JSONSchema7,
    parentTypeName: string,
    jsonPropName: string,
    isRequired: boolean,
    ctx: PyCodegenCtx
)

Source from the content-addressed store, hash-verified

1879}
1880
1881function resolvePyPropertyType(
1882 propSchema: JSONSchema7,
1883 parentTypeName: string,
1884 jsonPropName: string,
1885 isRequired: boolean,
1886 ctx: PyCodegenCtx
1887): PyResolvedType {
1888 const fallbackName = parentTypeName + toPascalCase(jsonPropName);
1889 const nestedName = typeof propSchema.title === "string" ? propSchema.title : fallbackName;
1890
1891 if (propSchema.$ref && typeof propSchema.$ref === "string") {
1892 const typeName = toPascalCase(refTypeName(propSchema.$ref, ctx.definitions));
1893 const resolved = resolveSchema(propSchema, ctx.definitions);
1894 if (resolved && resolved !== propSchema) {
1895 if (resolved.enum && Array.isArray(resolved.enum) && resolved.enum.every((value) => typeof value === "string")) {
1896 const enumType = getOrCreatePyEnum(typeName, resolved.enum as string[], ctx, resolved.description, getEnumValueDescriptions(resolved), isSchemaDeprecated(resolved), isSchemaExperimental(resolved));
1897 const enumResolved: PyResolvedType = {
1898 annotation: enumType,
1899 fromExpr: (expr) => `parse_enum(${enumType}, ${expr})`,
1900 toExpr: (expr) => `to_enum(${enumType}, ${expr})`,
1901 };
1902 return isRequired ? enumResolved : pyOptionalResolvedType(enumResolved);
1903 }
1904
1905 // Emit "$ref"-based discriminated unions as proper Python unions
1906 // (per-variant dataclasses + alias + dispatcher) rather than flat
1907 // merged dataclasses. Matches the polymorphic hierarchies emitted
1908 // by the TS / Rust / .NET / Go SDKs for the same schema shape.
1909 if (resolved.anyOf || resolved.oneOf) {
1910 const unionResolved = tryEmitPyRefBasedDiscriminatedUnion(typeName, resolved, ctx);
1911 if (unionResolved) {
1912 return isRequired ? unionResolved : pyOptionalResolvedType(unionResolved);
1913 }
1914 }
1915
1916 const resolvedObject = resolveObjectSchema(propSchema, ctx.definitions);
1917 if (isNamedPyObjectSchema(resolvedObject)) {
1918 emitPyClass(typeName, resolvedObject, ctx, resolvedObject.description);
1919 const objectResolved: PyResolvedType = {
1920 annotation: typeName,
1921 fromExpr: (expr) => `${typeName}.from_dict(${expr})`,
1922 toExpr: (expr) => `to_class(${typeName}, ${expr})`,
1923 };
1924 return isRequired ? objectResolved : pyOptionalResolvedType(objectResolved);
1925 }
1926
1927 return resolvePyPropertyType(resolved, parentTypeName, jsonPropName, isRequired, ctx);
1928 }
1929 }
1930
1931 if (propSchema.allOf && propSchema.allOf.length === 1 && typeof propSchema.allOf[0] === "object") {
1932 return resolvePyPropertyType(
1933 propSchema.allOf[0] as JSONSchema7,
1934 parentTypeName,
1935 jsonPropName,
1936 isRequired,
1937 ctx
1938 );

Callers 3

emitPyClassFunction · 0.85

Calls 15

refTypeNameFunction · 0.85
resolveSchemaFunction · 0.85
getOrCreatePyEnumFunction · 0.85
getEnumValueDescriptionsFunction · 0.85
isSchemaDeprecatedFunction · 0.85
isSchemaExperimentalFunction · 0.85
pyOptionalResolvedTypeFunction · 0.85
resolveObjectSchemaFunction · 0.85
isNamedPyObjectSchemaFunction · 0.85
emitPyClassFunction · 0.85
isPyNullLikeSchemaFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…