Add enum value descriptions to generated docs#1336
Merged
Conversation
Propagate x-enumDescriptions through the SDK code generators so enum values get language-appropriate documentation while retaining existing fallback comments. Add focused codegen coverage across C#, Go, Python, Rust, and TypeScript. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the SDK code generators to preserve per-enum-value documentation coming from runtime schemas via the x-enumDescriptions extension, so generated public APIs can surface value-level docs instead of generic boilerplate.
Changes:
- Added a shared
getEnumValueDescriptions()helper and treatedx-enumDescriptionsas documentation-only metadata for schema sharing/deduping. - Threaded enum-value descriptions through the C#, Go, Python, Rust, and TypeScript generators to emit value-level docs/comments where supported.
- Adjusted generators to be safely imported by tests (guard CLI entrypoints) and added unit tests covering enum-value doc emission and schema sharing behavior.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/utils.ts | Adds getEnumValueDescriptions() and excludes x-enumDescriptions from definition equality checks to avoid doc-only duplicate types. |
| scripts/codegen/typescript.ts | Emits per-enum-value JSDoc via tsType override during schema normalization; adds import-safe CLI entrypoint guard. |
| scripts/codegen/rust.ts | Threads enum-value descriptions into Rust string-enum variant docs; adds import-safe CLI entrypoint guard and exports for tests. |
| scripts/codegen/python.ts | Emits per-enum-value comments for Python enums; adds import-safe CLI entrypoint guard. |
| scripts/codegen/go.ts | Emits per-enum-value comments for Go enum constants; adds import-safe CLI entrypoint guard and exports for tests. |
| scripts/codegen/csharp.ts | Uses schema-provided value docs for enum-like members while retaining fallback XML docs; adds import-safe CLI entrypoint guard and exports for tests. |
| nodejs/test/typescript-codegen.test.ts | Adds coverage ensuring enum-value descriptions are emitted into TypeScript output. |
| nodejs/test/shared-codegen.test.ts | Adds coverage for extracting descriptions and for shared-definition deduping behavior with x-enumDescriptions. |
| nodejs/test/python-codegen.test.ts | Adds cross-generator assertions (Python/C#/Go/Rust) for enum-value description emission and fallback behavior. |
Copilot's findings
- Files reviewed: 9/9 changed files
- Comments generated: 0
Contributor
Cross-SDK Consistency Review ✅This PR updates all five SDK code generators simultaneously — TypeScript, Python, Go, C#, and Rust — with the same What was checked:
The entry-point guard pattern (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The runtime schemas are adding per-enum-value descriptions, and the SDK generators should preserve that information in the generated public APIs instead of falling back to generic value comments.
This updates the shared codegen utilities to read
x-enumDescriptionsand threads that metadata through the C#, Go, Python, Rust, and TypeScript generators. C# enum-like value members now use XML docs from the schema when available and retain the existing boilerplate fallback when not. Other SDKs emit the closest language-appropriate doc/comment surface for enum values.A small schema-sharing adjustment treats
x-enumDescriptionsas documentation-only metadata, matching existing handling for schema descriptions, so shared definitions with documentation-only differences do not produce duplicate generated types.Validation:
npm test -- --run test\shared-codegen.test.ts test\python-codegen.test.ts test\typescript-codegen.test.tsnpx prettier --check test\python-codegen.test.ts test\shared-codegen.test.ts test\typescript-codegen.test.tsnpm run typecheck