Subject: | Improper default value of additionalProperties |
Date: | Mon, 30 Apr 2012 11:06:24 +0200 |
To: | bug-JSON-Schema [...] rt.cpan.org |
From: | Piotr Piatkowski <pp [...] idea7.pl> |
I think there's a bug when no additionalProperties is defined for schema,
here's sample code:
use Test::More tests => 2;
use JSON::Schema;
my $schema = {
type => 'object',
properties => {
x => { type => 'integer' },
},
};
my $doc = {
foo => 123,
};
my $res = JSON::Schema->new( $schema )->validate( $doc );
ok( $res, "Object with extra property is valid" ) or diag( join( "\n",
$res->errors ) );
$schema->{additionalProperties} = {};
my $res2 = JSON::Schema->new( $schema )->validate( $doc );
ok( $res2, "Same with added empty additionalProperties" ) or diag( join(
"\n", $res2->errors ) );
And the output is:
1..2
not ok 1 - Object with extra property is valid
# Failed test 'Object with extra property is valid'
# at ./bug line 18.
# $0: The property foo is not defined in the schema and the schema does not
allow additional properties
ok 2 - Same with added empty additionalProperties
# Looks like you failed 1 test of 2.
I think this is a bug, as RFC draft clearly states:
5.4 <http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.4>.
additionalProperties [...] The default value is an empty schema
which allows any
value for additional properties.
This makes a problem with using "extends" attribute, as you need to provide
empty additionalProperties to both base and extended schema.
--
Piotr PiÄ…tkowski, idea7.pl