Open gjstreicher opened 6 months ago
Are you talking about the generated open API doc? Are null
and undefined
not being parsed correctly there?
Are you talking about the generated open API doc? Are
null
andundefined
not being parsed correctly there?
Nope, I'm just talking about the error that is returned from the validation of the passed data failing against the given schema.
Could you share a code example that throws this error?
Dependency versions
Node version: 21.7.3 Fastify version: 4.26.2 Zod version: 3.22.4 Fastify-Type-Provider-Zod version: 1.1.9
Issue description
A Zod schema used to validate a JSON object containing a property that can be
null
, by using the Zod.nullish()
or.nullable()
methods on the given object schema property, doesn't indicate that the value can be the JSON value ofnull
.This means that users of an API endpoint with this JSON as it's body won't be able to discover that they can pass
null
as a valid option.This is important because
null
indicates something different toundefined
. For example, assigning the value ofnull
to a property of a resource on an update endpoint can indicate that the given property (or attribute) needs to be deleted for the given resource, whilst assigning the value ofundefined
to the same property (or simply leaving out the property completely) can indicate that the update should leave the given property (or attribute) in tact and unchanged.