Add $ref support to all four language code generators#1062
Open
stephentoub wants to merge 3 commits intomainfrom
Open
Add $ref support to all four language code generators#1062stephentoub wants to merge 3 commits intomainfrom
stephentoub wants to merge 3 commits intomainfrom
Conversation
Contributor
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
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>
c614eb4 to
17ba6bc
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
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.