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

Function generateNestedClass

scripts/codegen/csharp.ts:1104–1139  ·  view source on GitHub ↗
(
    className: string,
    schema: JSONSchema7,
    knownTypes: Map<string, string>,
    nestedClasses: Map<string, string>,
    enumOutput: string[]
)

Source from the content-addressed store, hash-verified

1102}
1103
1104function generateNestedClass(
1105 className: string,
1106 schema: JSONSchema7,
1107 knownTypes: Map<string, string>,
1108 nestedClasses: Map<string, string>,
1109 enumOutput: string[]
1110): string {
1111 const required = new Set(schema.required || []);
1112 const lines: string[] = [];
1113 lines.push(...xmlDocCommentWithFallback(schema.description, `Nested data type for <c>${className}</c>.`, ""));
1114 if (isSchemaExperimental(schema)) pushExperimentalAttribute(lines);
1115 if (isSchemaDeprecated(schema)) pushObsoleteAttributes(lines);
1116 lines.push(`${isSchemaInternal(schema) ? "internal" : "public"} sealed partial class ${className}`, `{`);
1117
1118 for (const [propName, propSchema] of Object.entries(schema.properties || {}).sort(([a], [b]) => a.localeCompare(b))) {
1119 if (typeof propSchema !== "object") continue;
1120 const prop = propSchema as JSONSchema7;
1121 const isReq = required.has(propName);
1122 const csharpName = toCSharpPropertyName(propName, prop);
1123 const csharpType = resolveSessionPropertyType(prop, className, csharpName, isReq, knownTypes, nestedClasses, enumOutput);
1124
1125 lines.push(...xmlDocPropertyComment(prop.description, propName, " "));
1126 lines.push(...emitDataAnnotations(prop, " ", csharpType));
1127 if (isSchemaDeprecated(prop)) pushObsoleteAttributes(lines, " ");
1128 if (isSchemaExperimental(prop)) pushExperimentalAttribute(lines, " ");
1129 if (isMillisecondsDurationProperty(propName, prop)) lines.push(` [JsonConverter(typeof(MillisecondsTimeSpanConverter))]`);
1130 if (!isReq) lines.push(` [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]`);
1131 const propVisibility = pushCSharpInternalAttribute(lines, prop);
1132 lines.push(` [JsonPropertyName("${propName}")]`);
1133 const reqMod = isReq && !csharpType.endsWith("?") ? "required " : "";
1134 lines.push(` ${propVisibility} ${reqMod}${csharpType} ${csharpName} { get; set; }`, "");
1135 }
1136 if (lines[lines.length - 1] === "") lines.pop();
1137 lines.push(`}`);
1138 return lines.join("\n");
1139}
1140
1141function resolveSessionPropertyType(
1142 propSchema: JSONSchema7,

Callers 2

Calls 15

isSchemaExperimentalFunction · 0.85
isSchemaDeprecatedFunction · 0.85
pushObsoleteAttributesFunction · 0.85
isSchemaInternalFunction · 0.85
toCSharpPropertyNameFunction · 0.85
xmlDocPropertyCommentFunction · 0.85
emitDataAnnotationsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…