-
Notifications
You must be signed in to change notification settings - Fork 331
Description
Hi, first of, thanks for all your work you put into this library.
What is the issue
Given this test, it seems that if I (e.g. accidentally) put a TextNode into a schema, this schema will validate anything (I tested integers and strings).
@Test
void testSchemaStringValidation() {
JsonNode schemaNode = new TextNode("false");
JsonSchema schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4).getSchema(schemaNode);
Set<ValidationMessage> errors = schema.validate(new IntNode(42));
assertTrue(errors.isEmpty(), "Schema should validate any string, but got errors: " + errors);
}
Why is this an issue?
I was accidentally not parsing a JSON string that I got from an API. I read the response JSON, but forgot to parse the JSON string given in one of its values. The result was that I spent hours diving into what is wrong with this schema (but not with others I got from another API), checking versions, wondering if $refs are the issue... until I saw in the debugger that my JsonNode was a TextNode instance and tried out if this had an effect. I think there is no clue on this in the API docs or so, but to be honest, while debugging this was not the kind of detail I was actively looking for. So, maybe I just did not see it.
What would I expect?
I would find it helpful if the library would only accept ObjectNode and maybe a variant with boolean nodes or so. Or it could throw a specialized error on validation, or an exception on schema creation. I think the minimum would be a note in the Javadoc, or make the note more present if it is already somewhere.
Available Workarounds
Well, make sure the JsonNode we generate a schema from is not a Textual node.