(schema: JSONSchema7)
| 1319 | } |
| 1320 | |
| 1321 | export function generateSessionEventsCode(schema: JSONSchema7): string { |
| 1322 | generatedEnums.clear(); |
| 1323 | sessionDefinitions = collectDefinitionCollections(schema as Record<string, unknown>); |
| 1324 | const variants = extractEventVariants(schema); |
| 1325 | const knownTypes = new Map<string, string>(); |
| 1326 | const nestedClasses = new Map<string, string>(); |
| 1327 | const enumOutput: string[] = []; |
| 1328 | const envelopeProperties = getSharedSessionEventEnvelopeProperties(schema, sessionDefinitions); |
| 1329 | |
| 1330 | const lines: string[] = []; |
| 1331 | lines.push(`${COPYRIGHT} |
| 1332 | |
| 1333 | // AUTO-GENERATED FILE - DO NOT EDIT |
| 1334 | // Generated from: session-events.schema.json |
| 1335 | |
| 1336 | #pragma warning disable CS0612 // Type or member is obsolete |
| 1337 | #pragma warning disable CS0618 // Type or member is obsolete (with message) |
| 1338 | |
| 1339 | using System.ComponentModel; |
| 1340 | using System.ComponentModel.DataAnnotations; |
| 1341 | using System.Diagnostics; |
| 1342 | using System.Diagnostics.CodeAnalysis; |
| 1343 | using System.Text.Json; |
| 1344 | using System.Text.Json.Serialization; |
| 1345 | |
| 1346 | namespace GitHub.Copilot; |
| 1347 | `); |
| 1348 | |
| 1349 | // Base class with XML doc |
| 1350 | lines.push(`/// <summary>`); |
| 1351 | lines.push(`/// Provides the base class from which all session events derive.`); |
| 1352 | lines.push(`/// </summary>`); |
| 1353 | lines.push(`[DebuggerDisplay("{DebuggerDisplay,nq}")]`); |
| 1354 | lines.push(`[JsonPolymorphic(`, ` TypeDiscriminatorPropertyName = "type",`, ` IgnoreUnrecognizedTypeDiscriminators = true)]`); |
| 1355 | for (const variant of [...variants].sort((a, b) => a.typeName.localeCompare(b.typeName))) { |
| 1356 | lines.push(`[JsonDerivedType(typeof(${variant.className}), "${variant.typeName}")]`); |
| 1357 | } |
| 1358 | lines.push(`public partial class SessionEvent`, `{`); |
| 1359 | for (const property of envelopeProperties) { |
| 1360 | lines.push(...emitSessionEventEnvelopeProperty(property, knownTypes, nestedClasses, enumOutput)); |
| 1361 | } |
| 1362 | lines.push(` /// <summary>`, ` /// The event type discriminator.`, ` /// </summary>`); |
| 1363 | lines.push(` [JsonIgnore]`, ` public virtual string Type => "unknown";`, ""); |
| 1364 | lines.push(` /// <summary>Deserializes a JSON string into a <see cref="SessionEvent"/>.</summary>`); |
| 1365 | lines.push(` public static SessionEvent FromJson(string json) =>`, ` JsonSerializer.Deserialize(json, SessionEventsJsonContext.Default.SessionEvent)!;`, ""); |
| 1366 | lines.push(` /// <summary>Serializes this event to a JSON string.</summary>`); |
| 1367 | lines.push(` public string ToJson() =>`, ` JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);`, ""); |
| 1368 | lines.push(` [DebuggerBrowsable(DebuggerBrowsableState.Never)]`, ` private string DebuggerDisplay => ToJson();`); |
| 1369 | lines.push(`}`, ""); |
| 1370 | |
| 1371 | // Event classes with XML docs |
| 1372 | for (const variant of variants) { |
| 1373 | const remarksLine = `/// <remarks>Represents the <c>${escapeXml(variant.typeName)}</c> event.</remarks>`; |
| 1374 | if (variant.dataDescription) { |
| 1375 | lines.push(...xmlDocComment(variant.dataDescription, "")); |
| 1376 | lines.push(remarksLine); |
| 1377 | } else { |
| 1378 | lines.push(`/// <summary>Represents the <c>${escapeXml(variant.typeName)}</c> event.</summary>`); |
no test coverage detected
searching dependent graphs…