Skip Menu |

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

Report information
The Basics
Id: 95923
Status: open
Priority: 0/
Queue: JSON-Schema

People
Owner: Nobody in particular
Requestors: NJFRANCK [...] cpan.org
Cc:
AdminCc:

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



Subject: keyword "required" not used like documented
According to the latest specification of JSON-Schema, one can require the existance of some keys like this: { "title": "Example Schema", "type": "object", "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "age": { "description": "Age in years", "type": "integer", "minimum": 0 } }, "required": ["firstName", "lastName"] } But this "required" is not supported in your module in this way. Your module does it like this: .. "lastName": { "type": "string", "required": 1 } .. Cf. http://json-schema.org/examples.html Are you using an older version of the specification? Doesn't matter if it is older. But I just need to know what version is supported, so I can document it. Thanks in advance
Hi, I wrote a simple patch to enable support of "required" keyword. I'm not sure completely if it's correct in all situations, but this is a start. Can you tell what should I do to get it merged? Do you see any problems? -- Best regards, Ruslan.
Subject: JSON-Schema-0.015-per-spec-required-check.patch
Only in JSON-Schema-0.015/: MYMETA.json Only in JSON-Schema-0.015/: MYMETA.yml Only in JSON-Schema-0.015/: Makefile Only in JSON-Schema-0.015/: blib diff -ur JSON-Schema-0.015/lib/JSON/Schema/Helper.pm JSON-Schema-0.015-my/lib/JSON/Schema/Helper.pm --- JSON-Schema-0.015/lib/JSON/Schema/Helper.pm 2014-07-30 20:01:29.000000000 +0400 +++ JSON-Schema-0.015-my/lib/JSON/Schema/Helper.pm 2012-12-14 12:09:05.000000000 +0400 @@ -276,11 +276,6 @@ { push @{$self->{errors}}, $self->checkObj($value, $path, $schema->{'properties'}, $schema->{'additionalProperties'}, $schema->{'patternProperties'}, $_changing); } - - if ( defined $schema->{'required'} && ref $value eq 'HASH' ) { - $addError->("does not have required property '$_'") - foreach grep !exists $value->{$_}, @{$schema->{'required'}} - } if ($schema->{'pattern'} and $self->jsMatchType('string', $value)) { Only in JSON-Schema-0.015/: pm_to_blib diff -ur JSON-Schema-0.015/t/03required.t JSON-Schema-0.015-my/t/03required.t --- JSON-Schema-0.015/t/03required.t 2014-07-30 20:04:47.000000000 +0400 +++ JSON-Schema-0.015-my/t/03required.t 2012-12-14 12:06:49.000000000 +0400 @@ -41,11 +41,6 @@ additionalProperties => {}, }); -my $schema5 = JSON::Schema->new({ - type => 'object', - required => ['mynumber'], -}); - my $data1 = { mynumber => 1 }; my $data2 = { mynumbre => 1 }; @@ -81,13 +76,5 @@ ok !$result, 'H' or map { diag "reason: $_" } $result->errors; -$result = $schema5->validate($data1); -ok $result, 'H' - or map { diag "reason: $_" } $result->errors; - -$result = $schema5->validate($data2); -ok !$result, 'H' - or map { diag "reason: $_" } $result->errors; - done_testing;
JSON::Schema supports an older version of the spec, circa 2012. Given how much the spec has changed over time, I'm not willing to play catch-up. Instead I want to wait until the JSON Schema people give some kind of indication that the spec is stable. Ideally, by finally publishing it as an IETF RFC. Once that happens, I'll rewrite JSON::Schema from scratch (but retain the current API for compatibility). In the mean time, I'm happy for somebody else to have co-maint of JSON::Schema for small updates like this, provided they agree to the overall plan that the current implementation will eventually be scrapped. If anybody wants to volunteer, let me know. Until then, I am marking this issue as stalled.
On Thu Sep 11 09:20:03 2014, TOBYINK wrote: Show quoted text
> If anybody wants to volunteer, let me know. Until then, I am marking > this issue as stalled.
I'm willing to volunteer (CPANID: RUZ) as otherwise my team will probably fork this module. -- Best regards, Ruslan.