expose omitted fields in the zod schemas
Thanks for this awesome library, I've got a huge schema, and it saved me hours of dev.
I would like to propose a small feature request to have a more flexible way to handle omitted fields.
When a field is omitted in the schema, it's only omitted in the MyModelScalarSchema, not in the MyModelCreateScalarSchema, or MyModelUpdateScalarSchema:
const baseSchema = z.object({ ...all fields...}).strict();
const relationSchema = z.object({ ...relations...});
const fkSchema = z.object({ ...fk fields...});
export const MyModelScalarSchema = baseSchema.omit({
omittedField: true,
....
});
export const MyModelCreateScalarSchema = baseSchema.partial({
...fields with defaults...
});
export const MyModelCreateSchema = MyModelCreateScalarSchema.merge(fkSchema);
export const MyModelUpdateScalarSchema = baseSchema.partial();
export const MyModelUpdateSchema = MyModelUpdateScalarSchema.merge(fkSchema.partial());
IMHO, it would make sense to also exclude them from the MyModelCreateSchema, and MyModelUpdateSchema.
But I understand it's a major change, so should it be possible to expose a variable named myModelOmittedFields or something like that, so we can call it anywhere we need it ?
export const myModelOmittedFields = {
omittedField: true,
....
};
export const MyModelScalarSchema = baseSchema.omit(myModelOmittedFields);
Hi @svengau , thank for filing this. The inconsistency feels like a bug to me and not by intention. I'll check why it's the case. Is it urgent for you?
@ymc9 thanks for your feedback. And for now I handle it manually so not urgent.
@ymc9 I'm wondering if we don't have also an issue with fkSchema: an omitted field will finally be present in MyModelCreateSchema if it's a foreign key.