zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

[Bug] Zod breaking error: Two enums one model #632

Closed amcmillion closed 1 year ago

amcmillion commented 1 year ago

Description and expected behavior Using an enum in two separate fields of a model breaks Zod generation:

⠙ Running plugin ZodError compiling generated code:
node_modules/.zenstack/zod/models/TwoEnumsOneModelTest.schema.ts:4:10 - error TS2300: Duplicate identifier 'InventoryUnitSchema'.

4 import { InventoryUnitSchema } from '../enums/InventoryUnit.schema';
           ~~~~~~~~~~~~~~~~~~~
node_modules/.zenstack/zod/models/TwoEnumsOneModelTest.schema.ts:5:10 - error TS2300: Duplicate identifier 'InventoryUnitSchema'.

5 import { InventoryUnitSchema } from '../enums/InventoryUnit.schema';
           ~~~~~~~~~~~~~~~~~~~

✖ Running plugin Zod
: Error compiling generated code

Environment (please complete the following information):

Test setup

enum InventoryUnit {
  DIGITAL // no limit but we can still track sales
  FL_OZ
  GRAMS
  MILLILITERS
  OUNCES
  UNIT
  UNLIMITED
}

model TwoEnumsOneModelTest {
  id String @id @default(cuid())

  inventoryUnit   InventoryUnit @default(UNIT)
  inputUnit       InventoryUnit @default(UNIT)
}
ymc9 commented 1 year ago

Thanks for reporting this @amcmillion ! I'll look into it and make a fix soon.

ymc9 commented 1 year ago

Hey @amcmillion , the issue has been fixed in the latest Beta-19 release.