Skip to content

Commit

Permalink
Correctly handle enum generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Fernando Planella Gonzalez committed Feb 6, 2019
1 parent a28f2d2 commit bf460eb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/gen-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function typeName(name: string): string {
*/
export function enumName(value: string, options: Options): string {
const name = toBasicChars(value, true);
if (options.enumModule === 'upper') {
if (options.enumStyle === 'upper') {
return upperCase(name).replace(/\s+/g, '_');
} else {
return upperFirst(camelCase(name));
Expand Down
6 changes: 2 additions & 4 deletions lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class Model extends GenType {
// Simple properties
simpleType: string;
enumValues: EnumValue[];
enumModule: boolean;

// Array properties
elementType: string;
Expand All @@ -40,10 +39,9 @@ export class Model extends GenType {

const type = schema.type || 'any';

// When enumModule is 'alias' it is handled as a simple type.
if (options.enumModule !== 'alias' && (schema.enum || []).length > 0 && ['string', 'number', 'integer'].includes(type)) {
// When enumStyle is 'alias' it is handled as a simple type.
if (options.enumStyle !== 'alias' && (schema.enum || []).length > 0 && ['string', 'number', 'integer'].includes(type)) {
this.enumValues = (schema.enum || []).map(v => new EnumValue(type, v, options));
this.enumModule = true;
}

this.isObject = type === 'object' || (schema.allOf || []).length > 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface Options {
*
* Defaults to 'pascal'.
*/
enumModule?: 'alias' | 'upper' | 'pascal';
enumStyle?: 'alias' | 'upper' | 'pascal';

/** Custom templates directory. Any `.handlebars` files here will be used instead of the corresponding default. */
templates?: string;
Expand Down
3 changes: 1 addition & 2 deletions test/all-types.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"$schema": "../ng-openapi-gen-schema.json",
"input": "all-types.json",
"output": "out/all-types",
"enumModule": "none"
"output": "out/all-types"
}
5 changes: 3 additions & 2 deletions test/cyclos.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "../ng-openapi-gen-schema.json",
"input": "cyclos.yaml",
"input": "cyclos.json",
"output": "out/cyclos",
"includeTags": [
"Auth",
Expand All @@ -23,5 +23,6 @@
"Captcha",
"Files",
"Images"
]
],
"enumStyle": "upper"
}

0 comments on commit bf460eb

Please sign in to comment.