objection.js: type must be JSONType or JSONType[]: date-time

After update to the 3.0.0 I got this validation error.

static get jsonSchema() {
		return {
			type: "object",
			required: [
				"first_name",
				"last_name",
				"email",
				"phone_number",
			],
			properties: {
				first_name: { type: "string" },
				last_name: { type: "string" },
				last_change: { type: "date-time" },
				email: { type: "email" },
				phone_number: { type: "string" },
				last_try: { type: "date-time" },
				last_logged: { type: "date-time" },
			},
		};
	}
const now = new Date(Date.now());
const lastLogged = response.isValid ? { last_logged: now } : {};

const toPatch = {
	last_try: now,
	...lastLogged,
};

await user.$query().patch(toPatch);

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

date-time is not a valid JSON schema type. It’s been working before by accident. I think Ajv has added more validation in recent versions. email is also not a valid type.

Valid types are JSON types string, number, boolean, object, array and null (and also integer). You can use the format field to implement additional format checks like date-time or email. See what formats Ajv supports by default. You may need to add a library like ajv-formats to make those work.