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/timestamp" #1295

Closed
Gazoh opened this issue Oct 3, 2020 · 10 comments

Comments

@Gazoh
Copy link

Gazoh commented Oct 3, 2020

What version of Ajv are you using? Does the issue happen if you use the latest version?
6.12.5

JSON Schema

https://uniswap.org/tokenlist.schema.json

Sample data

"timestamp": "2018-11-13T20:20:39+00:00"

Your code

export const generateMyTokenList = (tokenList: TokenList) => {
    // Your list
    const myList = tokenList;
    // Creating a new Ajv object
    const validator = new Ajv();
    // Validating if the scheme is a valid scheme
    const validateScheme = validator.validateSchema(schema);
    console.log('validateScheme', validateScheme)
    // If the validateScheme returns true it is a valid scheme than validate my list
    if(validateScheme) {
        let validatedList = validator.validate(schema, myList); 
        console.log('validatedList', validatedList)
    }
}

Validation result, data AFTER validation, error messages

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

What results did you expect?
I am having this trouble also for 'URI'. My question is why is AJV ignoring all the formats? i am using

@epoberezkin
Copy link
Member

Are you sure you are using version 6 and not 7? Try validating just date time string against schema {format: “date-time”}.

A side comment - you don’t need to validate the schema in a separate call to validateSchema, it happens by default.

@epoberezkin
Copy link
Member

This is a working example: https://runkit.com/esp/5f6224b4256fbf001beeee11

Please try to reproduce your issue in runkit (you can clone this sample), but please keep the total code size under 20 lines - I cannot review or debug your application schema.

@BlackGlory
Copy link

I get this error on 7.0.0-beta.3: Unknown format "uri" ignored in schema.
Should I go back to Ajv v6?

@epoberezkin
Copy link
Member

No, the formats are now in ajv-formats package - see its docs how to add them.

@mariano-aguero
Copy link

What version of Ajv are you using? Does the issue happen if you use the latest version?
6.12.5

JSON Schema

https://uniswap.org/tokenlist.schema.json

Sample data

"timestamp": "2018-11-13T20:20:39+00:00"

Your code

export const generateMyTokenList = (tokenList: TokenList) => {
    // Your list
    const myList = tokenList;
    // Creating a new Ajv object
    const validator = new Ajv();
    // Validating if the scheme is a valid scheme
    const validateScheme = validator.validateSchema(schema);
    console.log('validateScheme', validateScheme)
    // If the validateScheme returns true it is a valid scheme than validate my list
    if(validateScheme) {
        let validatedList = validator.validate(schema, myList); 
        console.log('validatedList', validatedList)
    }
}

Validation result, data AFTER validation, error messages

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

What results did you expect?
I am having this trouble also for 'URI'. My question is why is AJV ignoring all the formats? i am using

I'm using the version 6.12.6 and seems to works fine, I'm trying to do exactly the same as you

@epoberezkin
Copy link
Member

I am not sure what the issue is. If the issue is with Ajv v6.* please submit the full code sample to reproduce, what’s above is not enough to understand the problem. If it’s with Ajv v7.* it is because formats are now in a separate package ajv-formats that has to be added if you use them - seem release notes for v7.

@mattiekat
Copy link

I can confirm running into this error when migrating from v6 to v7 and it was solved by following the instructions here: https://ajv.js.org/docs/validation.html#formats

@sakthiiv
Copy link

sakthiiv commented Jan 5, 2021

Thanks for the awesome library.

For those who are using NodeJs require, the below snippet works

	const AJV = require('ajv').default;
	const addFormats = require('ajv-formats').default;

  	const ajv = new AJV();
  	addFormats(ajv);

@epoberezkin
Copy link
Member

closing here - thank you for the examples

@felixfbecker
Copy link

@epoberezkin is there a way to use string formats with TypeCompiler too? Especially since that's what @fastify/type-provider-typebox uses – currently it throws at runtime when format is used somewhere, even though on the type level it's accepted and enumerates all the formats from JSONSchema.

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

No branches or pull requests

7 participants