Skip Menu |

This queue is for tickets about the JSON-Schema CPAN distribution.

Report information
The Basics
Id: 76892
Status: resolved
Priority: 0/
Queue: JSON-Schema

People
Owner: perl [...] toby.ink
Requestors: pp [...] idea7.pl
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
Fixed in the repository - I'll try to push out a new release in the next few days. https://bitbucket.org/tobyink/p5-json-schema