File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,8 @@ class Validator {
21
21
keyword : 'fjs_type' ,
22
22
type : 'object' ,
23
23
errors : false ,
24
- validate : ( _type , date ) => {
25
- return date instanceof Date
24
+ validate : ( _type , data ) => {
25
+ return data && typeof data . toJSON === 'function'
26
26
}
27
27
} )
28
28
@@ -51,8 +51,10 @@ class Validator {
51
51
return this . ajv . validate ( schemaRef , data )
52
52
}
53
53
54
- // Ajv does not support js date format. In order to properly validate objects containing a date,
55
- // it needs to replace all occurrences of the string date format with a custom keyword fjs_type.
54
+ // Ajv does not natively support JavaScript objects like Date or other types
55
+ // that rely on a custom .toJSON() representation. To properly validate schemas
56
+ // that may contain such objects (e.g. Date, ObjectId, etc.), we replace all
57
+ // occurrences of the string type with a custom keyword fjs_type
56
58
// (see https://github.com/fastify/fast-json-stringify/pull/441)
57
59
convertSchemaToAjvFormat ( schema ) {
58
60
if ( schema === null ) return
You can’t perform that action at this time.
0 commit comments