Skip to content

Zod z.enum() not working on Open API #1417

@xkalf

Description

@xkalf

What version of Elysia is running?

elysia@1.4.5

What platform is your computer?

Darwin 25.0.0 arm64 arm

What environment are you using

1.2.21

Are you using dynamic mode?

no

What steps can reproduce the bug?

table schema

export const user = pgTable("user", {
	id: text("id").primaryKey(),
	name: text("name").notNull(),
	email: text("email").notNull().unique(),
	emailVerified: boolean("email_verified").notNull(),
	image: text("image"),
	createdAt: timestamp("created_at").notNull(),
	updatedAt: timestamp("updated_at").notNull(),
	companyId: uuid().notNull(),
	branchId: uuid().notNull(),
	kind: userKindEnum("kind").notNull().default("CUSTOMER"),
	employeeId: uuid(),
});

model.ts file

const select = createSelectSchema(user);
const create = createInsertSchema(user);
const update = createUpdateSchema(user);

export const selectUserSchema = select
	.partial()
	.pick({
		branchId: true,
	})
	.extend(PaginationSchema.shape);
export type selectUserSchema = z.infer<typeof selectUserSchema>;

export const createUserSchema = create
	.pick({
		name: true,
		email: true,
		kind: true,
		employeeId: true,
	})
	.extend({
		password: z.string().optional(),
		merchantId: z.uuid().optional(),
		branchId: z.uuid().optional(),
		permissions: z.enum(permissionList.map((p) => p.code)),
	});
export type createUserSchema = z.infer<typeof createUserSchema>;

export const updateUserSchema = update.extend({
	permissions: z.enum(permissionList.map((p) => p.code)).optional(),
	password: z.string().optional(),
});
export type updateUserSchema = z.infer<typeof updateUserSchema>;

createUserSchema is works well on open api but updateUserSchema not working

Elysia Route

	.post("/", async ({ body, user }) => UserLogic.registerUser(body, user), {
		body: createUserSchema,
		userKind: "COMPANY_ADMIN",
	})
	.put(
		"/:id",
		async ({ body, user, params: { id } }) =>
			UserLogic.update(id, body, user).catch((e) => console.log(e)),
		{
			body: updateUserSchema,
			userKind: "COMPANY_ADMIN",
		},
	);

when i comment put request open api document is showing but adding this put request is not showing

What is the expected behavior?

No response

What do you see instead?

Image

Additional information

I think z.enum() is not working

	.use(
		openapi({
			documentation: {
				tags: swaggerTags,
			},
			path: "/swagger",
			// references: fromTypes("src/index.ts"),
			mapJsonSchema: {
				zod: toJSONSchema,
			},
		}),
	)

also references: fromTypes is not working on seprate routes

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions