-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
with v3: error unknown format "date-time" #2146
Comments
Same probleme here (and here #2147 ). Based on #2142 I tried adding ajv-formats to enforce the validation: the error disapear, but the validation is not done. I can provide any data and it will still pass the validator. My object contains a field Here is what I did to enable ajv-formats: import { Model, AjvValidator } from "objection"
import addFormats from('ajv-formats')
export default class MyModel extends Model {
...
// enable ajv formats to validate the date field when inserting in database
static createValidator() {
return new AjvValidator({
onCreateAjv: (ajv) => {
addFormats(ajv)
},
options: {
allErrors: true,
validateSchema: true,
ownProperties: true
},
})
}
static get jsonSchema() {
return {
type: "object",
required: ["theDate"],
properties: {
// if providing something that is not a date, this should cause an error
theDate: {
type: "string",
format: "date"
}
}
}
}
} |
This is the third issue about the exact same thing. |
I see. This is kind of enerving. |
Hey @koskimas, I totally understand your frustration with the duplicate issues. I ran into this issue myself today when upgrading to v3. If I may, I'd recommend adding this as a breaking change to the v3 migration guide. Objection.js v2 uses Ajv v6, which includes formats out of the box. Starting with Ajv v7, however – Objection.js v3 uses Ajv v8 – they separated formats into its own package that you have to manually add. In my mind, that's a breaking change to Objection.js, since it exposes the Ajv functionality. Just a suggestion! |
Feel free to create a PR. I'll merge it. |
@vdechef I believe you may need to add |
helpful to me if you DONT want to convert your date into a string |
For anyone wondering, if you go down the route of adding the ajv-formats package and creating a property with Wasn't obvious to me so thought I'd add a note. |
I updated objection in my project from v2.2.18 to v3.0.0 and suddenly my models are kind of invalid:
and there is an error at
passwordUpdatedAt
-field, which has the "date-time"-Format:I am running a koaJS-app on node v14.18.1. with knex v0.95.14.
Regarding the upgrade instructions at https://vincit.github.io/objection.js/release-notes/migration.html everything should work out of the box - no problems there.
The model was working perfectly in v2.x.
Do you have any clue, what am I doing wrong?
The text was updated successfully, but these errors were encountered: