kwalify 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +7 -1
- data/README.txt +1 -1
- data/bin/kwalify +1 -1
- data/doc/users-guide.html +108 -18
- data/examples/address-book/address-book.schema.yaml +2 -1
- data/examples/invoice/invoice.schema.yaml +3 -3
- data/examples/tapkit/tapkit.schema.yaml +5 -1
- data/lib/kwalify.rb +2 -2
- data/lib/kwalify/errors.rb +1 -1
- data/lib/kwalify/main-program.rb +1 -1
- data/lib/kwalify/messages.rb +20 -4
- data/lib/kwalify/meta-validator.rb +101 -47
- data/lib/kwalify/rule.rb +86 -14
- data/lib/kwalify/types.rb +1 -1
- data/lib/kwalify/util/assert-diff.rb +1 -1
- data/lib/kwalify/util/option-parser.rb +1 -1
- data/lib/kwalify/util/yaml-helper.rb +1 -1
- data/lib/kwalify/validator.rb +51 -5
- data/test/test-metavalidator.rb +172 -2
- data/test/test-metavalidator.rb.error +1 -1
- data/test/test-validator.rb +294 -2
- data/test/test.rb +1 -1
- data/todo.txt +4 -2
- metadata +2 -2
data/ChangeLog
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
.=title: ChangeLog
|
2
|
-
.?release: $Release: 0.
|
2
|
+
.?release: $Release: 0.3.0 $
|
3
3
|
.?lastupdate: $Date$
|
4
4
|
.?version: $Rev$
|
5
5
|
|
6
|
+
.: 2005-09-30 (release 0.3.0)
|
7
|
+
.* Enhances:
|
8
|
+
.- Support 'max-ex' and 'min-ex' (max/min exclusive) support with 'range:'
|
9
|
+
.- Support 'max-ex' and 'min-ex' (max/min exclusive) support with 'length:'
|
10
|
+
.- Support 'unique' constraint
|
11
|
+
|
6
12
|
.: 2005-09-25 (release 0.2.0)
|
7
13
|
.* Enhances:
|
8
14
|
.- New type 'scalar' and 'timestamp' added
|
data/README.txt
CHANGED
data/bin/kwalify
CHANGED
data/doc/users-guide.html
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
<div align="left"><h1>Kwalify Users' Guide</h1></div>
|
16
16
|
<div align="left">
|
17
17
|
makoto kuwata <kwa(at)kuwata-lab.com><br>
|
18
|
-
last update: $Date: 2005-
|
18
|
+
last update: $Date: 2005-10-02 22:45:14 +0900 (Sun, 02 Oct 2005) $<br>
|
19
19
|
</div>
|
20
20
|
|
21
21
|
<a name="preface"></a>
|
@@ -82,6 +82,8 @@ Table of Contents:
|
|
82
82
|
</li>
|
83
83
|
<li><a href="#schema-rules">Rules</a>
|
84
84
|
</li>
|
85
|
+
<li><a href="#schema-unique">Unique constraint</a>
|
86
|
+
</li>
|
85
87
|
<li><a href="#schema-hook">Validator#validator_hook()</a>
|
86
88
|
</li>
|
87
89
|
<li><a href="#schema-block">Validator with Block</a>
|
@@ -467,6 +469,11 @@ document04b.yaml#0: INVALID
|
|
467
469
|
String which represents validation expression. String should contain variable name <code>val</code> which repsents value.
|
468
470
|
(This is an experimental function.)
|
469
471
|
</dd>
|
472
|
+
<dt class="dt3"><strong>
|
473
|
+
<code>unique:</code> </strong></dt>
|
474
|
+
<dd class="dd3">
|
475
|
+
Value is unique for mapping or sequence. See the next subsection for detail.
|
476
|
+
</dd>
|
470
477
|
</dl>
|
471
478
|
<a name="schema05.yaml"></a>
|
472
479
|
<div class="program_caption">
|
@@ -554,14 +561,96 @@ document05b.yaml#0: INVALID
|
|
554
561
|
<br>
|
555
562
|
|
556
563
|
|
564
|
+
<a name="schema-unique"></a>
|
565
|
+
<h3 class="section2">Unique constraint</h3>
|
566
|
+
<p>'<code>unique:</code>' constraint is available with elements of sequence or mapping.
|
567
|
+
This is equivalent to unique key or primary key of RDBMS.
|
568
|
+
</p>
|
569
|
+
<p>Type of a rule which has '<code>unique:</code>' constraint should be scalar (str, int, float, ...).
|
570
|
+
Type of parent rule should be sequence or mapping.
|
571
|
+
</p>
|
572
|
+
<a name="schema06.yaml"></a>
|
573
|
+
<div class="program_caption">
|
574
|
+
<code>schema06.yaml</code> : unique constraint with mapping</div>
|
575
|
+
<pre class="program">type: seq
|
576
|
+
sequence:
|
577
|
+
- type: map
|
578
|
+
required: yes
|
579
|
+
mapping:
|
580
|
+
name:
|
581
|
+
type: str
|
582
|
+
required: yes
|
583
|
+
<strong>unique: yes</strong>
|
584
|
+
email:
|
585
|
+
type: str
|
586
|
+
groups:
|
587
|
+
type: seq
|
588
|
+
sequence:
|
589
|
+
- type: str
|
590
|
+
<strong>unique: yes</strong>
|
591
|
+
</pre>
|
592
|
+
<a name="document06a.yaml"></a>
|
593
|
+
<div class="program_caption">
|
594
|
+
<code>document06a.yaml</code> : valid document example</div>
|
595
|
+
<pre class="program">- name: foo
|
596
|
+
email: admin@mail.com
|
597
|
+
groups:
|
598
|
+
- users
|
599
|
+
- foo
|
600
|
+
- admin
|
601
|
+
- name: bar
|
602
|
+
email: admin@mail.com
|
603
|
+
groups:
|
604
|
+
- users
|
605
|
+
- admin
|
606
|
+
- name: baz
|
607
|
+
email: baz@mail.com
|
608
|
+
groups:
|
609
|
+
- users
|
610
|
+
</pre>
|
611
|
+
<div class="terminal_caption">
|
612
|
+
validate</div>
|
613
|
+
<pre class="terminal">$ kwalify -f schema06.yaml document06a.yaml
|
614
|
+
document06a.yaml#0: valid.
|
615
|
+
</pre>
|
616
|
+
<a name="document06b.yaml"></a>
|
617
|
+
<div class="program_caption">
|
618
|
+
<code>document06b.yaml</code> : invalid document example</div>
|
619
|
+
<pre class="program">- name: foo
|
620
|
+
email: admin@mail.com
|
621
|
+
groups:
|
622
|
+
- foo
|
623
|
+
- users
|
624
|
+
- admin
|
625
|
+
- foo
|
626
|
+
- name: bar
|
627
|
+
email: admin@mail.com
|
628
|
+
groups:
|
629
|
+
- admin
|
630
|
+
- users
|
631
|
+
- name: bar
|
632
|
+
email: baz@mail.com
|
633
|
+
groups:
|
634
|
+
- users
|
635
|
+
</pre>
|
636
|
+
<div class="terminal_caption">
|
637
|
+
validate</div>
|
638
|
+
<pre class="terminal">$ kwalify -f schema06.yaml document06b.yaml
|
639
|
+
document06b.yaml#0: INVALID
|
640
|
+
- [/0/groups/3] 'foo': is already used at '/0/groups/0'.
|
641
|
+
- [/2/name] 'bar': is already used at '/1/name'.
|
642
|
+
</pre>
|
643
|
+
<br>
|
644
|
+
|
645
|
+
|
557
646
|
<a name="schema-hook"></a>
|
558
647
|
<h3 class="section2">Validator#validator_hook()</h3>
|
559
648
|
<p>You can extend Kwalify::Validator class and override Kwalify::Validator#validator_hook() method.
|
560
649
|
This method is called by Kwalify::Validator#validate().
|
561
650
|
</p>
|
562
|
-
<a name="
|
651
|
+
<a name="schema07.yaml"></a>
|
563
652
|
<div class="program_caption">
|
564
|
-
|
653
|
+
schema07.yaml : 'name:' is important.</div>
|
565
654
|
<pre class="program">type: map
|
566
655
|
mapping:
|
567
656
|
questionnaires:
|
@@ -583,9 +672,9 @@ mapping:
|
|
583
672
|
reason:
|
584
673
|
type: str
|
585
674
|
</pre>
|
586
|
-
<a name="
|
675
|
+
<a name="validate07.rb"></a>
|
587
676
|
<div class="program_caption">
|
588
|
-
|
677
|
+
validate07.rb : validate script</div>
|
589
678
|
<pre class="program">#!/usr/bin/env ruby
|
590
679
|
|
591
680
|
require 'kwalify'
|
@@ -595,7 +684,7 @@ require 'yaml'
|
|
595
684
|
class QuestionnairesValidator < Kwalify::Validator
|
596
685
|
|
597
686
|
## load schema definition
|
598
|
-
@@schema = YAML.load_file('
|
687
|
+
@@schema = YAML.load_file('schema07.yaml')
|
599
688
|
|
600
689
|
def initialize()
|
601
690
|
super(@@schema)
|
@@ -636,9 +725,9 @@ else
|
|
636
725
|
end
|
637
726
|
end
|
638
727
|
</pre>
|
639
|
-
<a name="
|
728
|
+
<a name="document07a.yaml"></a>
|
640
729
|
<div class="program_caption">
|
641
|
-
<code>
|
730
|
+
<code>document07a.yaml</code> : valid document example</div>
|
642
731
|
<pre class="program">questionnaires:
|
643
732
|
- name: Foo
|
644
733
|
answer: good
|
@@ -651,12 +740,12 @@ end
|
|
651
740
|
</pre>
|
652
741
|
<div class="terminal_caption">
|
653
742
|
validate</div>
|
654
|
-
<pre class="terminal">$ ruby
|
743
|
+
<pre class="terminal">$ ruby validate07.rb document07a.yaml
|
655
744
|
Valid.
|
656
745
|
</pre>
|
657
|
-
<a name="
|
746
|
+
<a name="document07b.yaml"></a>
|
658
747
|
<div class="program_caption">
|
659
|
-
<code>
|
748
|
+
<code>document07b.yaml</code> : invalid document example</div>
|
660
749
|
<pre class="program">questionnaires:
|
661
750
|
- name: Foo
|
662
751
|
answer: good
|
@@ -667,7 +756,7 @@ Valid.
|
|
667
756
|
</pre>
|
668
757
|
<div class="terminal_caption">
|
669
758
|
validate</div>
|
670
|
-
<pre class="terminal">$ ruby
|
759
|
+
<pre class="terminal">$ ruby validate07.rb document07b.yaml
|
671
760
|
*** INVALID!
|
672
761
|
- [/questionnaires/1] : reason is required when answer is 'bad'.
|
673
762
|
</pre>
|
@@ -680,9 +769,9 @@ validate</div>
|
|
680
769
|
</p>
|
681
770
|
<p><code>Kwalify::Validator.new()</code> method can take a block which is invoked when validation.
|
682
771
|
</p>
|
683
|
-
<a name="
|
772
|
+
<a name="validate08.rb"></a>
|
684
773
|
<div class="program_caption">
|
685
|
-
<code>
|
774
|
+
<code>validate08.rb</code> : validate script</div>
|
686
775
|
<pre class="program">#!/usr/bin/env ruby
|
687
776
|
|
688
777
|
require 'kwalify'
|
@@ -723,14 +812,15 @@ end
|
|
723
812
|
</pre>
|
724
813
|
<div class="terminal_caption">
|
725
814
|
validate</div>
|
726
|
-
<pre class="terminal">$ ruby
|
727
|
-
|
815
|
+
<pre class="terminal">$ ruby validate08.rb document07a.yaml
|
816
|
+
*** INVALID!
|
817
|
+
- [/] : not a sequence.
|
728
818
|
</pre>
|
729
819
|
<div class="terminal_caption">
|
730
820
|
validate</div>
|
731
|
-
<pre class="terminal">$ ruby
|
821
|
+
<pre class="terminal">$ ruby validate08.rb document07b.yaml
|
732
822
|
*** INVALID!
|
733
|
-
- [/
|
823
|
+
- [/] : not a sequence.
|
734
824
|
</pre>
|
735
825
|
<br>
|
736
826
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
##
|
2
2
|
## Kwalify schema example for address book
|
3
3
|
##
|
4
|
-
## $Release: 0.
|
4
|
+
## $Release: 0.3.0 $
|
5
5
|
## copyright(c) 2005 kuwata-lab all rights reserved.
|
6
6
|
##
|
7
7
|
##
|
@@ -17,6 +17,7 @@ sequence:
|
|
17
17
|
"name":
|
18
18
|
type: str
|
19
19
|
required: yes
|
20
|
+
unique: yes
|
20
21
|
"email":
|
21
22
|
type: str
|
22
23
|
pattern: /@/
|
@@ -1,15 +1,15 @@
|
|
1
1
|
###
|
2
2
|
### Kwalify schema example for invoice
|
3
3
|
###
|
4
|
-
### $Rev:
|
5
|
-
### $Release: 0.
|
4
|
+
### $Rev: 20 $
|
5
|
+
### $Release: 0.3.0 $
|
6
6
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
7
7
|
###
|
8
8
|
|
9
9
|
type: map
|
10
10
|
required: yes
|
11
11
|
mapping:
|
12
|
-
"invoice": { type: int, required: yes }
|
12
|
+
"invoice": { type: int, required: yes, unique: yes }
|
13
13
|
"date": { type: date, required: yes }
|
14
14
|
"bill-to": &customer
|
15
15
|
type: map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
##
|
2
2
|
## Kwalify schema example for TapKit
|
3
3
|
##
|
4
|
-
## $Release: 0.
|
4
|
+
## $Release: 0.3.0 $
|
5
5
|
## copyright(c) 2005 kuwata-lab all rights reserved.
|
6
6
|
##
|
7
7
|
|
@@ -41,6 +41,7 @@ mapping:
|
|
41
41
|
"name":
|
42
42
|
type: str
|
43
43
|
required: yes
|
44
|
+
unique: yes
|
44
45
|
"external_name":
|
45
46
|
type: str
|
46
47
|
required: yes
|
@@ -54,6 +55,7 @@ mapping:
|
|
54
55
|
required: yes
|
55
56
|
sequence:
|
56
57
|
- type: str
|
58
|
+
unique: yes
|
57
59
|
"attributes":
|
58
60
|
type: seq
|
59
61
|
required: yes
|
@@ -63,6 +65,7 @@ mapping:
|
|
63
65
|
"name":
|
64
66
|
type: str
|
65
67
|
required: yes
|
68
|
+
unique: yes
|
66
69
|
"column_name":
|
67
70
|
type: text
|
68
71
|
required: yes
|
@@ -105,6 +108,7 @@ mapping:
|
|
105
108
|
"name":
|
106
109
|
type: str
|
107
110
|
required: yes
|
111
|
+
unique: yes
|
108
112
|
"destination":
|
109
113
|
type: str
|
110
114
|
required: yes
|
data/lib/kwalify.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
###
|
2
2
|
### $Rev: 18 $
|
3
|
-
### $Release: 0.
|
3
|
+
### $Release: 0.3.0 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
7
|
|
8
8
|
module Kwalify
|
9
9
|
|
10
|
-
RELEASE = ("$Release: 0.
|
10
|
+
RELEASE = ("$Release: 0.3.0 $" =~ /[.\d]+/) && $&
|
11
11
|
|
12
12
|
end
|
13
13
|
|
data/lib/kwalify/errors.rb
CHANGED
data/lib/kwalify/main-program.rb
CHANGED
data/lib/kwalify/messages.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
2
|
+
### $Rev: 22 $
|
3
|
+
### $Release: 0.3.0 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
@@ -17,9 +17,8 @@ module Kwalify
|
|
17
17
|
# filename: lib/kwalify/main-program.rb
|
18
18
|
@@messages[:action_required] = "command-line option '-f' or '-m' required."
|
19
19
|
@@messages[:meta_schema_empty] = "%s: empty.\n"
|
20
|
-
@@messages[:meta_validation_invalid] = "%s: NG!\n"
|
21
20
|
@@messages[:meta_validation_valid] = "%s: ok.\n"
|
22
|
-
@@messages[:
|
21
|
+
@@messages[:meta_validation_invalid] = "%s: NG!\n"
|
23
22
|
@@messages[:schema_empty] = "%s#%d: empty.\n"
|
24
23
|
@@messages[:validation_valid] = "%s#%d: valid.\n"
|
25
24
|
@@messages[:validation_invalid] = "%s#%d: INVALID\n"
|
@@ -29,6 +28,7 @@ module Kwalify
|
|
29
28
|
@@messages[:type_notstr] = "not a string."
|
30
29
|
@@messages[:type_unknown] = "unknown type."
|
31
30
|
@@messages[:required_notbool] = "not a boolean."
|
31
|
+
@@messages[:pattern_notmatch] = "should be '/..../'."
|
32
32
|
@@messages[:pattern_syntaxerr] = "has regexp error."
|
33
33
|
@@messages[:enum_notseq] = "not a sequence."
|
34
34
|
@@messages[:enum_notscalar] = "not available with seq or map."
|
@@ -41,10 +41,21 @@ module Kwalify
|
|
41
41
|
@@messages[:range_notscalar] = "is available only with scalar type."
|
42
42
|
@@messages[:range_type_unmatch] = "not a %s."
|
43
43
|
@@messages[:range_undefined] = "undefined key."
|
44
|
+
@@messages[:range_twomax] = "both 'max' and 'max-ex' are not available at once."
|
45
|
+
@@messages[:range_twomin] = "both 'min' and 'min-ex' are not available at once."
|
44
46
|
@@messages[:length_notmap] = "not a mapping."
|
45
47
|
@@messages[:length_nottext] = "is available only with string or text."
|
46
48
|
@@messages[:length_notint] = "not an integer."
|
47
49
|
@@messages[:length_undefined] = "undefined key."
|
50
|
+
@@messages[:length_twomax] = "both 'max' and 'max-ex' are not available at once."
|
51
|
+
@@messages[:length_twomin] = "both 'min' and 'min-ex' are not available at once."
|
52
|
+
@@messages[:ident_notbool] = "not a boolean."
|
53
|
+
@@messages[:ident_notscalar] = "is available only with a scalar type."
|
54
|
+
@@messages[:ident_onroot] = "is not available on root element."
|
55
|
+
@@messages[:ident_notmap] = "is available only with an element of mapping."
|
56
|
+
@@messages[:unique_notbool] = "not a boolean."
|
57
|
+
@@messages[:unique_notscalar] = "is available only with a scalar type."
|
58
|
+
@@messages[:unique_onroot] = "is not available on root element."
|
48
59
|
@@messages[:sequence_notseq] = "not a sequence."
|
49
60
|
@@messages[:sequence_noelem] = "required one element."
|
50
61
|
@@messages[:sequence_toomany] = "required just one element."
|
@@ -66,8 +77,13 @@ module Kwalify
|
|
66
77
|
@@messages[:pattern_unmatch] = "not matched to pattern %s."
|
67
78
|
@@messages[:range_toolarge] = "too large (> max %s)."
|
68
79
|
@@messages[:range_toosmall] = "too small (< min %s)."
|
80
|
+
@@messages[:range_toolargeex] = "too large (>= max %s)."
|
81
|
+
@@messages[:range_toosmallex] = "too small (<= min %s)."
|
69
82
|
@@messages[:length_toolong] = "too long (length %d > max %d)."
|
70
83
|
@@messages[:length_tooshort] = "too short (length %d < min %d)."
|
84
|
+
@@messages[:length_toolongex] = "too long (length %d >= max %d)."
|
85
|
+
@@messages[:length_tooshortex] = "too short (length %d <= min %d)."
|
86
|
+
@@messages[:value_notunique] = "is already used at '%s'."
|
71
87
|
@@messages[:required_nokey] = "key '%s:' is required."
|
72
88
|
@@messages[:key_undefined] = "key '%s' is undefined."
|
73
89
|
# --
|
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
2
|
+
### $Rev: 21 $
|
3
|
+
### $Release: 0.3.0 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
@@ -65,6 +65,12 @@ mapping: &main-rule
|
|
65
65
|
type: scalar
|
66
66
|
"min":
|
67
67
|
type: scalar
|
68
|
+
"max-ex":
|
69
|
+
type: scalar
|
70
|
+
"min-ex":
|
71
|
+
type: scalar
|
72
|
+
#complement":
|
73
|
+
# type: boolean
|
68
74
|
"length":
|
69
75
|
type: map
|
70
76
|
mapping:
|
@@ -72,6 +78,14 @@ mapping: &main-rule
|
|
72
78
|
type: int
|
73
79
|
"min":
|
74
80
|
type: int
|
81
|
+
"max-ex":
|
82
|
+
type: int
|
83
|
+
"min-ex":
|
84
|
+
type: int
|
85
|
+
"ident":
|
86
|
+
type: bool
|
87
|
+
"unique":
|
88
|
+
type: bool
|
75
89
|
"sequence":
|
76
90
|
name: SEQUENCE
|
77
91
|
type: seq
|
@@ -116,11 +130,11 @@ END
|
|
116
130
|
type = hash['type']
|
117
131
|
type = Kwalify::DEFAULT_TYPE if type == nil
|
118
132
|
unless type.is_a?(String)
|
119
|
-
errors <<
|
133
|
+
errors << validate_error(:type_notstr, rule, "#{path}/type", type.to_s)
|
120
134
|
end
|
121
135
|
klass = Kwalify.get_type_class(type)
|
122
136
|
unless klass
|
123
|
-
errors <<
|
137
|
+
errors << validate_error(:type_unknown, rule, "#{path}/type", type.to_s)
|
124
138
|
end
|
125
139
|
#
|
126
140
|
if hash.key?('pattern')
|
@@ -129,22 +143,22 @@ END
|
|
129
143
|
begin
|
130
144
|
Regexp.compile(pat)
|
131
145
|
rescue RegexpError => ex
|
132
|
-
errors <<
|
146
|
+
errors << validate_error(:pattern_syntaxerr, rule, "#{path}/pattern", val)
|
133
147
|
end
|
134
148
|
end
|
135
149
|
#
|
136
150
|
if hash.key?('enum')
|
137
151
|
if type == 'seq' || type == 'map' # unless Kwalify.scalar_class?(klass)
|
138
|
-
errors <<
|
152
|
+
errors << validate_error(:enum_notscalar, rule, path, 'enum:')
|
139
153
|
else
|
140
154
|
elem_table = {}
|
141
155
|
hash['enum'].each do |elem|
|
142
156
|
if elem_table[elem]
|
143
|
-
errors <<
|
157
|
+
errors << validate_error(:enum_duplicate, rule, "#{path}/enum", elem.to_s)
|
144
158
|
end
|
145
159
|
elem_table[elem] = true
|
146
160
|
unless elem.is_a?(klass)
|
147
|
-
errors <<
|
161
|
+
errors << validate_error(:enum_type_unmatch, rule, "#{path}/enum", elem, [Kwalify.word(type)])
|
148
162
|
end
|
149
163
|
end
|
150
164
|
end
|
@@ -152,11 +166,11 @@ END
|
|
152
166
|
#
|
153
167
|
if hash.key?('assert')
|
154
168
|
val = hash['assert']
|
155
|
-
val =~ /\bval\b/ or errors <<
|
169
|
+
val =~ /\bval\b/ or errors << validate_error(:assert_noval, rule, "#{path}/assert", val)
|
156
170
|
begin
|
157
171
|
eval "proc { |val| #{val} }"
|
158
172
|
rescue SyntaxError => ex
|
159
|
-
errors <<
|
173
|
+
errors << validate_error(:assert_syntaxerr, rule, "#{path}/assert", val)
|
160
174
|
end
|
161
175
|
end
|
162
176
|
#
|
@@ -164,84 +178,124 @@ END
|
|
164
178
|
val = hash['range']
|
165
179
|
curr_path = path + "/range"
|
166
180
|
if ! val.is_a?(Hash)
|
167
|
-
errors <<
|
181
|
+
errors << validate_error(:range_notmap, rule, curr_path, val)
|
168
182
|
elsif type == 'seq' || type == 'map' || type == 'bool' || type == 'any'
|
169
|
-
errors <<
|
183
|
+
errors << validate_error(:range_notscalar, rule, path, 'range:')
|
170
184
|
else
|
171
185
|
val.each do |rkey, rval|
|
172
|
-
case rkey
|
173
|
-
when 'max', 'min'
|
186
|
+
#case rkey
|
187
|
+
#when 'max', 'min', 'max-ex', 'min-ex'
|
174
188
|
unless rval.is_a?(klass)
|
175
189
|
typename = Kwalify.word(type) || type
|
176
|
-
errors <<
|
190
|
+
errors << validate_error(:range_type_unmatch, rule, "#{curr_path}/#{rkey}", rval, [typename])
|
177
191
|
end
|
178
|
-
else
|
179
|
-
|
180
|
-
end
|
192
|
+
#else
|
193
|
+
# errors << validate_error(:range_undefined, rule, curr_path, "#{rkey}:")
|
194
|
+
#end
|
181
195
|
end
|
182
196
|
end
|
197
|
+
if val.key?('max') && val.key?('max-ex')
|
198
|
+
errors << validate_error(:range_twomax, rule, curr_path, nil)
|
199
|
+
end
|
200
|
+
if val.key?('min') && val.key?('min-ex')
|
201
|
+
errors << validate_error(:range_twomin, rule, curr_path, nil)
|
202
|
+
end
|
183
203
|
end
|
184
204
|
#
|
185
205
|
if hash.key?('length')
|
186
206
|
val = hash['length']
|
187
207
|
curr_path = path + "/length"
|
188
|
-
val.is_a?(Hash) or errors <<
|
208
|
+
val.is_a?(Hash) or errors << validate_error(:length_notmap, rule, curr_path, val)
|
189
209
|
unless type == 'str' || type == 'text'
|
190
210
|
errors << validate_error(:length_nottext, rule, path, 'length:')
|
191
211
|
end
|
192
212
|
val.each do |lkey, lval|
|
193
|
-
case lkey
|
194
|
-
when 'max', 'min'
|
213
|
+
#case lkey
|
214
|
+
#when 'max', 'min', 'max-ex', 'min-ex'
|
195
215
|
unless lval.is_a?(Integer)
|
196
|
-
errors <<
|
216
|
+
errors << validate_error(:length_notint, rule, "#{curr_path}/#{lkey}", lval)
|
197
217
|
end
|
198
|
-
else
|
199
|
-
|
200
|
-
end
|
218
|
+
#else
|
219
|
+
# errors << validate_error(:length_undefined, rule, curr_path, "#{lkey}:")
|
220
|
+
#end
|
221
|
+
end
|
222
|
+
if val.key?('max') && val.key?('max-ex')
|
223
|
+
errors << validate_error(:length_twomax, rule, curr_path, nil)
|
224
|
+
end
|
225
|
+
if val.key?('min') && val.key?('min-ex')
|
226
|
+
errors << validate_error(:length_twomin, rule, curr_path, nil)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
#
|
230
|
+
if hash.key?('unique')
|
231
|
+
if hash['unique'] && (type == 'map' || type == 'seq')
|
232
|
+
errors << validate_error(:unique_notscalar, rule, path, "unique:")
|
233
|
+
end
|
234
|
+
if path.empty?
|
235
|
+
errors << validate_error(:unique_onroot, rule, "/", "unique:")
|
236
|
+
end
|
237
|
+
end
|
238
|
+
#
|
239
|
+
if hash.key?('ident')
|
240
|
+
if hash['ident'] && (type == 'map' || type == 'seq')
|
241
|
+
errors << validate_error(:ident_notscalar, rule, path, "ident:")
|
242
|
+
end
|
243
|
+
if path.empty?
|
244
|
+
errors << validate_error(:ident_onroot, rule, "/", "ident:")
|
201
245
|
end
|
202
246
|
end
|
203
247
|
#
|
204
248
|
if hash.key?('sequence')
|
205
249
|
val = hash['sequence']
|
206
250
|
if val != nil && !val.is_a?(Array)
|
207
|
-
errors <<
|
251
|
+
errors << validate_error(:sequence_notseq, rule, "#{path}/sequence", val)
|
208
252
|
elsif val == nil || val.empty?
|
209
|
-
errors <<
|
253
|
+
errors << validate_error(:sequence_noelem, rule, "#{path}/sequence", val)
|
210
254
|
elsif val.length > 1
|
211
|
-
errors <<
|
255
|
+
errors << validate_error(:sequence_toomany, rule, "#{path}/sequence", val)
|
256
|
+
else
|
257
|
+
child = hash['sequence'][0]
|
258
|
+
if child.is_a?(Hash)
|
259
|
+
if child['ident'] && child['type'] != 'map'
|
260
|
+
errors << validate_error(:ident_notmap, nil, "#{path}/sequence/0", 'ident:')
|
261
|
+
end
|
262
|
+
#if child['unique'] && child['type'] != 'map'
|
263
|
+
# errors << validate_error(:unique_notmap, nil, "#{path}/sequence/0", 'unique:')
|
264
|
+
#end
|
265
|
+
end
|
212
266
|
end
|
213
267
|
end
|
214
268
|
#
|
215
269
|
if hash.key?('mapping')
|
216
270
|
val = hash['mapping']
|
217
271
|
if val != nil && !val.is_a?(Hash)
|
218
|
-
errors <<
|
272
|
+
errors << validate_error(:mapping_notmap, rule, "#{path}/mapping", val)
|
219
273
|
elsif val == nil || val.empty?
|
220
|
-
errors <<
|
274
|
+
errors << validate_error(:mapping_noelem, rule, "#{path}/mapping", val)
|
221
275
|
end
|
222
276
|
end
|
223
277
|
#
|
224
278
|
if type == 'seq'
|
225
|
-
errors <<
|
226
|
-
#errors <<
|
227
|
-
errors <<
|
228
|
-
errors <<
|
229
|
-
#errors <<
|
230
|
-
errors <<
|
279
|
+
errors << validate_error(:seq_nosequence, rule, path, nil) unless hash.key?('sequence')
|
280
|
+
#errors << validate_error(:seq_conflict, rule, path, 'enum:') if hash.key?('enum')
|
281
|
+
errors << validate_error(:seq_conflict, rule, path, 'pattern:') if hash.key?('pattern')
|
282
|
+
errors << validate_error(:seq_conflict, rule, path, 'mapping:') if hash.key?('mapping')
|
283
|
+
#errors << validate_error(:seq_conflict, rule, path, 'range:') if hash.key?('range')
|
284
|
+
errors << validate_error(:seq_conflict, rule, path, 'length:') if hash.key?('length')
|
231
285
|
elsif type == 'map'
|
232
|
-
errors <<
|
233
|
-
#errors <<
|
234
|
-
errors <<
|
235
|
-
errors <<
|
236
|
-
#errors <<
|
237
|
-
errors <<
|
286
|
+
errors << validate_error(:map_nomapping, rule, path, nil) unless hash.key?('mapping')
|
287
|
+
#errors << validate_error(:map_conflict, rule, path, 'enum:') if hash.key?('enum')
|
288
|
+
errors << validate_error(:map_conflict, rule, path, 'pattern:') if hash.key?('pattern')
|
289
|
+
errors << validate_error(:map_conflict, rule, path, 'sequence:') if hash.key?('sequence')
|
290
|
+
#errors << validate_error(:map_conflict, rule, path, 'range:') if hash.key?('range')
|
291
|
+
errors << validate_error(:map_conflict, rule, path, 'length:') if hash.key?('length')
|
238
292
|
else
|
239
|
-
errors <<
|
240
|
-
errors <<
|
293
|
+
errors << validate_error(:scalar_conflict, rule, path, 'sequence:') if hash.key?('sequence')
|
294
|
+
errors << validate_error(:scalar_conflict, rule, path, 'mapping:') if hash.key?('mapping')
|
241
295
|
if hash.key?('enum')
|
242
|
-
errors <<
|
243
|
-
errors <<
|
244
|
-
errors <<
|
296
|
+
errors << validate_error(:enum_conflict, rule, path, 'range:') if hash.key?('range')
|
297
|
+
errors << validate_error(:enum_conflict, rule, path, 'length:') if hash.key?('length')
|
298
|
+
errors << validate_error(:enum_conflict, rule, path, 'pattern:') if hash.key?('pattern')
|
245
299
|
end
|
246
300
|
end
|
247
301
|
|