meta schema validates nothing

117 views
Skip to first unread message

Vincent Potucek

unread,
Nov 23, 2017, 4:08:36 AM11/23/17
to JSON Schema
Hey guys,

I´m confused as the "Core/Validation meta-schema Used for schemas written for pure validation" does not require any props such an id and stuff like that.
Leading to the doc (http://json-schema.org/latest/json-schema-core.html#rfc.section.4.3.1) an empty object {} and even an boolean is a "valid" schema.
I absolutely don´t get this, so im asking here for explanation. I expected the meta schema to enforce some kind of schema and not accepting garbage like I mentioned above.

Thanks.

Ben Hutton (@Relequestual)

unread,
Nov 23, 2017, 4:20:54 AM11/23/17
to JSON Schema
Hi Vincent,

Think of every JSON Schema (validation) key word as an added constraint to your validation of your JSON document.

When you consider that fact, an empty schema simply means "no constaints".

This may seem a bit silly, but consider the following two possible situations:

1. JSON Schemas may be generated my other code, and as such, it's possible that a schema may be required, but the constaints required are none.

2. $ref may be used in combination with 1., so I may have a "message" schema which has no validation constraints, and I may have code which automatically creates a schema that references the "message" schema.


I've worked on JSON Schema on and off for a while now, but others may have additional insight and clearer use cases than the simple one I could think of off the top of my head.

Cheers
Ben

Henry Andrews

unread,
Nov 23, 2017, 10:59:38 AM11/23/17
to json-...@googlegroups.com
Hi Vincent,
  I'll add a bit to Ben's explanation, all of which is correct.

* The boolean schemas are trivial shortcuts that always validated (true) or always fail to validate (false).  They are most commonly used with keywords like "additionalProperties", which take a schema as a value.  But often you simply want to say that no additional properties are valid, and you use false in that case.  Or to explicitly say that all additional properties are valid, with any values, you use true.  A few drafts ago, we decided that the true and false schemas should be available everywhere instead of only for two specific keywords.  


* JSON Schema is extensible, so the meta-schema cannot fail in the presence of extensions.  If you want to use a more strict meta-schema to catch additional errors specific to your usage (let's say you always want to require a "type" field, for instance), then you can write your own meta-schema.  This is what I have often done- for testing internally, I'll use a strict meta-schema that enforces our team's style and finds additional bugs.  And then for publication, I'll use the standard meta-schema for compatibility.


JSON Schema is not like object-oriented programming.  In OOP an empty class allows nothing- there are no defined data members or functions.  In JSON Schema an empty schema allows everything, as there are no defined constraints.

thanks,
-henry


From: "Ben Hutton (@Relequestual)" <b...@sanger.ac.uk>
To: JSON Schema <json-...@googlegroups.com>
Sent: Thursday, November 23, 2017 1:20 AM
Subject: [json-schema] Re: meta schema validates nothing

Hi Vincent,

Think of every JSON Schema (validation) key word as an added constraint to your validation of your JSON document.

When you consider that fact, an empty schema simply means "no constaints".

This may seem a bit silly, but consider the following two possible situations:

1. JSON Schemas may be generated my other code, and as such, it's possible that a schema may be required, but the constaints required are none.

2. $ref may be used in combination with 1., so I may have a "message" schema which has no validation constraints, and I may have code which automatically creates a schema that references the "message" schema.


I've worked on JSON Schema on and off for a while now, but others may have additional insight and clearer use cases than the simple one I could think of off the top of my head.

Cheers
Ben

On Thursday, 23 November 2017 09:08:36 UTC, Vincent Potucek wrote:
Hey guys,

I´m confused as the "Core/Validation meta-schema Used for schemas written for pure validation" does not require any props such an id and stuff like that.
Leading to the doc (http://json-schema.org/ latest/json-schema-core.html# rfc.section.4.3.1) an empty object {} and even an boolean is a "valid" schema.
I absolutely don´t get this, so im asking here for explanation. I expected the meta schema to enforce some kind of schema and not accepting garbage like I mentioned above.

Thanks.
--
You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To unsubscribe from this group and stop receiving emails from it, send an email to json-schema...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages