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

Function generateDataClass

scripts/codegen/csharp.ts:1248–1288  ·  view source on GitHub ↗
(variant: EventVariant, knownTypes: Map<string, string>, nestedClasses: Map<string, string>, enumOutput: string[])

Source from the content-addressed store, hash-verified

1246}
1247
1248function generateDataClass(variant: EventVariant, knownTypes: Map<string, string>, nestedClasses: Map<string, string>, enumOutput: string[]): string {
1249 const dataVisibility = isSchemaInternal(variant.dataSchema) ? "internal" : "public";
1250 if (!variant.dataSchema?.properties) return `${dataVisibility} sealed partial class ${variant.dataClassName} { }`;
1251
1252 const required = new Set(variant.dataSchema.required || []);
1253 const lines: string[] = [];
1254 if (variant.dataDescription) {
1255 lines.push(...xmlDocComment(variant.dataDescription, ""));
1256 } else {
1257 lines.push(...rawXmlDocSummary(`Event payload for <see cref="${variant.className}"/>.`, ""));
1258 }
1259 if (variant.dataExperimental || isSchemaExperimental(variant.dataSchema)) {
1260 pushExperimentalAttribute(lines);
1261 }
1262 if (isSchemaDeprecated(variant.dataSchema)) {
1263 pushObsoleteAttributes(lines);
1264 }
1265 lines.push(`${dataVisibility} sealed partial class ${variant.dataClassName}`, `{`);
1266
1267 for (const [propName, propSchema] of Object.entries(variant.dataSchema.properties).sort(([a], [b]) => a.localeCompare(b))) {
1268 if (typeof propSchema !== "object") continue;
1269 const isReq = required.has(propName);
1270 const prop = propSchema as JSONSchema7;
1271 const csharpName = toCSharpPropertyName(propName, prop);
1272 const csharpType = resolveSessionPropertyType(prop, variant.dataClassName, csharpName, isReq, knownTypes, nestedClasses, enumOutput);
1273
1274 lines.push(...xmlDocPropertyComment(prop.description, propName, " "));
1275 lines.push(...emitDataAnnotations(prop, " ", csharpType));
1276 if (isSchemaDeprecated(prop)) pushObsoleteAttributes(lines, " ");
1277 if (isSchemaExperimental(prop)) pushExperimentalAttribute(lines, " ");
1278 if (isMillisecondsDurationProperty(propName, prop)) lines.push(` [JsonConverter(typeof(MillisecondsTimeSpanConverter))]`);
1279 if (!isReq) lines.push(` [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]`);
1280 const propVisibility = pushCSharpInternalAttribute(lines, prop);
1281 lines.push(` [JsonPropertyName("${propName}")]`);
1282 const reqMod = isReq && !csharpType.endsWith("?") ? "required " : "";
1283 lines.push(` ${propVisibility} ${reqMod}${csharpType} ${csharpName} { get; set; }`, "");
1284 }
1285 if (lines[lines.length - 1] === "") lines.pop();
1286 lines.push(`}`);
1287 return lines.join("\n");
1288}
1289
1290function emitSessionEventEnvelopeProperty(
1291 property: SessionEventEnvelopeProperty,

Callers 1

Calls 15

isSchemaInternalFunction · 0.85
xmlDocCommentFunction · 0.85
rawXmlDocSummaryFunction · 0.85
isSchemaExperimentalFunction · 0.85
isSchemaDeprecatedFunction · 0.85
pushObsoleteAttributesFunction · 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…