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 {
2121 keyword : 'fjs_type' ,
2222 type : 'object' ,
2323 errors : false ,
24- validate : ( _type , date ) => {
25- return date instanceof Date
24+ validate : ( _type , data ) => {
25+ return data && typeof data . toJSON === 'function'
2626 }
2727 } )
2828
@@ -51,8 +51,10 @@ class Validator {
5151 return this . ajv . validate ( schemaRef , data )
5252 }
5353
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
5658 // (see https://github.com/fastify/fast-json-stringify/pull/441)
5759 convertSchemaToAjvFormat ( schema ) {
5860 if ( schema === null ) return
You can’t perform that action at this time.
0 commit comments