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.63k stars 399 forks source link

can't validate a doc against the schema containing "const" #352

Open gneginskiy opened 4 years ago

gneginskiy commented 4 years ago

Hi guys.

Due to some reason the library cannot validate the sample json against the schema using const values by the link: https://www.jsonschemavalidator.net/s/myuH8UPz

expected: validation is passed actual: validation fails

however, if I replace all the const s with a single string enum, everything works as expected

e.g. "type": {"const": "backButton"}, with "type": {"type": "string", "enum": ["backButton"]},

version used: 2.2.14

sample code:

            JsonNode contextNode = JsonLoader.fromString(StringEscapeUtils.unescapeJava(jsonDocument));
            JsonValidator validator = JsonSchemaFactory.byDefault().getValidator();
            ProcessingReport report = validator.validate(jsonSchema, contextNode); //contains errors

can you please have a look

Thanks, Grigory

Relequestual commented 3 years ago

This library only supports draft 3 and 4. const was added later. You'll need to pick another library.