Closed Fedinjo closed 12 months ago
I just had to migrate from Zod to Yup and I've noticed that Yup doesn't set all the fields as required by default:
With this schema the validation passes even though all the fields are missing:
export const ContattaciBffPayloadSchema = yup.object().shape({ datiCliente: yup.object({ nomeCognome: yup.string(), codiceFiscale: yup.string().matches(Regexes.CodiceFiscale), testo: yup.string(), }), recapitoAgenzia: yup.string().email(), });
Adding .required() everywhere fixes it:
export const ContattaciBffPayloadSchema = yup.object().shape({ datiCliente: yup.object({ nomeCognome: yup.string().required(), codiceFiscale: yup.string().matches(Regexes.CodiceFiscale).required(), testo: yup.string().required(), }), recapitoAgenzia: yup.string().email().required(), }).required();
My question is: is there a way to make all the fields required by default so that you don't need to add .required() in every place?
.required()
There is not a way to change the default. you can wrap the schema factories and set things to required and reexport them if you want.
I just had to migrate from Zod to Yup and I've noticed that Yup doesn't set all the fields as required by default:
With this schema the validation passes even though all the fields are missing:
Adding .required() everywhere fixes it:
My question is: is there a way to make all the fields required by default so that you don't need to add
.required()
in every place?