Comments (24)
(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:
#/properties/from/indexed: instance does not match any allowed primitive type
Care to show your code?
from json-schema-validator.
The version that I am using is 0.5.0 beta 3.
Then, about the code. I have three files, schema-draftv3.json, schema1.json and schema2.json.
The first file has the schema drat v3 (your #/core) and other files have the following contents
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.
One question? If http://json-schema.org/draft-03/schema was not found, then that error should be reported, isn't it?
from json-schema-validator.
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.
from json-schema-validator.
Ok, thanks for your help.
from json-schema-validator.
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.
from json-schema-validator.
"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 :/
from json-schema-validator.
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.
from json-schema-validator.
Ok, if you need any help please fell free to ask.
from json-schema-validator.
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...
from json-schema-validator.
I use git clone.
from json-schema-validator.
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.
from json-schema-validator.
Fine. I will check it.
from json-schema-validator.
The problem is solved.
from json-schema-validator.
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.
from json-schema-validator.
OK, I admit I am too lazy to be reading this thread from the start again, so could you please post:
- the version you are currently using,
- the schema you use,
- an instance which validates successfully but you think should not validate successfully, and
- an instance which does not validate successfully but you think it should?
from json-schema-validator.
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 org.eel.kitchen.jsonschema.ValidationContext;
import org.eel.kitchen.jsonschema.schema.JsonSchema;
import org.eel.kitchen.jsonschema.schema.JsonSchemaFactory;
import org.eel.kitchen.jsonschema.util.JsonLoader;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.IOException;
import static org.testng.Assert.*;
public final class Issue7Test
{
private JsonNode draftv3, schema1, schema2;
@BeforeClass
public void setUp()
throws IOException
{
draftv3 = JsonLoader.fromResource("/schema-draftv3.json");
schema1 = JsonLoader.fromResource("/schema1.json");
schema2 = JsonLoader.fromResource("/schema2.json");
}
@Test
public void testIssue7()
{
final JsonSchemaFactory factory = new JsonSchemaFactory();
ValidationContext context;
JsonSchema schema;
context = factory.newContext();
schema = factory.create(draftv3);
schema.validate(context, schema1);
assertTrue(context.isSuccess());
context = factory.newContext();
schema = factory.create(schema1);
schema.validate(context, schema2);
assertFalse(context.isSuccess());
}
}
The schema1.json file is
{
"extends":{
"$ref" : "http://json-schema.org/draft-03/schema#"
},
"properties":{
"indexed":{
"type": "boolean",
"default":false
}
}
}
The schema2.json is
{
"type" : "object",
"properties" : {
"from" : {
"type" : "string",
"required":true,
"indexed":111
}
}
}
The problem is that on schema2, the "indexed" property has an incorrect value 111, instead of true or false.
The schema is validated correctly, but should give an error.
I was using 0.5.3 beta X and now I am using 1.4.1.
from json-schema-validator.
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 org.eel.kitchen.jsonschema.examples
package?
from json-schema-validator.
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 java.io.IOException;
import com.fasterxml.jackson.databind.JsonNode;
import org.eel.kitchen.jsonschema.main.JsonSchema;
import org.eel.kitchen.jsonschema.main.JsonSchemaFactory;
import org.eel.kitchen.jsonschema.report.ValidationReport;
import org.eel.kitchen.jsonschema.util.JsonLoader;
public class JsonSchemaTest {
public static void main(String[] args) {
try {
JsonNode draftv3 = JsonLoader.fromResource("/draftv3/schema");
JsonNode schema1 = JsonLoader.fromFile(new File("schema1.json"));
JsonNode schema2 = JsonLoader.fromFile(new File("schema2.json"));
ValidationReport report;
JsonSchemaFactory factory = JsonSchemaFactory.defaultFactory();
JsonSchema draftv3Schema = factory.fromSchema(draftv3);
report = draftv3Schema.validate(schema1);
if (!report.isSuccess())
System.out.println("Schema1: " + report.asJsonObject());
JsonSchema schema1Schema = factory.fromSchema(schema1);
report = schema1Schema.validate(schema2);
if (!report.isSuccess())
System.out.println("Schema2: " + report.asJsonObject());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
from json-schema-validator.
OK, how does that fail and when? Can you give the full output?
from json-schema-validator.
The problem is that it should fail, but the schema2 is validated correctly.
Basically the all pictures is more less as follows:
- Define a schema1 that is an extension from draftv3 and that add a new property, 'indexed', that is declared as boolean.
- Define an instance of schema1, schema2. The value for property 'indexed' is 111.
- The validator should give an error, since for property 'indexed' only a boolean value should be allowed.
from json-schema-validator.
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?
from json-schema-validator.
Yes, I am trying to validate a schema. Sorry, in the previous comment I incorrectly use the term 'instance' to name the schema2.
from json-schema-validator.
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 :/
from json-schema-validator.
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.
And I will open an new issue.
from json-schema-validator.
Related Issues (20)
- Failed validation for no apparent reason?
- Getting java.util.concurrent.ExecutionException while validating
- Error when validating Json against a schema defining oneOf
- Are we planning on supporting draft-07 HOT 1
- Example code on README.md please plus links to examples in src
- Migrate from joda-time to java 8 time API HOT 2
- Improcess error hanling in getJsonSchema - never squash exceptions
- Android app crashes because schema (v4) cannot be found at runtime HOT 2
- Getting NPE when passing null to validate method.
- Has the functionality of the ResolvingSchemaWalker been replaced in more recent versions?
- Conflicting Transitive Dependency Versions for Guava and Jsr305
- Where is pom.xml ? I want to import this library to my local and customize it
- Not compatible with GraalVM
- NoSuchFieldError on signing
- When JSONObject contains JSONArray, JSONArray's object can not be validated
- draftv4/schema is different between json-schema-validator 2.2.14 and json-schema-core 1.2.14 HOT 2
- release new version HOT 2
- How can we get Error Message with the error path appended?
- Obtain JUST the message from a ValidationMessage?
- BUG: ECMA262 valid pattern throws an exception
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-schema-validator.