Skip to content

Commit bc36d06

Browse files
committed
fix(DEV-656): Fix isOptional and enum generation in server object/module commands
1 parent 03362ee commit bc36d06

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/extensions/parse-properties.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ export default (toolbox: ExtendedGluegunToolbox) => {
104104
const value = parameters.options[key];
105105

106106
if (field === 'nullable' || field === 'isArray') {
107-
propData[field] = value === 'true';
107+
// Accept both string 'true' and boolean true
108+
propData[field] = value === 'true' || value === true;
108109
} else {
109110
propData[field] = value;
110111
}

src/extensions/server.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,9 @@ export class Server {
470470
}
471471

472472
// Use utility functions for enum and type config
473+
// For enums, only use enum property (not type property)
473474
const enumConfig = this.getEnumConfig(item);
474-
const typeConfig = this.getTypeConfig(modelFieldType, isArray);
475+
const typeConfig = enumConfig ? '' : this.getTypeConfig(modelFieldType, isArray);
475476

476477
// Build mongoose configuration
477478
const mongooseConfig = reference
@@ -492,8 +493,8 @@ export class Server {
492493
description: '${this.pascalCase(propName) + (modelName ? ` of ${this.pascalCase(modelName)}` : '')}',
493494
${enumConfig}isOptional: ${item.nullable},
494495
mongoose: ${mongooseConfig},
495-
roles: RoleEnum.S_EVERYONE,
496-
${typeConfig}
496+
roles: RoleEnum.S_EVERYONE,${typeConfig ? `
497+
${typeConfig}` : ''}
497498
})
498499
${propName}: ${(reference ? reference : schema ? schema : enumRef || modelClassType) + (isArray ? '[]' : '')}${undefinedString}
499500
`;
@@ -592,8 +593,9 @@ export class Server {
592593
}
593594

594595
// Use utility functions for enum and type config
596+
// For enums, only use enum property (not type property)
595597
const enumConfig = this.getEnumConfig(item);
596-
const typeConfig = this.getTypeConfig(inputFieldType, item.isArray);
598+
const typeConfig = enumConfig ? '' : this.getTypeConfig(inputFieldType, item.isArray);
597599

598600
result += `
599601
/**
@@ -602,8 +604,8 @@ export class Server {
602604
@UnifiedField({
603605
description: '${this.pascalCase(name) + propertySuffix + (modelName ? ` of ${this.pascalCase(modelName)}` : '')}',
604606
${enumConfig}isOptional: ${nullable || item.nullable},
605-
roles: RoleEnum.S_EVERYONE,
606-
${typeConfig}
607+
roles: RoleEnum.S_EVERYONE,${typeConfig ? `
608+
${typeConfig}` : ''}
607609
})
608610
${overrideFlag + this.camelCase(name)}${nullable || item.nullable ? '?' : ''}: ${inputClassType}${item.isArray ? '[]' : ''}${propertyUndefinedString}
609611
`;

0 commit comments

Comments
 (0)