Skip to content

Commit 28cfe7c

Browse files
committed
fix enum reference in validation rules
1 parent a290d76 commit 28cfe7c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/schema/src/plugins/zod/generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ export const ${upperCaseFirst(model.name)}UpdateSchema = ${updateSchema};
760760
let expr = new TypeScriptExpressionTransformer({
761761
context: ExpressionContext.ValidationRule,
762762
fieldReferenceContext: 'value',
763+
useLiteralEnum: true,
763764
}).transform(valueArg);
764765

765766
if (isDataModelFieldReference(valueArg)) {

packages/sdk/src/typescript-expression-transformer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Options = {
4040
futureRefContext?: string;
4141
context: ExpressionContext;
4242
operationContext?: 'read' | 'create' | 'update' | 'postUpdate' | 'delete';
43+
useLiteralEnum?: boolean;
4344
};
4445

4546
type Casing = 'original' | 'upper' | 'lower' | 'capitalize' | 'uncapitalize';
@@ -392,7 +393,9 @@ export class TypeScriptExpressionTransformer {
392393
}
393394

394395
if (isEnumField(expr.target.ref)) {
395-
return `${expr.target.ref.$container.name}.${expr.target.ref.name}`;
396+
return this.options.useLiteralEnum
397+
? JSON.stringify(expr.target.ref.name)
398+
: `${expr.target.ref.$container.name}.${expr.target.ref.name}`;
396399
} else {
397400
if (this.options?.isPostGuard) {
398401
// if we're processing post-update, any direct field access should be

0 commit comments

Comments
 (0)