schema and $ref that are not resolved : JsonValidationFailureException: no match in schema

73 views
Skip to first unread message

Sebastien Dionne

unread,
Jan 31, 2012, 7:19:29 PM1/31/12
to JSON Schema
Hello. I'm playing with the json validator for few days, and I'm
stuck when I try to validate a schema that use $ref.

My Unittest failed when I try to validate : "logType".

@Test
public void testLogType() throws JsonValidationFailureException
{
testOne("logType");
}

if I validate all the others structure it passed fine. What I'm
missing here ?


Here the error that I have in my console :

org.eel.kitchen.jsonschema.main.JsonValidationFailureException: no
match in schema for path #/log/browserType
at
org.eel.kitchen.jsonschema.main.SchemaProvider.atPoint(SchemaProvider.java:
138)
at
org.eel.kitchen.jsonschema.main.ValidationContext.getValidator(ValidationContext.java:
254)
at
org.eel.kitchen.jsonschema.keyword.common.RefKeywordValidator.validate(RefKeywordValidator.java:
118)
at
org.eel.kitchen.jsonschema.container.ContainerValidator.validate(ContainerValidator.java:
74)
at
org.eel.kitchen.jsonschema.container.ObjectValidator.validateChildren(ObjectValidator.java:
66)
at
org.eel.kitchen.jsonschema.container.ContainerValidator.validate(ContainerValidator.java:
79)

If I change #/log/... And use directly the id.

I obtain : illegalArgumentException : invalid URI :.... URL is not
absolute...

here my SCHEMA

{
"logType": {
"id": "logType",
"description": "HTTP Archive structure.",
"type": "object",
"properties": {
"log": {
"type": "object",
"properties": {
"version": {"type": "string"},
"creator": {"$ref": "#/log/creatorType"},
"browser": {"$ref": "#/log/browserType"},
"pages": {"type": "array", "required": false,
"items": {"$ref": "#/log/pageType"}},
"entries": {"type": "array", "items": {"$ref": "#/
log/entryType"}},
"comment": {"type": "string", "required":
false}
}
}
}
},
"creatorType": {
"id": "creatorType",
"description": "Name and version info of the log creator
app.",
"type": "object",
"properties": {
"name": {"type": "string"},
"version": {"type": "string"},
"comment": {"type": "string", "required": false}
}
},
"browserType": {
"id": "browserType",
"description": "Name and version info of used browser.",
"type": "object",
"required": false,
"properties": {
"name": {"type": "string"},
"version": {"type": "string"},
"comment": {"type": "string", "required": false}
}
},
"pageType": {
"id": "pageType",
"description": "Exported web page",
"required": false,
"properties": {
"startedDateTime": {"type": "string", "format": "date-
time", "pattern": "dateTimePattern"},
"id": {"type": "string", "unique": true},
"title": {"type": "string"},
"pageTimings": {"$ref": "pageTimingsType"},
"comment": {"type": "string", "required": false}
}
},
"pageTimingsType": {
"id": "pageTimingsType",
"description": "Timing info about page load",
"properties": {
"onContentLoad": {"type": "number", "required": false,
"min": -1},
"onLoad": {"type": "number", "required": false, "min":
-1},
"comment": {"type": "string", "required": false}
}
},
"entryType": {
"id": "entryType",
"description": "Request and Response related info",
"required": false,
"properties": {
"pageref": {"type": "string", "required": false},
"startedDateTime": {"type": "string", "format": "date-
time", "pattern": "dateTimePattern"},
"time": {"type": "integer", "min": 0},
"request" : {"$ref": "requestType"},
"response" : {"$ref": "responseType"},
"cache" : {"$ref": "cacheType"},
"timings" : {"$ref": "timingsType"},
"serverIPAddress" : {"type": "string", "required":
false},
"connection" : {"type": "string", "required": false},
"comment": {"type": "string", "required": false}
}
},
"requestType": {
"id": "requestType",
"description": "Monitored request",
"properties": {
"method": {"type": "string"},
"url": {"type": "string"},
"httpVersion": {"type" : "string"},
"cookies" : {"type": "array", "items": {"$ref":
"cookieType"}},
"headers" : {"type": "array", "items": {"$ref":
"recordType"}},
"queryString" : {"type": "array", "items": {"$ref":
"recordType"}},
"postData" : {"$ref": "postDataType"},
"headersSize" : {"type": "integer"},
"bodySize" : {"type": "integer"},
"comment": {"type": "string", "required": false}
}
},
"recordType": {
"id": "recordType",
"description": "Helper name-value pair structure.",
"properties": {
"name": {"type": "string"},
"value": {"type": "string"},
"comment": {"type": "string", "required": false}
}
},
"responseType": {
"id": "responseType",
"description": "Monitored Response.",
"properties": {
"status": {"type": "integer"},
"statusText": {"type": "string"},
"httpVersion": {"type": "string"},
"cookies" : {"type": "array", "items": {"$ref":
"cookieType"}},
"headers" : {"type": "array", "items": {"$ref":
"recordType"}},
"content" : {"$ref": "contentType"},
"redirectURL" : {"type": "string"},
"headersSize" : {"type": "integer"},
"bodySize" : {"type": "integer"},
"comment": {"type": "string", "required": false}
}
},
"cookieType": {
"id": "cookieType",
"description": "Cookie description.",
"properties": {
"name": {"type": "string"},
"value": {"type": "string"},
"path": {"type": "string", "required": false},
"domain" : {"type": "string", "required": false},
"expires" : {"type": "string", "required": false},
"httpOnly" : {"type": "boolean", "required": false},
"secure" : {"type": "boolean", "required": false},
"comment": {"type": "string", "required": false}
}
},
"postDataType": {
"id": "postDataType",
"description": "Posted data info.",
"required": false,
"properties": {
"mimeType": {"type": "string"},
"text": {"type": "string", "required": false},
"params": {
"type": "array",
"required": false,
"properties": {
"name": {"type": "string"},
"value": {"type": "string", "required": false},
"fileName": {"type": "string", "required":
false},
"contentType": {"type": "string", "required":
false},
"comment": {"type": "string", "required":
false}
}
},
"comment": {"type": "string", "required": false}
}
},
"contentType": {
"id": "contentType",
"description": "Response content",
"properties": {
"size": {"type": "integer"},
"compression": {"type": "integer", "required": false},
"mimeType": {"type": "string"},
"text": {"type": "string", "required": false},
"encoding": {"type": "string", "required": false},
"comment": {"type": "string", "required": false}
}
},
"cacheType": {
"id": "cacheType",
"description": "Info about a response coming from the
cache.",
"properties": {
"beforeRequest": {"$ref": "cacheEntryType"},
"afterRequest": {"$ref": "cacheEntryType"},
"comment": {"type": "string", "required": false}
}
},
"cacheEntryType": {
"id": "cacheEntryType",
"required": false,
"description": "Info about cache entry.",
"properties": {
"expires": {"type": "string", "required": false},
"lastAccess": {"type": "string"},
"eTag": {"type": "string"},
"hitCount": {"type": "integer"},
"comment": {"type": "string", "required": false}
}
},
"timingsType": {
"id": "timingsType",
"description": "Info about request-response timing.",
"properties": {
"dns": {"type": "integer", "required": false, "min":
-1},
"connect": {"type": "integer", "required": false, "min":
-1},
"blocked": {"type": "integer", "required": false, "min":
-1},
"send": {"type": "integer", "min": -1},
"wait": {"type": "integer", "min": -1},
"receive": {"type": "integer", "min": -1},
"ssl": {"type": "integer", "required": false, "min":
-1},
"comment": {"type": "string", "required": false}
}
}
}


HERE A SUBSET OF DATA

{
"log": {
"version": "1.1",
"creator": {
"name": "Firebug",
"version": "1.8"
},
"browser": {
"name": "Firefox",
"version": "8.0"
}
}
}

Francis Galiegue

unread,
Feb 1, 2012, 4:08:47 AM2/1/12
to json-...@googlegroups.com
On Wed, Feb 1, 2012 at 01:19, Sebastien Dionne
<sebastie...@gmail.com> wrote:
> Hello.  I'm playing with the json validator for few days, and I'm
> stuck when I try to validate a schema that use $ref.
>
> My Unittest failed when I try to validate : "logType".
>
> @Test
>       public void testLogType() throws JsonValidationFailureException
> {
>               testOne("logType");
>       }
>
> if I validate all the others structure it passed fine.  What I'm
> missing here ?
>

(this is my implementation)

This is a bug or not, I don't know, and a limitation for sure.

First: as to "id", the spec is unclear. Here, what happens is that the
schema does NOT have an "id" per se. But all inner schemas have an
"id".

The schema starts at the first {, not the inner one, and refs are
calculated from there. As such, the JSON Pointer to subschemas are:

#/browserType
#/cookieType
etc etc

As to the limitation:

[...]


>
> If I change #/log/...  And use directly the id.
>
> I obtain : illegalArgumentException : invalid URI :.... URL is not
> absolute...
>

this is on purpose: if your ID is "#log" for your schema, how do you
address anything in it using JSON Pointer? You can't...

This needs clarification from the spec authors, and my implementation
probably needs fixing on that point. But I maintain that allowing any
URI as a schema ID, _including fragment-only URIs_, is a bug.


--
Francis Galiegue, fgal...@gmail.com
"It seems obvious [...] that at least some 'business intelligence'
tools invest so much intelligence on the business side that they have
nothing left for generating SQL queries" (Stéphane Faroult, in "The
Art of SQL", ISBN 0-596-00894-5)

Francis Galiegue

unread,
Feb 1, 2012, 4:12:30 AM2/1/12
to json-...@googlegroups.com
What's more, there are a couple problems with your schema:

- there is no "unique" keyword;
- it is "minimum", not "min";
- "pattern" takes a regex as an argument -- you have "pattern":
"dateTimePattern", this means the corresponding entry must match regex
"dateTimePattern".

Francis Galiegue

unread,
Feb 1, 2012, 4:47:05 AM2/1/12
to json-...@googlegroups.com
On Wed, Feb 1, 2012 at 10:12, Francis Galiegue <fgal...@gmail.com> wrote:
> What's more, there are a couple problems with your schema:
>
> - there is no "unique" keyword;
> - it is "minimum", not "min";
> - "pattern" takes a regex as an argument -- you have "pattern":
> "dateTimePattern", this means the corresponding entry must match regex
> "dateTimePattern".
>

Can you try and see here:
https://github.com/fge/json-schema-validator/tree/sdionne

It contains a "fixed" version of your schema (the outer "properties"
was missing as well) and sample data: the schema validates, so does
the data.

Sebastien Dionne

unread,
Feb 1, 2012, 9:05:17 AM2/1/12
to JSON Schema
thanks a lot. I took the schema of a framework HAR Viewer and fixed
so error, but I didn't though it was that bad. Maybe from a old
draft ? But doesn't matter now. I'll start from yours.


Bon.. on retourne coder :)

merci

On 1 fév, 04:47, Francis Galiegue <fgalie...@gmail.com> wrote:
> On Wed, Feb 1, 2012 at 10:12, Francis Galiegue <fgalie...@gmail.com> wrote:
> > What's more, there are a couple problems with your schema:
>
> > - there is no "unique" keyword;
> > - it is "minimum", not "min";
> > - "pattern" takes a regex as an argument -- you have "pattern":
> > "dateTimePattern", this means the corresponding entry must match regex
> > "dateTimePattern".
>
> Can you try and see here:https://github.com/fge/json-schema-validator/tree/sdionne
>
> It contains a "fixed" version of your schema (the outer "properties"
> was missing as well) and sample data: the schema validates, so does
> the data.
>
> --
> Francis Galiegue, fgalie...@gmail.com
Reply all
Reply to author
Forward
0 new messages