Skip to content
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

Error: unknown format "date-time" ignored in schema at path "#/properties/expires" #2249

Open
RodrigoNovais opened this issue Mar 22, 2022 · 5 comments

Comments

@RodrigoNovais
Copy link

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-3

The 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.

@abedmurrar
Copy link

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,
      },
    });
  }
}

@RodrigoNovais
Copy link
Author

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

@sfratini
Copy link

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.

@marceliwac
Copy link

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!

@lehni
Copy link
Collaborator

lehni commented Apr 15, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants