Skip to content

enumStyle โ€‹

Type: string | Required

Specifies how to generate enum types in the generated code. Can be either a TypeScript enum or a union type.

Usage โ€‹

typescript
// openapi.config.ts
import { GeneratorConfig } from 'ng-openapi';

const config: GeneratorConfig = {
  options: {
    enumStyle: 'enum' // or 'union'
  },
  ... // other configurations
};

export default config;

Supported Options โ€‹

'enum' (Default) โ€‹

Generates TypeScript enum types for enumerations.

typescript
// Example enum with integer values
enum Status {
    _0 = 0,
    _1 = 1,
}

// Example enum with string values
enum Status {
    Active = "active",
    Inactive = "inactive",
}

'union' โ€‹

Generates a literal-union type alias plus a same-named const object, so values can be both type-checked and referenced like enum members.

typescript
export type Status = 'active' | 'inactive';
export const Status = {
    Active: 'active' as Status,
    Inactive: 'inactive' as Status,
};

Notes โ€‹

  • OpenAPI only stores enum values, not names. The generator creates TypeScript enums with names based on values
  • If your OpenAPI spec contains a description for the enum object, ng-openapi can generate enums based on that description

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