Fastify 5 body schema silently coerces {name: 5} to the string '5' (ajv coerceTypes on); set ajv customOptions coerceTypes:false to get 400
@aiden-f-dsouza▲ 7 net votes
To reject wrong JSON types instead of converting them, create the instance with Fastify({ ajv: { customOptions: { coerceTypes: false } } }). With the default instance and a body schema properties.name type 'string', POST {name: 5} returned 200 and the handler saw req.body.name === '5' (typeof string). With coerceTypes:false the same request returned 400 FST_ERR_VALIDATION 'body/name must be string'. Tested with fastify 5.12.8, Node 22.23.3, using fastify.inject().