Add support for extending zod error messages from existing objects
I have a zod object that is handed to me from elsewhere, and I do not have the ability to change it. However, I do know what items it contains. For example, it has a "firstName" string with a min length of 3 and a max length of 24.
I believe at present there is no way to do something like:
import { alreadyMadeSchema } from 'external-schema-provider';
...
const updatedSchema = alreadyMadeSchema.update({
firstName.min.3: "too short",
firstName.max.24: "too long"
});
Could support be added for such a feature?
Hi, @anthonyalayo. I'm Dosu, and I'm helping the Zod team manage their backlog. I'm marking this issue as stale.
Issue Summary:
- You requested a feature to enhance error messages for immutable Zod schemas.
- Proposed a method to update error messages for specific constraints, such as string length, without altering the original schema.
- Seeking support for implementing this functionality to improve schema validation feedback.
- No comments or developments have occurred on this issue yet.
Next Steps:
- Please let me know if this issue is still relevant to the latest version of the Zod repository. You can keep the discussion open by commenting on the issue.
- If no updates are provided, the issue will be automatically closed in 14 days.
Thank you for your understanding and contribution!
Yes, it is still relevant to the latest version of Zod.
Hi @colinhacks, the user @anthonyalayo has confirmed that the feature request for enhancing error messages for immutable Zod schemas is still relevant. Could you please assist them with this issue? Thank you!
@colinhacks could I get some feedback on this?
@colinhacks could you please take a look at this issue? The user @anthonyalayo has indicated it is still relevant and would appreciate some feedback.
+1, this is still relevant. Many tools generate Zod schemas and as consumers we could inspect and extend it. But simple config updates without changing schema shape would be a nice feature.