Problem
The language emitters (--to typescript, and presumably the others) hardcode the shape of generated ADTs. There is no way to control:
readonly vs mutable fields
null vs undefined for Option<T>
- doc-comment passthrough from the
.td source
- (de)serialization helpers — e.g.
fromJson / toJson, including wire-key casing (snake_case <-> camelCase)
Every codebase has its own conventions, so a fixed emitter cannot fit them. See the companion bug in this repo for the concrete TypeScript pain.
Proposed feature
A user-supplied code template per output target that controls how each ADT construct (type, union, alias, and each field) is rendered. Concretely, either:
- a template file (Handlebars / EJS / Mustache) referenced via
--template ts.tmpl, with access to the parsed model (names, fields, types, optionality, docs); or
- render hooks in the Node API (
typediagram-core) that let callers override per-node emission.
This would let a project emit, in one pass, e.g. readonly field: T | null with doc comments AND a generated parseX(raw): X deserializer — no post-processing.
Why critical
Without it, real adopters must regex-rewrite the emitter output and hand-maintain serde — exactly the fragility a codegen tool is supposed to remove. This is currently blocking clean adoption.
Problem
The language emitters (
--to typescript, and presumably the others) hardcode the shape of generated ADTs. There is no way to control:readonlyvs mutable fieldsnullvsundefinedforOption<T>.tdsourcefromJson/toJson, including wire-key casing (snake_case <-> camelCase)Every codebase has its own conventions, so a fixed emitter cannot fit them. See the companion bug in this repo for the concrete TypeScript pain.
Proposed feature
A user-supplied code template per output target that controls how each ADT construct (
type,union,alias, and each field) is rendered. Concretely, either:--template ts.tmpl, with access to the parsed model (names, fields, types, optionality, docs); ortypediagram-core) that let callers override per-node emission.This would let a project emit, in one pass, e.g.
readonly field: T | nullwith doc comments AND a generatedparseX(raw): Xdeserializer — no post-processing.Why critical
Without it, real adopters must regex-rewrite the emitter output and hand-maintain serde — exactly the fragility a codegen tool is supposed to remove. This is currently blocking clean adoption.