Roslyn source generator that emits TypeScript (.ts) and OpenAPI 3.0
(.yaml / .json) from C# DTOs annotated with [GenerateTypes]. Optional
Python (Pydantic v2 / dataclass) output. Compile-time only, zero reflection,
no running app required.
[GenerateTypes(Targets = TypeTarget.TypeScript | TypeTarget.OpenApi, OutputDir = "generated")]
public class Order
{
public int Id { get; set; }
public string Customer { get; set; } = "";
public List<OrderItem> Items { get; set; } = new();
public OrderStatus Status { get; set; }
}
public class OrderItem { public int Qty { get; set; } public Product Product { get; set; } = new(); }
public class Product { public string Sku { get; set; } = ""; }
public enum OrderStatus { Pending, Shipped }→ at dotnet build (or on save in IDE — see below):
generated/Order.ts,OrderItem.ts,Product.ts,OrderStatus.ts— each with cross-fileimport { X } from './X';statements that compile directly withtsc.generated/openapi.yaml— OpenAPI 3.0.3 schema with every class undercomponents/schemas, correct$refs, andnullable/required/ validation constraints pulled fromZibStack.NET.Validationattributes.
Nested types without their own [GenerateTypes] are auto-discovered by walking
the property graph, so you only annotate root aggregates.
- Transitive type discovery — nested objects, enums, collections, dictionaries all pulled in automatically.
- C# inheritance preserved — emitted TS keeps the full
extendschain; OpenAPI usesallOf. [TsType<T>]/[TsType("expr", ImportFrom = "./…")]— override the TS type expression. Generic form auto-computes the relative import path.[JsonStringEnumConverter]aware — string-valued TS enums + Python(str, Enum)when the enum carries the converter attribute.[JsonExtensionData]→ schema-leveladditionalProperties(OpenAPI) / index signature[key: string]: unknown(TypeScript).[CrudApi]integration withZibStack.NET.Dto— emits OpenAPIpaths(GET list, GET by id, POST, PATCH, DELETE) with the right request/response schema refs, pagination wrappers, and query-string bindings forZibStack.NET.Querywhen referenced.- Fluent project-wide config via
ITypeGenConfigurator— global output dir, file layout (FilePerClass/SingleFile), naming styles, per-type overrides, property-level overrides. - Live regen on save — generator writes
.ts/.yamlfiles directly from the Roslyn pipeline, so your frontend dev server picks changes up without a fulldotnet build. Falls back to an MSBuild post-compile target in sandboxed analyzer hosts. - Stale file sweep — renames drop old files; the sweep is banner-gated so hand-written files in the same directory are safe.
dotnet add package ZibStack.NET.TypeGenThat's it — ZibStack.NET.TypeGen.Abstractions (attributes + settings types)
is pulled in transitively. The analyzer self-registers; everything else is
in the attribute / configurator surface.
Full reference — type mapping, diagnostic list (TG0001-TG0021), fluent DSL,
[CrudApi] integration, Python emitter, file layout options — lives at
mistykuu.github.io/ZibStack.NET/packages/typegen.
MIT. See the repository root LICENSE file.