Skip to content

Emit XML doc comments from schema descriptions in C# codegen#724

Merged
stephentoub merged 1 commit intomainfrom
stoub/improvexmlcomments
Mar 10, 2026
Merged

Emit XML doc comments from schema descriptions in C# codegen#724
stephentoub merged 1 commit intomainfrom
stoub/improvexmlcomments

Conversation

@stephentoub
Copy link
Collaborator

@stephentoub stephentoub commented Mar 8, 2026

Summary

Updates the C# code generator to emit /// <summary> \ XML doc comments on all generated types and members, sourced from JSON Schema \description\ annotations. This enables IntelliSense documentation for .NET SDK consumers.

Changes

\scripts/codegen/csharp.ts\

  • New helpers: \escapeXml(), \ensureTrailingPunctuation(), \xmlDocComment(),
    awXmlDocSummary(), \xmlDocCommentWithFallback()\
  • Session event classes: <summary>\ from schema description (or synthetic fallback with <c>\ tag), <remarks>\ with event type name when a real description exists
  • Data classes: <summary>\ from schema, fallback uses <see cref>\ to link to the parent event class
  • Nested/polymorphic classes: <summary>\ from schema with synthetic fallbacks for derived classes and nested types
  • Enum types and members: Type-level <summary>\ from schema, per-member <summary>\ with <c>\ variant name
  • Properties: <summary>\ from schema descriptions with XML escaping
  • Override properties: <inheritdoc />\ on all \override string Type\ properties
  • RPC types: Class-level and property-level docs with fallback summaries
  • Punctuation: All comments normalized to end with ., !, or ?\

Generated output (from published @github/copilot\ v1.0.2)

  • \SessionEvents.cs: ~525 <summary>\ + 69 <inheritdoc>\ doc comments
  • \Rpc.cs: Full class-level and property-level documentation with fallbacks
  • Both files build with 0 errors, 0 warnings

Notes

  • The #pragma warning disable CS1591\ remains in both generated files for members whose upstream schema definitions don't yet include descriptions. Once the upstream Zod schemas are enriched with .describe()\ calls and published, the pragmas can be removed.
  • A companion PR will be opened in \copilot-agent-runtime\ to add ~80 additional .describe()\ calls to the Zod source schemas.

Copilot AI review requested due to automatic review settings March 8, 2026 11:42
@stephentoub stephentoub requested a review from a team as a code owner March 8, 2026 11:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the C# code generator to emit XML doc comments (/// <summary>...</summary>) for generated .NET SDK types/members based on JSON Schema description, improving IntelliSense documentation for consumers.

Changes:

  • Added XML doc comment helpers to the C# generator (escaping, punctuation normalization, fallback summaries/remarks).
  • Emitted doc comments across generated Session Events and RPC types (including <inheritdoc /> on discriminator overrides).
  • Refreshed generated SessionEvents.cs and Rpc.cs outputs to include the new documentation.

Reviewed changes

Copilot reviewed 1 out of 3 changed files in this pull request and generated 2 comments.

File Description
scripts/codegen/csharp.ts Adds XML doc emission utilities and threads schema description through session-event / RPC codegen paths.
dotnet/src/Generated/SessionEvents.cs Regenerated session event models with XML doc comments on types and members.
dotnet/src/Generated/Rpc.cs Regenerated RPC request/response models and API wrappers with XML doc comments and punctuation normalization.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

SDK Consistency Review ✅

I've reviewed this PR for cross-SDK consistency and can confirm that this change improves consistency across all four SDK implementations.

Documentation Generation Status

Before this PR:

  • TypeScript: JSDoc comments generated via json-schema-to-typescript
  • Python: Docstrings generated via quicktype
  • Go: Go doc comments generated via quicktype
  • .NET: No XML doc comments in generated code

After this PR:

  • TypeScript: JSDoc comments (unchanged)
  • Python: Docstrings (unchanged)
  • Go: Go doc comments (unchanged)
  • .NET: Now has XML doc comments sourced from JSON Schema descriptions

Analysis

This PR brings the .NET SDK into feature parity with the other three SDK implementations. All four languages now provide IntelliSense/IDE documentation for consumers, which is a core developer experience feature.

The implementation follows .NET conventions (XML doc comments with <summary>, (remarks), (inheritdoc/)) just as the other SDKs follow their respective language conventions (JSDoc for TS, docstrings for Python, Go doc comments for Go).

Recommendation: This PR maintains and improves cross-SDK consistency. No changes needed in other SDKs. ✨

Generated by SDK Consistency Review Agent for issue #724 ·

@stephentoub stephentoub enabled auto-merge March 8, 2026 14:21
Update the C# code generator (csharp.ts) to emit /// <summary> XML doc
comments on all generated types and members, sourced from JSON Schema
description annotations.

Changes to scripts/codegen/csharp.ts:
- Add escapeXml(), ensureTrailingPunctuation(), xmlDocComment(),
  rawXmlDocSummary(), and xmlDocCommentWithFallback() helpers
- Emit <summary> on all data classes, nested classes, polymorphic base
  and derived classes, enum types, and enum members
- Emit <remarks> with event name on SessionEvent-derived classes when a
  real schema description is present
- Emit <inheritdoc /> on all override string Type properties
- Emit <see cref> cross-references in data class fallback summaries
- Use <c> tags for event names and discriminator values
- Ensure all comments end with sentence-ending punctuation
- Add synthetic fallback summaries for types without schema descriptions
- Apply XML escaping to schema-sourced text; skip escaping for
  codegen-controlled XML tags

Regenerated output (from published @github/copilot v1.0.2 schemas):
- SessionEvents.cs: ~525 <summary> + 69 <inheritdoc> comments
- Rpc.cs: class-level and property-level docs with fallbacks

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub force-pushed the stoub/improvexmlcomments branch from 2bd43e7 to e25dfe8 Compare March 10, 2026 02:45
@github-actions
Copy link
Contributor

✅ Cross-SDK Consistency Review

This PR improves cross-SDK consistency by adding comprehensive XML documentation to the .NET SDK, bringing it into parity with the other three language implementations.

Documentation Status Across All SDKs

SDK Session Events RPC Types Documentation Source
TypeScript ✅ JSDoc ✅ JSDoc json-schema-to-typescript
Python ✅ Docstrings ✅ Docstrings quicktype
Go ✅ Comments ✅ Comments quicktype
.NET C# ⚠️ → ✅ ⚠️ → ✅ This PR adds

What This PR Achieves

Before: C# generated code had minimal documentation (only base class summary, partial RPC property docs)

After: C# now has comprehensive XML doc comments:

  • ✅ Class-level summaries from schema description fields
  • ✅ Property-level docs for all fields
  • ✅ Event data class documentation
  • ✅ Enum type and member documentation
  • ✅ Synthetic fallback docs when schema lacks descriptions
  • ✅ IntelliSense support for .NET SDK consumers

This matches the documentation coverage already provided by TypeScript's JSDoc, Python's docstrings, and Go's comments. No consistency gaps introduced — this PR closes a documentation gap that existed in C# relative to the other SDKs.

Recommendation

Approve ✨ — This change maintains and improves cross-SDK consistency by ensuring all four language implementations provide equivalent IDE documentation support to their users.

Generated by SDK Consistency Review Agent for issue #724 ·

@stephentoub stephentoub added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 2b3337a Mar 10, 2026
27 checks passed
@stephentoub stephentoub deleted the stoub/improvexmlcomments branch March 10, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants