Getting started
Want to see the output first? Paste a spec into the playground; the generator runs in your browser.
Install
Section titled “Install”pnpm add -D @avsystem/openapi-ngopenapi-ng requires Node.js 22.12+. See Runtime & platforms
for the full compatibility matrix.
Generate from the CLI
Section titled “Generate from the CLI”openapi-ng generate --input petstore.openapi.yaml --output ./generatedOutput:
✓ Generated 5 files from Petstore (3.0.3) 1 path · 1 operation · 1 schema
model.ts rest.model.ts rest.util.ts rest.validate.ts rest/pet.rest.tsThe full flag list is on the CLI page.
Generate from Node
Section titled “Generate from Node”import { generate } from '@avsystem/openapi-ng';
const result = await generate({ inputPath: './petstore.openapi.yaml', outputPath: './generated', emit: ['models', 'angular'],});
console.log(result.summary);console.log(result.diagnostics);console.log(result.artifacts);Omit outputPath to keep the result entirely in memory.
What you get
Section titled “What you get”| Artifact | File | Description |
|---|---|---|
| TypeScript models | model.ts |
Interfaces, type aliases, and string enum unions |
| Angular support | rest.model.ts, rest.util.ts |
HTTP helper types and request utilities |
| Forms validation | rest.validate.ts |
validateRest helper for signal-forms async validation (optional peer) |
| Angular services | rest/{tag}.rest.ts |
@Injectable service classes grouped by OpenAPI tag |
With operations in layout each service gives way to one file per
operation under rest/{tag}/ plus a barrel rest/{tag}/index.ts; list
services as well to keep the classes. See
Layout.
See Angular generator for the shape of the emitted services and example component usage.
The output directory belongs to the generator. Every file in it starts
with a // Generated by openapi-ng banner and is overwritten on each
run, so point --output at a directory of its own and treat it as one
unit: commit or ignore the whole directory, and exclude it from lint
and formatting rules the same way. Files the generator no longer emits
are not removed, so delete the directory before regenerating after
removing an operation or renaming a tag.
Next steps
Section titled “Next steps”- Tune naming and mapped types on the Configuration page.
- Walk through the Angular generator to see what the services look like and how to consume them.
- Skim the Diagnostics reference so error codes don’t surprise you later.