generateEnumBasedOnDescription
Type: boolean | undefined
| Default: false
When set to true
, the generator parses enum values from the description field of the OpenAPI specification for more descriptive enum names.
Usage
typescript
// openapi.config.ts
import { GeneratorConfig } from 'ng-openapi';
const config: GeneratorConfig = {
options: {
enumStyle: 'enum',
generateEnumBasedOnDescription: true,
},
... // other configurations
};
export default config;
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Description Format
The generator expects the description to be a JSON string of EnumValueObject[]
:
typescript
interface EnumValueObject {
Name: string;
Value: number;
}
1
2
3
4
2
3
4
Example OpenAPI Enum with Description
json
{
"Status": {
"enum": [0, 1],
"type": "integer",
"description": "[{\"Name\":\"Active\",\"Value\":0},{\"Name\":\"InActive\",\"Value\":1}]",
"format": "int32"
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Generated enum:
typescript
enum Status {
Active = 0,
Inactive = 1
}
1
2
3
4
2
3
4
Notes
- If the description doesn't match the expected format, the generator falls back to using enum values directly