File: issue-103-one-of.t

package info (click to toggle)
libjson-validator-perl 5.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,160 kB
  • sloc: perl: 3,015; makefile: 14
file content (68 lines) | stat: -rw-r--r-- 1,869 bytes parent folder | download | duplicates (3)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use lib '.';
use t::Helper;

validate_ok {who_id => 'WHO', expire => '2018-01-01', amount => 1000, desc => 'foo'}, 'data://main/example.json',
  E('/sym', '/oneOf/0/allOf/0/allOf/0 Missing property.'), E('/template', '/oneOf/0/allOf/2 Missing property.'),
  E('/sym', '/oneOf/1/allOf/0 Missing property.'),         E('/',         '/oneOf/2 Expected string - got object.');

validate_ok {sym => 'a', expire => 'b', amount => 1, desc => 'foo', who_id => 'c', template => 'd'},
  'data://main/example.json', E('/', 'oneOf rules 0, 1 match.');

done_testing;

__DATA__
@@ example.json
{
  "oneOf": [
    {"$ref": "#/definitions/template_1"},
    {"$ref": "#/definitions/bar_header"},
    {"type": "string"}
  ],
  "definitions": {
    "hwho":{
      "required": [ "who_id" ],
      "properties": {
        "who_id": { "type": "string" },
        "sub_who_id": { "type": "string" }
      }
    },
    "header": {
      "required": [ "sym", "expire" ],
      "properties": {
        "sym": { "type": "string" },
        "expire": { "type": "string" }
      }
    },
    "foo_header": {
      "allOf": [
        { "$ref": "#/definitions/header" },
        {
          "required": [ "amount", "desc" ],
          "properties": {
            "amount": { "type": "integer" },
            "desc": { "enum": [ "foo" ] }
          }
        }
      ]
    },
    "template_1": {
      "allOf": [
        { "$ref": "#/definitions/foo_header" },
        { "$ref": "#/definitions/hwho" },
        { "required": [ "template" ], "properties": { "template": { "type": "string" } } }
      ]
    },
    "bar_header" : {
      "allOf": [
        { "$ref": "#/definitions/header" },
        {
          "required": [ "amount", "desc" ],
          "properties": {
            "amount": { "type": "integer" },
            "desc": { "enum": [ "foo" ] }
          }
        }
      ]
    }
  }
}