Open RodrigoNovais opened 2 years ago
Objection now uses ajv
version 8, objection 2 probably used ajv
version 6 ( which had built in formats ), formats are now separated to a different package ( which has nothing to do with objection ), but to solve this, you can install ajv-formats
package
$ npm install ajv-formats
and then extend your model's ajv
validator, or in base model
import addFormats from "ajv-formats";
export default abstract class BaseModel extends Model {
static createValidator() {
return new AjvValidator({
onCreateAjv: (ajv) => {
addFormats(ajv);
},
options: {
allErrors: true,
validateSchema: false,
ownProperties: true,
},
});
}
}
In this case, updating the guide would be required since the examples still follows the old system and the types still defines the old behaviour
Thank you for replying, I'll be checking it as soon as possible
This also happens for UUID. Specially if you are using one of the recommended plugins which is objection-guid.
The fix works, but should be added into the native Model class then.
This also happens for UUID. Specially if you are using one of the recommended plugins which is objection-guid.
The fix works, but should be added into the native Model class then.
I can second that, the missing format support for UUID took me by surprise!
This keeps happening, see #2142, #2146, #2147, #2170
@kibertoad should we just include the ajv formats by default and be done with it? #2218 proposes this.
date-time
format is not working correctly in Objection 3. I'm working in a new project using a model structure I'm used to and can be found in this repo: https://github.com/RodrigoNovais/rocketseat-nlw-3The problematic model is
Tokens
, a use case can be found here.This syntax used to work in Objection 2. Using Objection 3, attempting to insert a new token gives me this error:
Error: unknown format "date-time" ignored in schema at path "#/properties/expires"
My use case in the new project is pretty much the same. I'm not sure if this error only relates to the specific 'date-time' format or if it expands for other strings formats.
If there's anything I can change in my code or even in the dependences by my own in order for it to work again it would be enough for me.