Skip to content

warning: format attribute "date" not supported #103

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

Closed
hminds-ritesh opened this issue May 28, 2014 · 9 comments
Closed

warning: format attribute "date" not supported #103

hminds-ritesh opened this issue May 28, 2014 · 9 comments

Comments

@hminds-ritesh
Copy link

Hi,

I have a JSON schema which has a property "BIRTH_DATE" with format as "date".

"BIRTH_DATE" : {
"description" : "BIRTH DATE",
"format" : "date",
"type" : "string"
},

Whenever I try to validate a json payload after this schema, the validator succeeds but shows up a warning:

warning: format attribute "date" not supported
level: "warning"
schema: {"loadingURI":"#","pointer":"/definitions/MemberDemographicJsSchema/properties/BIRTH_DATE"}
domain: "validation"
keyword: "format"
attribute: "date"

Am I doing anything wrong here? Or json validator does not support date format? If later, then how do I validate the date?

Regards,
Ritesh

@fge
Copy link
Collaborator

fge commented May 29, 2014

Hello,

This is a poor choice on my part when writing draft v4; of all the date/time attributes, only date-time is supported; date and time were pulled out. They will be back in draft v5 however.

So, this message is normal. However, you can add them back programmatically:

final Library library = DraftV4Library.get().thaw()
    .addFormatAttribute("date", DateAttribute.getInstance())
    .freeze();

final ValidationConfiguration cfg = ValidationConfiguration.newBuilder()
    .setDefaultLibrary("http://some.site/myschema#", library).freeze();

final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder()
    .setValidationConfiguration(cfg).freeze();

You can then build schemas from this factory: they will support this format attribute.

@hminds-ritesh
Copy link
Author

Hi,

I still see the same warning after adding the code that you mentioned.
Not sure if I am doing anything wrong.

@fge
Copy link
Collaborator

fge commented Jun 3, 2014

Can you post your full code?

@hminds-ritesh
Copy link
Author

Apologizes for the late response.

Here is my code and I think there is something wrong with the way I am adding the default library. I copied draft4 schema in my local drive and referring the same (in the below code)

public static void main (String[] args) throws IOException {
    final Library library = DraftV4Library.get().thaw()
        .addFormatAttribute("date", DateAttribute.getInstance())
        .freeze();

    final ValidationConfiguration cfg = ValidationConfiguration
        .newBuilder()
        .setDefaultLibrary("file:///D:/work/ZeOmega/zeomega_wso2/schema.json", library)
        .freeze();

    final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder()
        .setValidationConfiguration(cfg).freeze();

    try {
        JsonNode json = Utils.loadResource("D:/work/ZeOmega/zeomega_wso2/jiva_member.json");
        JsonNode jsonSchema = Utils.loadResource("D:/work/ZeOmega/zeomega_wso2/jiva_member_post_schema.json");
        JsonSchema schema = factory.getJsonSchema(jsonSchema);
        ProcessingReport report = schema.validate(json);
        System.out.println(report);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

@hminds-ritesh
Copy link
Author

Hi,

Any update on this?

@jeegarmaru
Copy link

I got this to work. I needed to change the value of the $schema field in the JSON schema file to not be "http://json-schema.org/draft-04/schema#" or any of the supported schemas.

Change it to the same value as what you use in the setDefaultLibrary (I used "http://mycompany.com/myschema#").

@hminds-ritesh
Copy link
Author

Thanks Jeegar. I shall try this.

Regards,

Ritesh

From: Jeegar Maru [mailto:[email protected]]
Sent: Thursday, October 02, 2014 7:58 PM
To: fge/json-schema-validator
Cc: hminds-ritesh
Subject: Re: [json-schema-validator] warning: format attribute "date" not supported (#103)

I got this to work. I needed to change the value of the $schema field in the JSON schema file to not be "http://json-schema.org/draft-04/schema# http://json-schema.org/draft-04/schema " or any of the supported schemas.

Change it to the same value as what you use in the setDefaultLibrary (I used "http://mycompany.com/myschema# http://mycompany.com/myschema ").


Reply to this email directly or view it on GitHub #103 (comment) . https://github.com/notifications/beacon/7579897__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNzg3OTI3NCwiZGF0YSI6eyJpZCI6MzMyNjA5MTd9fQ==--13f5f57c7815691e66d68dae48429f52e7d54a17.gif

@fge
Copy link
Collaborator

fge commented Oct 17, 2014

(sorry for the long delay)

What @jeegarmaru said; see also the examples as to how to modify your library to add a format attribute.

@girish-pisharath
Copy link

Hi @fge this is still giving me the same error even after changing the $schema.Please help.

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

4 participants