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

Lost ability to use "date-time" format in JSON Scheme (version 7.0.0) #140

Closed
lnovelli opened this issue Jan 23, 2021 · 3 comments · Fixed by #144
Closed

Lost ability to use "date-time" format in JSON Scheme (version 7.0.0) #140

lnovelli opened this issue Jan 23, 2021 · 3 comments · Fixed by #144

Comments

@lnovelli
Copy link

lnovelli commented Jan 23, 2021

HI,

I just upgraded to 7.0.0, but I get the following error when loading the store using a JSON scheme:

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

Nothing else has changed, just the packages upgrade. Am i missing something? 🤔

My JSON Scheme is the following:


  type AppDatabaseExtra = { lastStartDate: Date }
  
  type AppDatabaseModel = {
    extra: AppDatabaseExtra;
  }

  const AppDatabaseSchema: Schema<AppDatabaseModel> = {
    extra: {
      type: 'object',
      properties: {
        lastStartDate: {
          type: "string",
          format: "date-time"
        }
      }
    }
  }

And I initialize it like this:

  this.store = new Store<AppDatabaseModel>({
        name: "appDatabase",
        schema: AppDatabaseSchema,
        clearInvalidConfig: true
   });

Thank you

@sindresorhus
Copy link
Owner

Please read the release notes.

@ezzatron
Copy link
Contributor

@sindresorhus Could you clarify if it's still supposed to be possible to use ajv formats as stated in the README? I've read the release notes (the part about ajv being updated to v7), but as far as I can tell it's currently impossible to use formats, which explains this issue.

In order to add formats to ajv v7, you need access to the Ajv instance, which conf does not seem to expose:

import Ajv from "ajv"
import addFormats from "ajv-formats"

const ajv = new Ajv()
addFormats(ajv)

@sindresorhus
Copy link
Owner

I missed that in Ajv release notes.

https://github.com/ajv-validator/ajv/blob/ab19dac8690bb3cfdfb0680e986be15d0f11bf75/docs/validation.md#formats

I think we can just depend on ajv-formats in conf since that's how it used to work. PR welcome.

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

Successfully merging a pull request may close this issue.

3 participants