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 in extended schemas #7
Comments
(what version?) That sounds strange, for one reason at least: http://json-schema.org/draft-03/schema# does not exist (404). If I adapt the schema like this: {
"extends": {
"$ref": "#/core"
},
"properties": {
"indexed": {
"type": "boolean",
"default": false
}
},
"core": {
"$schema" : "http://json-schema.org/draft-03/schema#",
"id" : "http://json-schema.org/draft-03/schema#",
"type" : "object",
"properties" : {
"type" : {
"type" : ["string", "array"],
"items" : {
"type" : ["string", { "$ref" : "#" } ]
},
"uniqueItems" : true,
"default" : "any"
},
"properties" : {
"type" : "object",
"additionalProperties" : { "$ref" : "#" },
"default" : {}
},
"patternProperties" : {
"type" : "object",
"additionalProperties" : { "$ref" : "#" },
"default" : {}
},
"additionalProperties" : {
"type" : [ { "$ref" : "#" }, "boolean" ],
"default" : {}
},
"items" : {
"type" : [ { "$ref" : "#" }, "array" ],
"items" : {
"$ref" : "#"
},
"default" : {}
},
"additionalItems" : {
"type" : [ { "$ref" : "#" }, "boolean" ],
"default" : {}
},
"required" : {
"type" : "boolean",
"default" : false
},
"dependencies" : {
"type" : "object",
"additionalProperties" : {
"type" : ["string", "array", { "$ref" : "#" } ],
"items" : { "type" : "string" }
},
"default" : {}
},
"minimum" : {
"type" : "number"
},
"maximum" : {
"type" : "number"
},
"exclusiveMinimum" : {
"type" : "boolean",
"default" : false
},
"exclusiveMaximum" : {
"type" : "boolean",
"default" : false
},
"minItems" : {
"type" : "integer",
"minimum" : 0,
"default" : 0
},
"maxItems" : {
"type" : "integer",
"minimum" : 0
},
"uniqueItems" : {
"type" : "boolean",
"default" : false
},
"pattern" : {
"type" : "string",
"format" : "regex"
},
"minLength" : {
"type" : "integer",
"minimum" : 0,
"default" : 0
},
"maxLength" : {
"type" : "integer"
},
"enum" : {
"type" : "array",
"minItems" : 1,
"uniqueItems" : true
},
"default" : {
"type" : "any"
},
"title" : {
"type" : "string"
},
"description" : {
"type" : "string"
},
"format" : {
"type" : "string"
},
"divisibleBy" : {
"type" : "number",
"minimum" : 0,
"exclusiveMinimum" : true,
"default" : 1
},
"disallow" : {
"type" : ["string", "array"],
"items" : {
"type" : ["string", { "$ref" : "#" } ]
},
"uniqueItems" : true
},
"extends" : {
"type" : [ { "$ref" : "#" }, "array" ],
"items" : {
"$ref" : "#"
},
"default" : {}
},
"id" : {
"type" : "string",
"format" : "uri"
},
"$ref" : {
"type" : "string",
"format" : "uri"
},
"$schema" : {
"type" : "string",
"format" : "uri"
}
},
"dependencies" : {
"exclusiveMinimum" : "minimum",
"exclusiveMaximum" : "maximum"
},
"default" : {}
}
} and run this simple main program: public static void main(final String... args)
throws IOException
{
final JsonNode schemaNode = JsonLoader.fromResource("/t.json");
final JsonNode data = JsonLoader.fromResource("/t2.json");
final JsonSchema schema = JsonSchema.fromNode(schemaNode);
final ValidationReport report = new ValidationReport();
schema.validate(report, data);
for (final String msg: report.getMessages())
System.out.println(msg);
System.exit(0);
} then the output is as expected:
Care to show your code? |
The version that I am using is 0.5.0 beta 3. schema1.json {
"extends":{"$ref" : "http://json-schema.org/draft-03/schema#"},
"properties":{
"indexed":{"type": "boolean", "default":false}
}
} schema2.json {
"type" : "object",
"properties" : {
"from" : { "type" : "string", "required":true, "indexed":111 }
}
} My test program is JsonNode draftv3 = JsonLoader.fromFile(new File("schema-draftv3.json"));
JsonNode schema1 = JsonLoader.fromFile(new File("schema1.json"));
JsonNode schema2 = JsonLoader.fromFile(new File("schema2.json"));
JsonSchema schema = JsonSchema.fromNode(draftv3);
schema.validate(valReport, schema1);
for (String msg : valReport.getMessages())
System.out.println(msg);
JsonSchema temp1schema = JsonSchema.fromNode(schema1);
temp1schema.validate(valReport, schema2);
for (String msg : valReport.getMessages())
System.out.println(msg); This the test that I was performed. Maybe I am making something wrong. |
About your question: the JsonReference class maitains a map of schemas with URIs if an id is found, which is program-wide. Which means, as schema-draftv3.json has "http://json-schema.org/draft-03/schema#" in "id", the value will be cached, and it will not be looked up over the net. That's probably a misfeature, I don't know. This part of the implementation is clearly not very nice. But that explains why you don't see an error. As to the behaviour you see, I'll try and reproduce it. |
Ok, thanks for your help. |
OK, I have reproduced the bug... Fixing it will not be easy :/ The implementation suffers a design problem AFAICS. This is a first impression, unfortunately I don't have the required time to debug the issue. I'll update tonight. |
"I don't have the required time to debug the issue" I meant, I don't have the time at the moment. $ref is a bitch :/ |
OK, I have found the source of the bug, and it is quite serious -- fixing it will require refactoring... JsonSchema as it is cannot handle this case. I make this a top priority item. Thanks a lot for the reproducer. I'll keep you informed. |
Quite serious, and I don't even understand the whole picture leading to this bug, but it is clearly there.
Ok, if you need any help please fell free to ask. |
One question: do you use maven to grab artifacts or do you git clone? If I need to have a fix tested, this will make a difference... |
I use git clone. |
There is really no other word for it. Maven's unit test plugin (I don't know what its name is yet, or even whether more than one such plugin exists) will not even _run_ a damn test if the _class_ doesn't have Test in its name. Rename the class to work around this f*cking brain damaged reasoning. I use TestNG, damnit, and TestNG has annotations to tell whether a class, or method, is a test. Maven, this is the 21st century, wake up! I'm sorry, Maven, but you're fired. You are just too stupid for my tastes. It's just that I don't know enough about gradle yet to switch to it.
This will allow to concentrate for now on issue #7 problems, but is an indication that the whole registry/container/node mechanism needs some rework.
This method is going to become obsolete. This means, though, that we don't have a performance test anymore, nor the test for issue #7.
A redesign is in the pipe, which means these tests will need to be modified.
With all these changes, the context is now properly transferred, which means "extends" actually works.
OK, the bug is fixed, but the API needs refining before I put it in the wild. In the meanwhile, you can try and see about the new API in Issue7Test. It is not final yet. |
Fine. I will check it. |
The problem is solved. |
Hi. I was upgrading for latest version (yes, I was using a very older version..., 0.5.x) and when testing this issue again I realise that it is reproducible again. Maybe I am doing something wrong since I only adapt the old test to the new version. |
OK, I admit I am too lazy to be reading this thread from the start again, so could you please post:
|
You wrote a Test case (Issue7TestCase that can be found in commit 7f3b82a) that summarises this issue. The test case is: package org.eel.kitchen; import com.fasterxml.jackson.databind.JsonNode; import java.io.IOException; import static org.testng.Assert.*; public final class Issue7Test
} The schema1.json file is { The schema2.json is { The problem is that on schema2, the "indexed" property has an incorrect value 111, instead of true or false. |
The code has changed quite a lot since 0.5.x days, the test case you point to cannot work anymore. Can you provide a more up to date example? For instance, based on one of the examples in the |
I adapt this test case for the version 1.4.1. Where is the code. Is based on the Examples and is not a junit case. import java.io.File; import com.fasterxml.jackson.databind.JsonNode; public class JsonSchemaTest {
} |
OK, how does that fail and when? Can you give the full output? |
The problem is that it should fail, but the schema2 is validated correctly.
|
OK, I think I am starting to get the whole picture -- and why it does not work. Before I give a detailed answer, can you confirm one thing: you are trying to validate a schema, and not an instance? |
Yes, I am trying to validate a schema. Sorry, in the previous comment I incorrectly use the term 'instance' to name the schema2. |
Well, I thought I had figured out why you got this error. Now, after having debugged through a test case I have written (which essentially matches yours), I see my first thought was wrong. There is a fundamentally flawed logic somewhere in my implementation and I need to figure it out :/ Since this issue is rather old and not relevant to new code anymore, would you mind re-opening a new issue with sample code? I have only checked HEAD at the moment, I am pretty sure that 1.4.x is affected and I surmise 1.2.x is affected as well. But I need to "start anew" here. This buggers me :/ |
I have a clue... I think that the validation context is not being created correctly when you have schema that is an extension of other schema. |
I was performing some tests of json-schema-validator and found the following behavior.
I defined the following schema
{
"extends":{"$ref" : "http://json-schema.org/draft-03/schema#"},
"properties":{
"indexed":{"type": "boolean", "default":false}
}
}
and after that I try the validate the next schema.
{
"type" : "object",
"properties" : {
"from" : { "type" : "string", "indexed":111 }
}
}
It should give an error, since Indexed is a boolean property and not a integer. And it don't.
The schema is validated and is considered correct.
The text was updated successfully, but these errors were encountered: