Skip to content

Targets

Typra emits generated model surfaces, tests, metadata, and documentation from the same TypeSpec source.

Target Generated surface
TypeScript Model classes, runtime helpers, JSON/YAML helpers, tests, protocol scaffold tests, and optional Zod validators.
Python Model surfaces, loader/saver helpers, JSON/YAML helpers, import-pruned output, tests, and optional Pydantic v2 models.
CSharp C# model types, System.Text.Json helpers, tests, and protocol scaffolds.
Go Structs, load/save helpers, JSON/YAML helpers, scalar shorthand coercion, polymorphic dispatch, and generated tests.
Java Models with load, save, fromJson, toJson, fromYaml, toYaml, scalar coercion, enum handling, polymorphic dispatch, tests, and optional Jackson interop.
Rust structs with from_json/to_json, from_yaml/to_yaml, provider wire mapping, optional case-insensitive enum parsing, and optional explicit serde impls.
Swift A SwiftPM package with TypraModel types, fromJSON/toJSON, fromYAML/toYAML, scalar coercion, polymorphic enums, provider wire mapping, optional explicit Codable, and XCTest tests.
Target Generated surface
Markdown Reference documentation output generated from the contract graph. Review copy before publishing product docs.
JSON AST json-ast/model.json, emitted for every generation for tooling, verification, and review.

Every target entry requires type. Most targets also use output-dir; tests are emitted only when test-dir is set.

emit-targets:
- type: TypeScript
output-dir: "generated/typescript"
test-dir: "generated/typescript/tests"
import-path: "../index"
- type: CSharp
output-dir: "generated/csharp"
test-dir: "generated/csharp/tests"
namespace: "Todo.Contracts"
- type: Java
output-dir: "generated/java"
test-dir: "generated/java/tests"
package-name: "todo.contracts"
Job Target choice
Browser or Node consumers Start with TypeScript.
Service or data tooling in Python Add Python.
.NET product surfaces Add CSharp and set namespace.
Go services or CLIs Add Go and set package-name.
JVM consumers Add Java and set package-name.
Rust consumers Add Rust; choose enum-parsing deliberately.
Apple platforms or Swift services Add Swift and set package-name.
Human-readable contract reference Add Markdown.
Tooling, review, or schema evolution Use the always-emitted JSON AST.
Target Example page
TypeScript TypeScript target
Python Python target
CSharp C# target
Go Go target
Java Java target
Rust Rust target
Swift Swift target
Markdown Markdown target

Target support is intentionally evidence-driven. The fixture suite validates generated compile/test surfaces, but runtime helper breadth differs by language.

Target Caveat to check before adopting
TypeScript, Python, Go Best fit when JSON/YAML helper behavior and scalar shorthand loading matter.
CSharp, Java Confirm package/namespace conventions before publishing generated output. Both include JSON and YAML helper surfaces.
Rust Choose enum-parsing deliberately; default behavior is case-sensitive. native-serialization: "serde" interop is a preview (see the note above).
Swift Emits a SwiftPM package with a Yams dependency for YAML; native-serialization: "codable" interop is a preview (see the note above). Requires a Swift toolchain to build and test.
Markdown Treat as generated reference output, not a replacement for product narrative docs.
JSON AST Use for tooling and review; do not treat it as a runtime API.

The Typra fixture slice validates TypeScript, Python, C#, Go, Java, Rust, Swift, Markdown, and JSON AST generation from synthetic TypeSpec shapes. Fixture validation also exercises generated metadata, verifier CLI output, consumer smoke wiring, native-interop variants (typescript-zod, python_pydantic, java-jackson, rust-serde, and swift-codable), and cross-language generated-code compile/test surfaces. For Go, that includes gofmt, go vet, go test, scalar coercion helper coverage, and executable conformance. Swift build and test require a Swift toolchain, which is a hard requirement like every other target’s toolchain.

The fixture source is the compact reference for supported shapes:

packages\typra-emitter\fixtures\tspconfig.yaml
packages\typra-emitter\fixtures\integration\main.tsp
packages\typra-emitter\fixtures\features\<feature>\main.tsp
packages\typra-emitter\fixtures\runtimes\<runtime>\<case>\main.tsp