Add $ref support to all four language code generators#1062
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the multi-language schema-to-SDK generators (TypeScript, Python, Go, C#) to support JSON Schema $ref so shared definitions can be deduplicated and emitted once per language.
Changes:
- Adds shared
$refutilities (resolveRef,refTypeName,collectDefinitions) and expandsApiSchemato surface schema definitions. - Refactors TypeScript RPC generation to compile a single combined schema (shared definitions + all RPC param/result types) in one pass.
- Updates Python/Go quicktype inputs and C# custom emitters to include/resolve referenced definitions.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/utils.ts | Adds $ref helpers and attempts $defs→definitions normalization in schema post-processing. |
| scripts/codegen/typescript.ts | Generates RPC types from one combined schema to dedupe $ref-shared types; re-adds experimental annotations post-compile. |
| scripts/codegen/python.ts | Includes shared definitions for quicktype to resolve $ref during session-event and RPC generation. |
| scripts/codegen/go.ts | Adds $ref handling to Go session-events custom generator; includes shared definitions for RPC quicktype generation. |
| scripts/codegen/csharp.ts | Adds $ref handling for session events + RPC generation, with on-demand referenced type emission. |
Copilot's findings
Comments suppressed due to low confidence (1)
scripts/codegen/python.ts:23
- The import list includes
isRpcMethodtwice, which will cause a TypeScript compile error (“Duplicate identifier 'isRpcMethod'”). Remove the duplicate specifier.
import {
getApiSchemaPath,
getSessionEventsSchemaPath,
isRpcMethod,
postProcessSchema,
writeGeneratedFile,
collectDefinitions,
isRpcMethod,
isNodeFullyExperimental,
type ApiSchema,
type RpcMethod,
} from "./utils.js";
- Files reviewed: 5/5 changed files
- Comments generated: 7
c614eb4 to
17ba6bc
Compare
Enable JSON Schema $ref for type deduplication across all SDK code generators (TypeScript, Python, Go, C#). Changes: - utils.ts: Add resolveRef(), refTypeName(), collectDefinitions() helpers; normalize $defs to definitions in postProcessSchema - typescript.ts: Build combined schema with shared definitions and compile once via unreachableDefinitions, instead of per-method compilation - python.ts/go.ts: Include all definitions alongside SessionEvent for quicktype resolution; include shared API defs in RPC combined schema - csharp.ts: Add handling to resolveSessionPropertyType and resolveRpcType; generate classes for referenced types on demand Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the rebased $ref generator follow-up aligned with the latest C# typing changes and clean up the Python/TypeScript generator adjustments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7ab5c81 to
2031d6a
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Generated by SDK Consistency Review Agent for issue #1062 · ● 2M
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review ✅This PR adds What was changedAll four generators were updated in a coordinated way:
Consistency strengths
Minor observation (not a blocker)The TypeScript generator now uses This asymmetry was a pre-existing characteristic of the TypeScript generator's approach and doesn't affect correctness. Not flagging it as a required change. SummaryThe PR is well-structured:
|
Summary
Enable JSON Schema
$reffor type deduplication across all SDK code generators (TypeScript, Python, Go, C#). This allows the runtime to declare a shared type once using$ref and have each generator produce a single deduplicated type per language.Changes
scripts/codegen/utils.tsresolveRef(),refTypeName(),collectDefinitions()helpers$defs todefinitionsinpostProcessSchemafor cross-draft compatibilitydefinitions/$defs fields toApiSchemainterfacescripts/codegen/typescript.tsunreachableDefinitions, instead of per-method compilation@experimentalJSDoc annotations via post-processingscripts/codegen/python.tsSessionEventfor quicktype$ref resolutionaddSourcecallscripts/codegen/go.ts$ref handling to the custom Go session events generator (resolveGoPropertyType) withdefinitionsonGoCodegenCtx$ref resolutionscripts/codegen/csharp.ts$ref handling toresolveSessionPropertyTypeandresolveRpcTypesessionDefinitions/rpcDefinitionsstate$ref in array itemsMotivation
The copilot-agent-runtime is moving to use
$ref for type deduplication in tool schemas. Without this change, generators would either fail to resolve$ref pointers or inline duplicate type definitions.