--
You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To post to this group, send email to json-...@googlegroups.com.
To unsubscribe from this group, send email to json-schema...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-schema?hl=en.
--
Thanks,
Kris
> If a single type is defined it would still essentially default to required.
Is this rule necessary?
In some cases, empty message bodies are OK.
Why not require "required" to be explicitly specified in all cases (even with a single item)?
-- Thanks, Kris
We won't be binding a default for required properties; in fact the
definition of a required property will be "a property without a
default". If you meant that binding for optional properties might not
always be possible or desirable (e.g. if null has different
semantics), I think the reference mechanism should make it possible to
define an "undefined" value that is bound as default. I mean something
like this (hope I get the $ref syntax right):
{
"properties": {
"undefined": {"default": {}},
"foo": {},
"bar": {"default": null}
"baz": {"default": {"$ref": "#undefined.default"}}
}
}
Here "foo" is required while "bar", "baz" and "undefined" are optional
(actually "undefined" should not be passed but I'm not sure if JSON
schema allows "local variables") . "bar"'s value will be null if
omitted. For "baz" though, its default is the object referenced by
undefined.default. The client code can check if "baz" was omitted
simply by:
if (data.baz === data.undefined) { ...}
The value for "undefined" doesn't have to be disposable like this, it
may be a persistent entity referenced externally. This is a known
pattern in Python that has a None (null) object but not undefined. If
None happens to be a semantically valid value, a fresh object can be
created and used as a sentinel:
_undefined = object()
def foo(x=_undefined):
if x is _undefined:
...
Regards,
George
On 6/4/2010 5:00 PM, Gary Court wrote:
> [snip]
> ***Solutions***
>
> There are three solutions to correcting this behavior:
>
> 1. Change the default empty schema to {"optional":true}
> 2. Make the default value of "optional" true
> 3. Rename "optional" to "required"
>
> First off, #1 is out of the picture for obvious reasons. Solution #2
> would work, but is against the idea that all boolean properties
> default to false.
>
> Solution #3 makes the most sense as it defaults to false and places no
> restrictions on the empty schema, allowing the empty set to contain
> every possible JSON value. Optionally, validators can examine a JSON
> schema for this attribute to see if it is using a revision 3 schema.
I had suggested option #4 of adding "undefined" as a type, but I tend to
think option #3 might actually be more sensible. Any objections to
changing to option #3 for rev 3 of the draft?
--
Thanks,
Kris