Configuration โ
Extensive configuration options to customize the generated output to match your needs.
Usage โ
The defineConfig helper gives you full autocomplete and inline type errors without a manual annotation:
// openapi.config.ts
import { defineConfig } from "ng-openapi";
export default defineConfig({
input: "./swagger.json",
output: "./src/api",
options: {
dateType: "Date",
enumStyle: "enum",
},
});Annotating a plain object with the GeneratorConfig type works identically (and is the way to go on ng-openapi versions that don't ship defineConfig yet):
// openapi.config.ts
import { GeneratorConfig } from "ng-openapi";
const config: GeneratorConfig = {
input: "./swagger.json",
output: "./src/api",
options: {
dateType: "Date",
enumStyle: "enum",
},
};
export default config;Properties at a Glance โ
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
input | string | โ | โ | Path or URL of the OpenAPI/Swagger spec (.json, .yaml, .yml) |
output | string | โ | โ | Output directory for generated files |
options | object | โ | โ | Generation options โ see options overview |
clientName | string | โ | 'default' | Names the provider function and tokens; enables multiple clients per app |
validateInput | (spec) => boolean | โ | undefined | Acceptance check on the parsed spec; false aborts generation |
plugins | IPluginGeneratorClass[] | โ | undefined | Plugin generators run after core generation |
compilerOptions | object | โ | undefined | ts-morph compiler settings for generation |
Configuration Properties โ
Input โ
Type: string | Required
Path or http(s) URL of your OpenAPI/Swagger specification.
Output โ
Type: string | Required
Output directory for generated files.
Options โ
Type: object | Required
Object containing various options to customize the code generation process.
Client Name โ
Type: string | undefined | Default: 'default'
Unique identifier for this client. Names the generated provider function (provide<ClientName>Client) and injection tokens, so multiple clients can coexist in one application.
Validate Input โ
Type: (spec: SwaggerSpec) => boolean | undefined | Default: undefined
Custom acceptance check run on the parsed specification; returning false aborts generation.
Plugins โ
Type: IPluginGeneratorClass[] | undefined | Default: undefined
Plugin generator classes (e.g. HttpResourcePlugin, ZodPlugin), run after core generation.
Compiler Options โ
Type: object | undefined | Default: undefined
TypeScript compiler options for the generated code.