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
10 changes: 6 additions & 4 deletions lib/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Validator {
keyword: 'fjs_type',
type: 'object',
errors: false,
validate: (_type, date) => {
return date instanceof Date
validate: (_type, data) => {
return data && typeof data.toJSON === 'function'
}
})

Expand Down Expand Up @@ -51,8 +51,10 @@ class Validator {
return this.ajv.validate(schemaRef, data)
}

// Ajv does not support js date format. In order to properly validate objects containing a date,
// it needs to replace all occurrences of the string date format with a custom keyword fjs_type.
// Ajv does not natively support JavaScript objects like Date or other types
// that rely on a custom .toJSON() representation. To properly validate schemas
// that may contain such objects (e.g. Date, ObjectId, etc.), we replace all
// occurrences of the string type with a custom keyword fjs_type
// (see https://github.com/fastify/fast-json-stringify/pull/441)
convertSchemaToAjvFormat (schema) {
if (schema === null) return
Expand Down
Loading