java-json-tools / json-schema-validator

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order
http://json-schema-validator.herokuapp.com/
Other
1.62k stars 399 forks source link

format attribute "date" not supported #286

Closed vidyac410 closed 5 years ago

vidyac410 commented 5 years ago

Hi, I have a JSON schema which has a property "InvoiceDate" of type "string" with format as "date". "InvoiceDate" : { "type" : "string", "format" : "date" } And I have a JSON payload as below: { "invoiceDate":"blah" } I am trying to validate the json payload against the above schema , the validator succeeds but shows up a warning:

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

Seems like the Json-schema-validator is not supporting 'date' format.

I tried solving the above issue by following the steps specified in the similar issue : https://github.com/java-json-tools/json-schema-validator/issues/103

This is what i gave in my code:

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

     final ValidationConfiguration cfg = ValidationConfiguration
                        .newBuilder()
                        .setDefaultLibrary("file:///Users/vidya/Desktop/DocSchema.json", library)
                        .freeze();

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

Apparantly this again is skipping the date validation , the the validator is succeeding and showing the warning. Am I doing anything wrong here? What value needs to be provided in the setDefaultLibrary? i tried providing my schema link ("file:///Users/vidya/Desktop/DocSchema.json"), and some random URL's as well. The validator keeps succeding.

vidyac410 commented 5 years ago

Working fine

jepoyoy commented 5 years ago

what did you do to make this work? Thanks!

vidyac410 commented 5 years ago

Hi @jepoyoy, I followed the steps as pointed out in issue : https://github.com/java-json-tools/json-schema-validator/issues/103#issuecomment-44518735