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

Function resolveSessionPropertyType

scripts/codegen/csharp.ts:1141–1246  ·  view source on GitHub ↗
(
    propSchema: JSONSchema7,
    parentClassName: string,
    propName: string,
    isRequired: boolean,
    knownTypes: Map<string, string>,
    nestedClasses: Map<string, string>,
    enumOutput: string[]
)

Source from the content-addressed store, hash-verified

1139}
1140
1141function resolveSessionPropertyType(
1142 propSchema: JSONSchema7,
1143 parentClassName: string,
1144 propName: string,
1145 isRequired: boolean,
1146 knownTypes: Map<string, string>,
1147 nestedClasses: Map<string, string>,
1148 enumOutput: string[]
1149): string {
1150 if (isOpaqueJson(propSchema)) {
1151 return isRequired ? "JsonElement" : "JsonElement?";
1152 }
1153 // Handle $ref by resolving against schema definitions
1154 if (propSchema.$ref) {
1155 const className = typeToClassName(refTypeName(propSchema.$ref, sessionDefinitions));
1156 const refSchema = resolveRef(propSchema.$ref, sessionDefinitions);
1157 if (!refSchema) {
1158 return isRequired ? className : `${className}?`;
1159 }
1160
1161 if (refSchema.enum && Array.isArray(refSchema.enum)) {
1162 const enumName = getOrCreateEnum(className, "", refSchema.enum as string[], enumOutput, refSchema.description, getEnumValueDescriptions(refSchema), undefined, isSchemaDeprecated(refSchema), isSchemaExperimental(refSchema));
1163 return isRequired ? enumName : `${enumName}?`;
1164 }
1165
1166 if (refSchema.type === "object" && refSchema.properties) {
1167 if (!nestedClasses.has(className)) {
1168 nestedClasses.set(className, generateNestedClass(className, refSchema, knownTypes, nestedClasses, enumOutput));
1169 }
1170 return isRequired ? className : `${className}?`;
1171 }
1172
1173 return resolveSessionPropertyType(refSchema, parentClassName, propName, isRequired, knownTypes, nestedClasses, enumOutput);
1174 }
1175 if (propSchema.anyOf) {
1176 const simpleNullable = getNullableInner(propSchema);
1177 if (simpleNullable) {
1178 return resolveSessionPropertyType(simpleNullable, parentClassName, propName, false, knownTypes, nestedClasses, enumOutput);
1179 }
1180 // Discriminated union: anyOf with multiple object variants sharing a const discriminator
1181 const nonNull = propSchema.anyOf.filter((s) => typeof s === "object" && s !== null && (s as JSONSchema7).type !== "null");
1182 if (nonNull.length > 1) {
1183 // Resolve $ref variants to their actual schemas
1184 const variants = (nonNull as JSONSchema7[]).map((v) => {
1185 if (v.$ref) {
1186 const resolved = resolveRef(v.$ref, sessionDefinitions);
1187 return resolved ?? v;
1188 }
1189 return v;
1190 });
1191 const discriminatorInfo = findDiscriminator(variants);
1192 if (discriminatorInfo) {
1193 const hasNull = propSchema.anyOf.length > nonNull.length;
1194 const baseClassName = (propSchema.title as string) ?? `${parentClassName}${propName}`;
1195 const renamedBase = applyTypeRename(baseClassName);
1196 const polymorphicCode = generateDiscriminatedUnionClass(baseClassName, discriminatorInfo, variants, knownTypes, nestedClasses, enumOutput, propSchema.description, undefined, isSchemaExperimental(propSchema), { sealLeafTypes: true });
1197 nestedClasses.set(renamedBase, polymorphicCode);
1198 return isRequired && !hasNull ? renamedBase : `${renamedBase}?`;

Callers 3

generateNestedClassFunction · 0.85
generateDataClassFunction · 0.85

Calls 15

isOpaqueJsonFunction · 0.85
typeToClassNameFunction · 0.85
refTypeNameFunction · 0.85
getOrCreateEnumFunction · 0.85
getEnumValueDescriptionsFunction · 0.85
isSchemaDeprecatedFunction · 0.85
isSchemaExperimentalFunction · 0.85
generateNestedClassFunction · 0.85
getNullableInnerFunction · 0.85
applyTypeRenameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…