Skip to content

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:

typescript
// 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):

typescript
// 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 โ€‹

PropertyTypeRequiredDefaultDescription
inputstringโœ…โ€”Path or URL of the OpenAPI/Swagger spec (.json, .yaml, .yml)
outputstringโœ…โ€”Output directory for generated files
optionsobjectโœ…โ€”Generation options โ€” see options overview
clientNamestringโ€”'default'Names the provider function and tokens; enables multiple clients per app
validateInput(spec) => booleanโ€”undefinedAcceptance check on the parsed spec; false aborts generation
pluginsIPluginGeneratorClass[]โ€”undefinedPlugin generators run after core generation
compilerOptionsobjectโ€”undefinedts-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.

Released under the MIT License.
This site is powered by Netlify
About ยท Impressum