feat(tii): emit JSON Schema for complex protocol types#337
Merged
Conversation
tx3c collapsed every user-defined record/variant to a bare
`{"type":"object"}` and never populated `components.schemas`, so the
structure of complex types that participate in a protocol was lost.
Resolve custom types by name against the program's own types/aliases and
register them under `components.schemas`: records as object schemas,
variants as an idiomatic tagged `oneOf`, nested types recursively, and
aliases inlined transparently. Params now reference them via `$ref`.
Codegen: fix the `$ref` name extraction (the `/$defs/Bytes` form yielded
the wrong name, so even builtins generated as `any`) and render named
types from `components.schemas` — full struct/interface/dataclass for
records, permissive named aliases for variants pending the variant arg
encoder.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move SchemaCtx, the env/param schema inference, and their tests out of tii/mod.rs into a dedicated tii/schema.rs. The mapping depends only on the AST and serde_json, so it decouples cleanly and sits alongside the existing tii/types.rs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
What
Make
tx3cemit JSON Schema for the complex (record / variant) types thatparticipate in a protocol, and consume them in codegen.
Emitter (
bin/tx3c/src/tii/mod.rs)Previously every user-defined type collapsed to a bare
{"type":"object"}andcomponents.schemaswas never populated, so a.tiicarried no structure forits protocol types.
SchemaCtxresolves custom types by name against the program's owntypes/aliases(the analyzer doesn't resolve symbols nested inside typedefinitions, so name lookup is the only reliable path).
properties/required; variants → idiomatictagged
oneOf; nested custom types register recursively (with aself-reference guard); aliases inline transparently.
$ref: #/components/schemas/<Name>.Codegen (
bin/tx3c/src/codegen.rs)$refname extraction — the…/$defs/Bytesform previously yielded/$defs/Bytes, so even builtins generated asany.componentTypeshelper renders named declarations fromcomponents.schemas: full struct/interface/dataclass for records, namedpermissive aliases for variants (pending the variant arg encoder).
Tests
5 emitter unit tests (record, nested, variant
oneOf, alias, primitive-only).tx3c codegenverified against all four SDK template dirs.Depends on
tx3-lang/tii(spec$defs). Consumed by the SDK codegen PRs inweb-sdk/rust-sdk/python-sdk/go-sdk.🤖 Generated with Claude Code