Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ export const TypeBoxValidatorCompiler: FastifySchemaCompiler<TSchema> = ({ schem
if (typeCheck.Check(converted)) {
return { value: converted }
}
const errors = [...typeCheck.Errors(converted)]
const errors = []
for (const error of typeCheck.Errors(converted)) {
errors.push({
message: error.message,
instancePath: error.path
})
}
return {
// Note: Here we return a FastifySchemaValidationError[] result. As of writing, Fastify
// does not currently export this type. Future revisions should uncomment the assertion
// below and return the full set of properties. The specified properties 'message' and
// 'instancePath' do however result in a near equivalent error messages to Ajv.
error: errors.map((error) => ({
message: `${error.message}`,
instancePath: error.path
})) // as FastifySchemaValidationError[]
error: errors // as FastifySchemaValidationError[]
}
}
}
Expand Down