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;1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
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",
}1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
'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,
};1
2
3
4
5
2
3
4
5
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
enumobject,ng-openapican generate enums based on that description