Seal generated session event types#1330
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review ✅This PR modifies only
The change adds
No cross-SDK consistency issues identified. The change is appropriately scoped to the .NET SDK.
|
There was a problem hiding this comment.
Pull request overview
This PR updates the C# session-event type generator to emit sealed for generated leaf DTOs (events, event payload/data types, nested object DTOs, JSON-union containers, and discriminated-union leaf variants) and regenerates the SessionEvents.cs output accordingly. This reduces unnecessary inheritance surface area while keeping polymorphic base types unsealed for System.Text.Json polymorphic deserialization.
Changes:
- Added
DiscriminatedUnionGenerationOptionsplumbing to allow sealing discriminated-union leaf variants during generation. - Updated the generator to emit
sealedfor nested DTOs, event payload DTOs, event leaf types, and the source-generatedJsonSerializerContext. - Regenerated
dotnet/src/Generated/SessionEvents.csto reflect the new sealing behavior.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/csharp.ts | Adds an option to seal discriminated-union leaf classes and applies sealed to generated leaf DTO classes and the JSON context. |
| dotnet/src/Generated/SessionEvents.cs | Regenerated output marking applicable session-event DTO types as sealed. |
Copilot's findings
- Files reviewed: 1/2 changed files
- Comments generated: 0
The session event generator currently emits most generated C# DTOs as inheritable classes even when they are leaf types. Sealing those generated types better communicates the intended object model and avoids unnecessary inheritance surface area.
Summary
dotnet/src/Generated/SessionEvents.csfrom the updated generator.Validation
dotnet build src\GitHub.Copilot.SDK.csproj --no-restoredotnet test test\GitHub.Copilot.SDK.Test.csproj --no-build --filter FullyQualifiedName~GitHub.Copilot.SDK.Test.UnitGenerated by Copilot.