Using Zod objects generated from drizzle zod with ts-rest . Parameters interpreted as optional

Hey I am trying to use drizzle zod to generate zod objects to be used in my ts rest contract. however when I try to use this contract in my handlers the fields in the body being passed are interpreted as being optional and not mandatory contract
import { Tenant } from "@repo/drizzle/src/schema/tenant";
import { selectUserSchema, insertUserSchema } from "./users";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { initContract } from "@ts-rest/core";
import { z } from "zod";

export const insertTenantSchema = createInsertSchema(Tenant).required({ name: true ,subdomain: true}).omit({ id: true, createdAt: true, updatedAt: true })
export const selectTenantSchema = createSelectSchema(Tenant)


const c = initContract();

export const tenantsContract = c.router({
create: {
method: 'POST',
path: '/tenants',
responses: {
201: z.object({
tenant: selectTenantSchema,
adminUser: selectUserSchema.omit({ password: true })
})
},
body: z.object({
tenant: insertTenantSchema,
adminUser: insertUserSchema
}),
summary: 'Create a new tenant with an admin user'
}
});
import { Tenant } from "@repo/drizzle/src/schema/tenant";
import { selectUserSchema, insertUserSchema } from "./users";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { initContract } from "@ts-rest/core";
import { z } from "zod";

export const insertTenantSchema = createInsertSchema(Tenant).required({ name: true ,subdomain: true}).omit({ id: true, createdAt: true, updatedAt: true })
export const selectTenantSchema = createSelectSchema(Tenant)


const c = initContract();

export const tenantsContract = c.router({
create: {
method: 'POST',
path: '/tenants',
responses: {
201: z.object({
tenant: selectTenantSchema,
adminUser: selectUserSchema.omit({ password: true })
})
},
body: z.object({
tenant: insertTenantSchema,
adminUser: insertUserSchema
}),
summary: 'Create a new tenant with an admin user'
}
});
body object
parameter) body: {
tenant?: {
name?: string;
subdomain?: string;
};
adminUser?: {
id?: string;
name?: string;
createdAt?: unknown;
updatedAt?: unknown;
email?: string;
password?: string;
tenantId?: string;
role?: string;
};
}
parameter) body: {
tenant?: {
name?: string;
subdomain?: string;
};
adminUser?: {
id?: string;
name?: string;
createdAt?: unknown;
updatedAt?: unknown;
email?: string;
password?: string;
tenantId?: string;
role?: string;
};
}
2 Replies
Musa
MusaOP5d ago
Musa
MusaOP5d ago
For those of you coming here with the same issue in your tsconfig set
compilerOptions: {
strict: true,
strictNullChecks: true,
}
compilerOptions: {
strict: true,
strictNullChecks: true,
}
this worked for me
Want results from more Discord servers?
Add your server