Generated output and regeneration
Generation produces TypeScript source, not a standalone HTTP implementation: install the packages the actual output imports.
How the input is read
The input is read as a Wow Manifest when it is one: a document with a numeric format and a contexts array, and no openapi or swagger key, as a service answers it at GET /wow/manifest or as a project commits it as a baseline. Anything else must be an OpenAPI 3 document.
- From a Manifest, the generator writes the typed clients on
@ahoo-wang/wow-client, one directory per bounded context: its commands, queries, state and service routes. - From an OpenAPI document, it writes the document's models (
types.ts) and one decorator API client per tag (*ApiClient.ts), and nothing else: no command, query or state client, whatever the document's paths. Compile them withexperimentalDecorators: true.
Output families
From a Manifest
For each bounded context, a directory named after it:
| Output | Holds |
|---|---|
contract.ts | <Context>Contract: the context's name, its context-level error codes, its wait hops (Wait) and its aggregates, each with its error codes; the <Context>ErrorCode union and <Context>Subscription |
manifest.ts | <Context>Manifest, a RoutingManifest: the routes of every command the context lists (each aggregate's domain and system commands, by their names and former names, and the context's own, a job's; an internal command left out) and of its service routes, and the property of the body that names the aggregate of a command whose body does (idProperty), with no schema. The command clients send by it, as a CommandClient over the whole Manifest does |
client.ts | <Context>Client: the context's CommandClient (commands), which writes every command's exact numbers unquoted as the aggregate's command client does, and, per aggregate, its command, snapshot, event and state clients; its service routes (routes) when it has any |
routes.ts | <Context>Routes: a method per service route, on ServiceRoutes of @ahoo-wang/wow-client/routes; written only when the Manifest lists service routes |
textNumbers.ts | Where a recursive type holds exact numbers, marked once; written only when one does |
types.ts | The commands, events and states of the Manifest's schemas, each named after its class's simple name; a name two classes share, or one the generated modules already bind, is qualified by the class's package. A computed property (readOnly in its schema) is readonly. A type a caller sends (a command's or a lifecycle command's body, a service route's request or parameter) that holds a computed property, at any depth, is declared again as <Name>Input, numbered when the Manifest already uses the name: the type the method takes, in which that property is optional. A schema is typed by all its keywords at once: a class's own properties and the allOf part of each @JsonUnwrapped member ({ sku: string } & { home_street: string }), a reference and what is written beside it (a recursive subtype's discriminator), and a WRAPPER_ARRAY type's arrays (prefixItems) as tuples of the type id and the value (['Payment$Card', { amountMinor: string }, ...unknown[]], more items of any value, as the schema admits them). An array's items share one exact-number mark, so a tuple whose places read one number differently (one int64, another int32) fails the generation (exit 4), as a union's alternatives that no discriminator tells apart do |
<aggregate>/aggregate.ts | <Aggregate>Aggregate, the aggregate's descriptor; <Aggregate>StateField, the state.* fields a query names, those the Kotlin contract names, within arrays and nullable objects included; <Aggregate>Access, its access attributes; <Aggregate>Event, the union of its events, an event renamed with @Alias also under each former name (a name alone in the aggregate, a full name as it is), with the renamed event's body and exact numbers |
<aggregate>/commandClient.ts | <Aggregate>CommandClient: a method per command, a …Stream twin of each answering each hop, and the lifecycle commands the aggregate lists, sending through its commands, a CommandClient over the context's manifest.ts |
<aggregate>/queryClient.ts | <Aggregate>SnapshotQueryClient, <Aggregate>EventQueryClient and <Aggregate>StateClient |
index.ts | Recursive exports for the .ts files of this run and nonempty subdirectories. A name two contexts both export, such as the types of an aggregate name both have, is left out of the root index with no warning (--strict passes): import it from its context's index.ts |
.wow-generator.json | Version 1 ownership manifest with SHA-256 hashes of generated .ts files |
From an OpenAPI document
| Output | Generation rules |
|---|---|
types.ts | Component schemas grouped by schema-name namespace; model types and enums |
*ApiClient.ts | Ordinary tagged operations with operationId; operation tags must all be eligible API tags. Named after the class, camelCase like every generated file: cartApiClient.ts |
index.ts | Recursive exports for the .ts files of this run and nonempty subdirectories |
.wow-generator.json | Version 1 ownership manifest with SHA-256 hashes of generated .ts files |
Source conventions
Every generated file starts with // Code generated by wow-generator. DO NOT EDIT. and uses single quotes, two-space indentation and semicolons. Relative imports end in .js and each barrel re-exports ./dir/index.js, so the output compiles under "moduleResolution": "NodeNext" as well as "bundler".
Imports are written explicitly while generating, so the output is byte-for-byte the same whether or not the output directory resolves @ahoo-wang/*. Before saving, the generator checks that every file declares or imports each name it uses and declares none twice; if not, nothing is written. That check does not replace the consumer compiler.
A name that two sibling modules both export, such as a model of the same name in two packages, is left out of their common index.ts with a warning; import it from its own module.
Model doc comments carry a summary: title, description, schema key, format, default, example and constraints. A model of an object also lists the properties its schema requires (- required: a, b, or - required: (none)), since every generated property is declared without ?, with one exception: a property that is readOnly and that the schema does not require is declared optional, because the document says a reader may not find it (the input of a type whose computed property a request may leave out). A nullable value written as anyOf: [{type: null}, X] is documented from X, so a nullable integer keeps its format. --schema-docs full (option schemaDocs: 'full') also embeds the complete JSON schema. From a Manifest, the comment of a type and of each of its properties opens with the schema's title and description: the @Summary and @Description the service's source declares on the class and on the property, a property's own beside the reference to its type.
API client methods
An OpenAPI document's API clients name their methods, in order: apiClients[tag].methodNames[operationId] from the configuration, the operation's x-fetcher-method extension, or the last dot-separated segment of the operationId, camel-cased:
| operationId | Method |
|---|---|
getUserById | getUserById |
delete_user_by_id | deleteUserById |
getUser_1 | getUser1 |
users.list | list |
example.cart.add_cart_item | addCartItem |
The name depends on the operation alone, so adding an operation never renames an existing method. Two operations of one client that arrive at the same name fail the run with exit code 4, naming both operations; give one of them a name with methodNames or x-fetcher-method.
Ordinary methods take every path, query and header parameter as a typed positional parameter named after it (item-id → itemId), and the request body as its own @body() parameter. Required ones come first - the path parameters in the order the path holds them, then query and header parameters in document order, then the body - and optional ones follow, so a caller never passes undefined to reach a required one. Then come httpRequest?: ParameterRequest, for anything else a request may set (extra headers, a timeout, a signal), and attributes?: Record<string, unknown>:
search(@path('item-id') itemId: string, @query('q') q: string,
@header('X-Tenant') xTenant: string, @query('page') page?: number,
@query('status') status?: 'open' | 'closed',
@request() httpRequest?: ParameterRequest,
@attribute() attributes?: Record<string, unknown>): Promise<Item[]>| Parameter or body | Generated type |
|---|---|
| Path parameter | Always required; ignorePathParameters leaves some out |
| Query or header parameter | Required when the document says required: true; a primitive enum is the union of its literals |
| Cookie parameter | Left out with a warning: the browser sends cookies, and fetch cannot set them |
JSON body (application/json, +json) | The schema's type; properties the schema does not require, and the read-only ones, stay optional through PartialBy<Item, 'id'>, at the body's top level |
multipart/form-data | FormData |
application/x-www-form-urlencoded | URLSearchParams |
text/* | string |
| Any other media type | BodyInit |
The body is required when requestBody.required is true. A parameter's description becomes a @param tag of the method's doc comment. Path-level parameters are inherited; operation parameters override matching in/name. An operation without an operationId or a tag is skipped with a warning.
The return type comes from the success response: 200, else the lowest other 2xx, else 2XX. Any JSON media type (application/json, +json, with or without a charset) is typed from its schema, then a wildcard schema, then SSE. text/*, and a string schema under a wildcard, return Promise<string>; recognized SSE returns JsonServerSentEventStream, with any fallback when the event model cannot be inferred. Without an inferred body, the fallback is Promise<Response> with native Response extraction. Generated methods rely on decorators replacing their throw autoGeneratedError(...) placeholder at runtime.
Names and schemas
- Names become identifiers: parameter
item-id→itemId, schemaPage«User»→PageUser,1stThing→_1stThing, a Manifest's commandPayOrder→payOrder.*/inside descriptions is escaped. - A type name keeps each part of the schema name that starts with an upper-case letter and holds no separator as written, acronyms included:
MCPListToolsstaysMCPListTools,OpenAIFilestaysOpenAIFile. A part with a separator or a lower-case start is pascal-cased (order_item→OrderItem). Method names, enum members and endpoint constants keep their own rules. - Two schemas that normalise to the same model fail with exit code 4. Enum values that normalise alike get distinct members. Tags that name the same client generate a numbered class (
User2ApiClient) with a warning. - A
$refthat points at nothing fails with exit code 4, listing the references. { nullable: true, allOf: [{ $ref }] }admitsnull. AoneOfwith a discriminator narrows each branch by the discriminator property. A map of its own type generates an interface with an index signature. Models namedRecordorResponseare imported under an alias so they do not shadow the globals.- A Manifest's command body of no properties is
Record<string, never>, since the service refuses a member the body does not declare; an empty event staysRecord<string, unknown>, which a newer service may add to.
Runtime setup
pnpm add @ahoo-wang/fetcher @ahoo-wang/fetcher-eventstream @ahoo-wang/wow-client
pnpm exec wow-generator generate -i ./manifest.json -o ./src/generated
pnpm exec tsc --noEmit -p ./tsconfig.json@ahoo-wang/fetcher-eventstream is @ahoo-wang/wow-client's peer, for the …Stream methods. An OpenAPI document's API clients also import @ahoo-wang/fetcher-decorator.
A context's clients are built together by its <Context>Client, from WowClientOptions. fetcher sends the requests (the default fetcher when absent), with the host's interceptors (authentication, say), and basePath is a path put before every route, such as a gateway's prefix. Generation does not call the services. The eShop basket's:
// Code generated by wow-generator. DO NOT EDIT.
import { CommandClient, type WowClientOptions } from '@ahoo-wang/wow-client';
import { BasketAggregate } from './basket/aggregate.js';
import { BasketCommandClient } from './basket/commandClient.js';
import { BasketEventQueryClient, BasketSnapshotQueryClient, BasketStateClient } from './basket/queryClient.js';
import { EshopBasketManifest } from './manifest.js';
/** The clients of `eshop-basket`: its command client, and per aggregate its command, query and state clients. */
export class EshopBasketClient {
/** Sends any command of the service, by its Manifest's routes: `send`, `wait` and `stream`. */
readonly commands: CommandClient;
/** The clients of `eshop-basket.basket`. */
readonly basket: {
readonly commands: BasketCommandClient;
readonly snapshots: BasketSnapshotQueryClient;
readonly events: BasketEventQueryClient;
readonly state: BasketStateClient;
};
/** @param options - How the service is reached */
constructor(options?: WowClientOptions) {
this.commands = new CommandClient(options, {
manifest: EshopBasketManifest, textNumbers: {
'eshop-basket.basket.AddBasketItem': BasketAggregate.textNumbers.commands['eshop-basket.basket.AddBasketItem'],
}
});
this.basket = {
commands: new BasketCommandClient(options),
snapshots: new BasketSnapshotQueryClient(options),
events: new BasketEventQueryClient(options),
state: new BasketStateClient(options),
};
}
}The eShop web UI builds the clients of its five contexts on one fetcher of the page's origin, whose routes each start with /eshop-<context>/ (examples/eshop/web/src/shop/clients.ts).
Ownership and failures
Files emitted again at the same path are replaced: keep hand-written customizations outside generated files. Stale files are deleted only if they were recorded in the prior manifest and their content hash is unchanged. Modified stale files and unrelated files are preserved; preservation does not make them part of the current generated API. The generated index.ts files export only the files this run generates: a hand-written file in the output directory, or a modified stale one, is never re-exported, whatever the tsconfig include covers; import it from its own module.
A manifest the run cannot read fails it with exit code 5 before anything is written, and the message says what to do. One that is not JSON, typically a merge conflict in a committed manifest: resolve the conflict, or delete the file, knowing that without it this run cannot remove the stale files of the last one. One written by a newer wow-generator (a manifest version above 1): upgrade wow-generator. Anything else: restore it from version control, or delete it. A generated path escaping the output root also throws. Saves are awaited before stale deletion and the new manifest, but the operation is not an atomic directory transaction: partial writes can remain after failure. A run interrupted with Ctrl-C while it writes finishes the files it started, then stops without deleting stale files or writing the manifest, so the manifest never records a run that did not finish. Do not delete the manifest to force cleanup; use a dedicated output directory and review its diff after regeneration. The generator's own name check does not prove the output type-checks against your dependencies: run the consumer compiler.
Implementation sources
typescript/wow-generator/src/output/outputStore.ts
typescript/wow-generator/src/analysis/apiClients.ts
typescript/wow-generator/src/emitters/apiClients.ts
typescript/wow-generator/src/emitters/manifest/