Targets
Typra emits generated model surfaces, tests, metadata, and documentation from the same TypeSpec source.
Runtime targets
Section titled “Runtime targets”| 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. |
Reference targets
Section titled “Reference targets”| 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. |
Target configuration
Section titled “Target configuration”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"Choose targets by job
Section titled “Choose targets by job”| 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 examples
Section titled “Target examples”| 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 |
Capability caveats
Section titled “Capability caveats”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. Use native-serialization: "serde" when consumers need serde interop. |
Swift | Emits a SwiftPM package with a Yams dependency for YAML; use native-serialization: "codable" when consumers need JSONEncoder/JSONDecoder interop. 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. |
Confidence model
Section titled “Confidence model”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 run when a Swift toolchain is available, and are gated to a hard requirement with CI_SWIFT_REQUIRED=1.
The fixture source is the compact reference for supported shapes:
packages\typra-emitter\fixtures\tspconfig.yamlpackages\typra-emitter\fixtures\integration\main.tsppackages\typra-emitter\fixtures\features\<feature>\main.tsppackages\typra-emitter\fixtures\runtimes\<runtime>\<case>\main.tsp