Skip to content

Commit 8fe1d9b

Browse files
feat: return complete validation error properties (#243)
* feat: complete validation error properties * remove any --------- Co-authored-by: Jean <110341611+jean-michelet@users.noreply.github.com>
1 parent 64e737c commit 8fe1d9b

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

index.mts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
FastifyPluginCallback,
44
FastifyPluginOptions,
55
FastifySchemaCompiler,
6+
FastifySchemaValidationError,
67
FastifyTypeProvider,
78
RawServerBase,
89
RawServerDefault
@@ -23,25 +24,15 @@ export * from 'typebox'
2324
*/
2425
export const TypeBoxValidatorCompiler: FastifySchemaCompiler<TSchema> = ({ schema, httpPart }) => {
2526
const typeCheck = Compile(schema)
26-
return (value): any => {
27+
return (value): any /* TODO: remove any for next major */ => {
2728
// Note: Only support value conversion for querystring, params and header schematics
2829
const converted = httpPart === 'body' ? value : Value.Convert(schema, value)
2930
if (typeCheck.Check(converted)) {
3031
return { value: converted }
3132
}
32-
const errors = []
33-
for (const error of typeCheck.Errors(converted)) {
34-
errors.push({
35-
message: error.message,
36-
instancePath: error.instancePath
37-
})
38-
}
33+
const errors: FastifySchemaValidationError[] = typeCheck.Errors(converted);
3934
return {
40-
// Note: Here we return a FastifySchemaValidationError[] result. As of writing, Fastify
41-
// does not currently export this type. Future revisions should uncomment the assertion
42-
// below and return the full set of properties. The specified properties 'message' and
43-
// 'instancePath' do however result in a near equivalent error messages to Ajv.
44-
error: errors // as FastifySchemaValidationError[]
35+
error: errors
4536
}
4637
}
4738
}

0 commit comments

Comments
 (0)