File: id-keyword-draft7.t

package info (click to toggle)
libjson-validator-perl 4.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 828 kB
  • sloc: perl: 2,816; makefile: 14
file content (48 lines) | stat: -rw-r--r-- 1,421 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use Mojo::Base -strict;
use JSON::Validator;
use Test::Mojo;
use Test::More;

my ($base_url, $jv, $t, @e);

use Mojolicious::Lite;
get '/person'           => 'person';
get '/invalid-relative' => 'invalid-relative';

$t  = Test::Mojo->new;
$jv = JSON::Validator->new(ua => $t->ua);

eval {
  $t->get_ok('/person.json')->status_is(200);
  $base_url = $t->tx->req->url->to_abs->path('/');
  $jv->load_and_validate_schema("${base_url}person.json", {schema => 'http://json-schema.org/draft-07/schema#'});
};
ok !$@, "${base_url}schema.json" or diag $@;
isa_ok $jv->schema, 'JSON::Validator::Schema::Draft7';

is $jv->{version}, 7, 'detected version from draft-07';
is $jv->schema->id,            'http://example.com/person.json',          'schema id';
is $jv->schema->moniker,       'draft07',                                 'moniker';
is $jv->schema->specification, 'http://json-schema.org/draft-07/schema#', 'schema specification';
is $jv->_id_key, '$id', 'detected id_key from draft-07';

eval { $jv->load_and_validate_schema("${base_url}invalid-relative.json") };
like $@, qr{cannot have a relative}, 'Root id cannot be relative' or diag $@;

done_testing;

__DATA__
@@ invalid-relative.json.ep
{"$id": "whatever"}
@@ person.json.ep
{
  "$id": "http://example.com/person.json",
  "definitions": {
    "Person": {
      "type": "object",
      "properties": {
        "firstName": { "type": "string" }
      }
    }
  }
}