Skip to content

feat(tii): emit JSON Schema for complex protocol types#337

Merged
scarmuega merged 2 commits into
mainfrom
feat/tii-complex-type-schemas
Jun 8, 2026
Merged

feat(tii): emit JSON Schema for complex protocol types#337
scarmuega merged 2 commits into
mainfrom
feat/tii-complex-type-schemas

Conversation

@scarmuega

Copy link
Copy Markdown
Contributor

What

Make tx3c emit JSON Schema for the complex (record / variant) types that
participate 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"} and
components.schemas was never populated, so a .tii carried no structure for
its protocol types.

  • New SchemaCtx resolves custom types by name against the program's own
    types/aliases (the analyzer doesn't resolve symbols nested inside type
    definitions, so name lookup is the only reliable path).
  • Records → object schema with properties/required; variants → idiomatic
    tagged oneOf; nested custom types register recursively (with a
    self-reference guard); aliases inline transparently.
  • Params/env fields now reference types via $ref: #/components/schemas/<Name>.

Codegen (bin/tx3c/src/codegen.rs)

  • Fix $ref name extraction — the …/$defs/Bytes form previously yielded
    /$defs/Bytes, so even builtins generated as any.
  • New componentTypes helper renders named declarations from
    components.schemas: full struct/interface/dataclass for records, named
    permissive aliases for variants (pending the variant arg encoder).

Tests

5 emitter unit tests (record, nested, variant oneOf, alias, primitive-only).
tx3c codegen verified against all four SDK template dirs.

Depends on tx3-lang/tii (spec $defs). Consumed by the SDK codegen PRs in
web-sdk / rust-sdk / python-sdk / go-sdk.

🤖 Generated with Claude Code

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>
@scarmuega scarmuega merged commit 196feeb into main Jun 8, 2026
6 checks passed
@scarmuega scarmuega deleted the feat/tii-complex-type-schemas branch June 8, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant