Skip to content

Commit

Permalink
feat: add "ignorecase" enumStyle option
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael M committed Oct 27, 2023
1 parent 575038c commit 273c6ff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 5 additions & 4 deletions packages/ng-openapi-gen/src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ interface OptionsInput {
response?: string;
/**
* Determines how root enums will be generated. Possible values are:
* - `alias` for a type alias with the possible values;
* - `upper` for an enum with UPPER_CASE names;
* - `pascal` for an enum with PascalCase names (default).
* - `alias` for type aliases with the possible values;
* - `upper` for enums with UPPER_CASE names;
* - `ignorecase` for enums with names as is;
* - `pascal` for enums with PascalCase names (default).
* Defaults to 'pascal'.
*/
enumStyle?: 'alias' | 'upper' | 'pascal';
enumStyle?: 'alias' | 'upper' | 'ignorecase' | 'pascal';
/** Path to directory with custom templates. All `.handlebars` files will override the corresponding default. */
templates?: string;
/** When specified, filters the generated services, excluding any param corresponding to this list of params. */
Expand Down
8 changes: 7 additions & 1 deletion packages/ng-openapi-gen/src/lib/utils/open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ export function qualifiedName(name: string, options: Options): string {
/** Returns the name of the enum constant for a given value */
export function enumName(value: string, options: Options): string {
let name = toBasicChars(value, true);
name = options.enumStyle === 'upper' ? upperCase(name).replace(/\s+/g, '_') : upperFirst(camelCase(name));
if (options.enumStyle === 'ignorecase') {
return name;
} else if (options.enumStyle === 'upper') {
name = upperCase(name).replace(/\s+/g, '_');
} else {
name = upperFirst(camelCase(name));
}
if (/^\d/.test(name)) {
name = '$' + name;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ng-openapi-gen/src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
"default": "StrictHttpResponse"
},
"enumStyle": {
"description": "Determines how root enums will be generated. Possible values are:\n- `alias` for a type alias with the possible values;\n- `upper` for an enum with UPPER_CASE names;\n- `pascal` for an enum with PascalCase names (default).\nDefaults to 'pascal'.",
"enum": ["alias", "upper", "pascal"],
"description": "Determines how root enums will be generated. Possible values are:\n- `alias` for type aliases with the possible values;\n- `upper` for enums with UPPER_CASE names;\n- `ignorecase` for enums with names as is;\n- `pascal` for enums with PascalCase names (default).\nDefaults to 'pascal'.",
"enum": ["alias", "upper", "ignorecase", "pascal"],
"default": "pascal"
},
"templates": {
Expand Down
9 changes: 5 additions & 4 deletions tools/executors/schema-generator/schema-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ export const schemaDescriptor: { properties: Record<string, Property> } = {
enumStyle: {
description: [
'Determines how root enums will be generated. Possible values are:',
'- `alias` for a type alias with the possible values;',
'- `upper` for an enum with UPPER_CASE names;',
'- `pascal` for an enum with PascalCase names (default).',
'- `alias` for type aliases with the possible values;',
'- `upper` for enums with UPPER_CASE names;',
'- `ignorecase` for enums with names as is;',
'- `pascal` for enums with PascalCase names (default).',
'',
].join('\n'),
type: 'enum',
default: 'pascal',
values: ['alias', 'upper', 'pascal'],
values: ['alias', 'upper', 'ignorecase', 'pascal'],
},
// operationPathVisibility: {
// description: 'Determines visibility of "operation path" class properties.',
Expand Down

0 comments on commit 273c6ff

Please sign in to comment.