Skip to content

Getting started

Want to see the output first? Paste a spec into the playground; the generator runs in your browser.

Terminal window
pnpm add -D @avsystem/openapi-ng

openapi-ng requires Node.js 22.12+. See Runtime & platforms for the full compatibility matrix.

Terminal window
openapi-ng generate --input petstore.openapi.yaml --output ./generated

Output:

✓ 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.ts

The full flag list is on the CLI page.

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.

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.