kwalify 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +232 -0
- data/MIT-LICENSE +20 -0
- data/README.txt +16 -19
- data/bin/kwalify +3 -3
- data/contrib/inline-require +6 -4
- data/contrib/kwalify +3719 -2427
- data/doc-api/classes/CommandOptionError.html +17 -17
- data/doc-api/classes/CommandOptionParser.html +63 -63
- data/doc-api/classes/Kwalify.html +29 -7
- data/doc-api/classes/Kwalify/AssertionError.html +9 -9
- data/doc-api/classes/Kwalify/BaseError.html +72 -71
- data/doc-api/classes/Kwalify/BaseParser.html +461 -0
- data/doc-api/classes/Kwalify/CommandOptionError.html +11 -11
- data/doc-api/classes/Kwalify/ErrorHelper.html +51 -46
- data/doc-api/classes/Kwalify/HashInterface.html +13 -135
- data/doc-api/classes/Kwalify/Json.html +105 -0
- data/doc-api/classes/Kwalify/Main.html +129 -126
- data/doc-api/classes/Kwalify/MetaValidator.html +248 -232
- data/doc-api/classes/Kwalify/Parser.html +12 -12
- data/doc-api/classes/Kwalify/PlainYamlParser.html +166 -163
- data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +11 -11
- data/doc-api/classes/Kwalify/Rule.html +152 -130
- data/doc-api/classes/Kwalify/SchemaError.html +10 -10
- data/doc-api/classes/Kwalify/SyntaxError.html +185 -0
- data/doc-api/classes/Kwalify/Types.html +26 -25
- data/doc-api/classes/Kwalify/Util.html +389 -0
- data/doc-api/classes/Kwalify/Util/HashLike.html +246 -0
- data/doc-api/classes/Kwalify/Util/OrderedHash.html +330 -0
- data/doc-api/classes/Kwalify/ValidationError.html +10 -10
- data/doc-api/classes/Kwalify/Validator.html +153 -86
- data/doc-api/classes/Kwalify/Yaml.html +181 -0
- data/doc-api/classes/Kwalify/Yaml/Parser.html +1538 -0
- data/doc-api/classes/Kwalify/YamlParser.html +190 -183
- data/doc-api/classes/Kwalify/YamlSyntaxError.html +8 -57
- data/doc-api/created.rid +1 -1
- data/doc-api/files/__/README_txt.html +17 -22
- data/doc-api/files/kwalify/errors_rb.html +2 -2
- data/doc-api/files/kwalify/main_rb.html +4 -3
- data/doc-api/files/kwalify/messages_rb.html +2 -2
- data/doc-api/files/kwalify/meta-validator_rb.html +3 -3
- data/doc-api/files/kwalify/{util/yaml-helper_rb.html → parser/base_rb.html} +8 -6
- data/doc-api/files/kwalify/parser/yaml_rb.html +117 -0
- data/doc-api/files/kwalify/rule_rb.html +2 -2
- data/doc-api/files/kwalify/types_rb.html +2 -2
- data/doc-api/files/kwalify/util/assert-text-equal_rb.html +2 -2
- data/doc-api/files/kwalify/util/hash-interface_rb.html +9 -2
- data/doc-api/files/kwalify/util/hashlike_rb.html +107 -0
- data/doc-api/files/kwalify/util/option-parser_rb.html +2 -2
- data/doc-api/files/kwalify/util/ordered-hash_rb.html +107 -0
- data/doc-api/files/kwalify/util/testcase-helper_rb.html +2 -2
- data/doc-api/files/kwalify/util_rb.html +107 -0
- data/doc-api/files/kwalify/validator_rb.html +2 -2
- data/doc-api/files/kwalify/yaml-parser_rb.html +2 -2
- data/doc-api/files/kwalify_rb.html +3 -2
- data/doc-api/fr_class_index.html +8 -1
- data/doc-api/fr_file_index.html +5 -1
- data/doc-api/fr_method_index.html +128 -69
- data/doc/img/fig01.png +0 -0
- data/doc/users-guide.html +882 -717
- data/examples/address-book/address-book.schema.yaml +2 -2
- data/examples/data-binding/BABEL.data.yaml +63 -0
- data/examples/data-binding/BABEL.schema.yaml +31 -0
- data/examples/data-binding/Makefile +8 -0
- data/examples/data-binding/Rakefile +13 -0
- data/examples/data-binding/main.rb +27 -0
- data/examples/invoice/invoice.schema.yaml +3 -3
- data/examples/tapkit/tapkit.schema.yaml +2 -2
- data/lib/kwalify.rb +41 -4
- data/lib/kwalify/errors.rb +118 -96
- data/lib/kwalify/kwalify.schema.yaml +58 -0
- data/lib/kwalify/main.rb +384 -377
- data/lib/kwalify/messages.rb +41 -27
- data/lib/kwalify/meta-validator.rb +251 -331
- data/lib/kwalify/parser/base.rb +127 -0
- data/lib/kwalify/parser/yaml.rb +837 -0
- data/lib/kwalify/rule.rb +545 -487
- data/lib/kwalify/templates/genclass-java.eruby +189 -162
- data/lib/kwalify/templates/genclass-php.eruby +104 -0
- data/lib/kwalify/templates/genclass-ruby.eruby +95 -66
- data/lib/kwalify/types.rb +107 -106
- data/lib/kwalify/util.rb +157 -0
- data/lib/kwalify/util/assert-text-equal.rb +33 -31
- data/lib/kwalify/util/hash-interface.rb +11 -30
- data/lib/kwalify/util/hashlike.rb +51 -0
- data/lib/kwalify/util/option-parser.rb +144 -144
- data/lib/kwalify/util/ordered-hash.rb +57 -0
- data/lib/kwalify/util/testcase-helper.rb +3 -3
- data/lib/kwalify/validator.rb +267 -212
- data/lib/kwalify/yaml-parser.rb +822 -768
- data/setup.rb +861 -607
- data/test/Rookbook.yaml +10 -0
- data/test/{tmp.dir/Context.java → data/users-guide/AddressBook.java.expected} +11 -11
- data/test/data/users-guide/BABEL.data.yaml +24 -0
- data/test/data/users-guide/BABEL.schema.yaml +30 -0
- data/test/data/users-guide/ExampleAddressBook.java +47 -0
- data/test/{tmp.dir/Group.java → data/users-guide/Group.java.expected} +2 -11
- data/test/data/users-guide/Person.java.expected +44 -0
- data/test/data/users-guide/address_book.rb +52 -0
- data/test/data/users-guide/address_book.schema.yaml +28 -0
- data/test/data/users-guide/address_book.yaml +27 -0
- data/test/data/users-guide/answers-schema.yaml +12 -0
- data/test/data/users-guide/answers-validator.rb +52 -0
- data/test/data/users-guide/babel_genclass.result +26 -0
- data/test/data/users-guide/config.schema.yaml +7 -0
- data/test/data/users-guide/config.yaml +4 -0
- data/test/{tmp.dir/silent1.document → data/users-guide/document01a.yaml} +0 -0
- data/test/data/users-guide/document01b.yaml +3 -0
- data/test/data/users-guide/document02a.yaml +4 -0
- data/test/data/users-guide/document02b.yaml +4 -0
- data/test/data/users-guide/document03a.yaml +6 -0
- data/test/data/users-guide/document03b.yaml +6 -0
- data/test/data/users-guide/document04a.yaml +9 -0
- data/test/data/users-guide/document04b.yaml +9 -0
- data/test/data/users-guide/document05a.yaml +11 -0
- data/test/data/users-guide/document05b.yaml +12 -0
- data/test/data/users-guide/document06a.yaml +15 -0
- data/test/data/users-guide/document06b.yaml +16 -0
- data/test/data/users-guide/document07a.yaml +9 -0
- data/test/data/users-guide/document07b.yaml +7 -0
- data/test/data/users-guide/document12a.json +10 -0
- data/test/data/users-guide/document12b.json +6 -0
- data/test/data/users-guide/document13a.yaml +17 -0
- data/test/data/users-guide/document14a.yaml +3 -0
- data/test/data/users-guide/document14b.yaml +3 -0
- data/test/data/users-guide/document15a.yaml +6 -0
- data/test/data/users-guide/document15b.yaml +5 -0
- data/test/data/users-guide/example_address_book.rb +10 -0
- data/test/data/users-guide/example_address_book_java.result +32 -0
- data/test/data/users-guide/example_address_book_ruby.result +31 -0
- data/test/data/users-guide/genclass_java.result +4 -0
- data/test/data/users-guide/howto-validation-with-parsing.rb +28 -0
- data/test/data/users-guide/howto-validation.rb +25 -0
- data/test/data/users-guide/howto3.rb +6 -0
- data/test/data/users-guide/howto3.result +5 -0
- data/test/data/users-guide/howto3.yaml +8 -0
- data/test/data/users-guide/howto5_databinding.result +111 -0
- data/test/data/users-guide/invalid01.result +3 -0
- data/test/data/users-guide/invalid02.result +5 -0
- data/test/data/users-guide/invalid03.result +5 -0
- data/test/data/users-guide/invalid04.result +4 -0
- data/test/data/users-guide/invalid05.result +11 -0
- data/test/data/users-guide/invalid06.result +4 -0
- data/test/data/users-guide/invalid07.result +3 -0
- data/test/data/users-guide/invalid08.result +3 -0
- data/test/data/users-guide/invalid12.json +8 -0
- data/test/data/users-guide/invalid14.result +4 -0
- data/test/data/users-guide/invalid15.result +4 -0
- data/test/data/users-guide/loadbabel.rb +27 -0
- data/test/data/users-guide/loadconfig.rb +15 -0
- data/test/data/users-guide/loadconfig.result +2 -0
- data/test/data/users-guide/models.rb +22 -0
- data/test/data/users-guide/option_ha.result +6 -0
- data/test/data/users-guide/option_ha_genclass_java.result +7 -0
- data/test/{tmp.dir/meta1.schema → data/users-guide/schema01.yaml} +0 -0
- data/test/data/users-guide/schema02.yaml +12 -0
- data/test/data/users-guide/schema03.yaml +9 -0
- data/test/data/users-guide/schema04.yaml +20 -0
- data/test/data/users-guide/schema05.yaml +29 -0
- data/test/data/users-guide/schema06.yaml +11 -0
- data/test/data/users-guide/schema12.json +12 -0
- data/test/data/users-guide/schema13.yaml +13 -0
- data/test/data/users-guide/schema14.yaml +5 -0
- data/test/data/users-guide/schema15.yaml +21 -0
- data/test/data/users-guide/valid01.result +2 -0
- data/test/data/users-guide/valid02.result +2 -0
- data/test/data/users-guide/valid03.result +2 -0
- data/test/data/users-guide/valid04.result +2 -0
- data/test/data/users-guide/valid05.result +2 -0
- data/test/data/users-guide/valid06.result +2 -0
- data/test/data/users-guide/valid07.result +2 -0
- data/test/data/users-guide/valid08.result +2 -0
- data/test/data/users-guide/valid12.result +2 -0
- data/test/data/users-guide/valid13.result +2 -0
- data/test/data/users-guide/valid14.result +2 -0
- data/test/data/users-guide/valid15.result +2 -0
- data/test/data/users-guide/validate08.rb +37 -0
- data/test/test-action.rb +78 -0
- data/test/test-action.yaml +738 -0
- data/test/test-databinding.rb +80 -0
- data/test/test-databinding.yaml +301 -0
- data/test/test-main.rb +129 -150
- data/test/test-main.yaml +126 -321
- data/test/test-metavalidator.rb +47 -47
- data/test/test-metavalidator.yaml +77 -21
- data/test/test-parser-yaml.rb +57 -0
- data/test/test-parser-yaml.yaml +1749 -0
- data/test/test-rule.rb +14 -15
- data/test/test-rule.yaml +6 -3
- data/test/test-users-guide.rb +75 -0
- data/test/test-validator.rb +77 -52
- data/test/test-validator.yaml +168 -6
- data/test/test-yaml-parser.rb +47 -0
- data/test/{test-yamlparser.yaml → test-yaml-parser.yaml} +159 -52
- data/test/test.rb +37 -21
- metadata +136 -37
- data/COPYING +0 -340
- data/ChangeLog +0 -70
- data/doc-api/classes/YamlHelper.html +0 -259
- data/lib/kwalify/util/yaml-helper.rb +0 -82
- data/test/test-yamlparser.rb +0 -58
- data/test/tmp.dir/User.java +0 -43
- data/test/tmp.dir/action1.document +0 -18
- data/test/tmp.dir/action1.schema +0 -32
- data/test/tmp.dir/action2.document +0 -18
- data/test/tmp.dir/action2.schema +0 -32
- data/test/tmp.dir/emacs.document +0 -6
- data/test/tmp.dir/emacs.schema +0 -6
- data/test/tmp.dir/meta1.document +0 -0
- data/test/tmp.dir/meta2.document +0 -0
- data/test/tmp.dir/meta2.schema +0 -3
- data/test/tmp.dir/silent1.schema +0 -3
- data/test/tmp.dir/silent2.document +0 -7
- data/test/tmp.dir/silent2.schema +0 -3
- data/test/tmp.dir/stream.invalid +0 -8
- data/test/tmp.dir/stream.schema +0 -3
- data/test/tmp.dir/stream.valid +0 -8
- data/test/tmp.dir/untabify.document +0 -5
- data/test/tmp.dir/untabify.schema +0 -10
- data/todo.txt +0 -34
data/lib/kwalify/messages.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
4
|
-
### copyright(c) 2005 kuwata-lab all rights reserved.
|
2
|
+
### $Rev: 95 $
|
3
|
+
### $Release: 0.7.0 $
|
4
|
+
### copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
7
|
module Kwalify
|
@@ -15,21 +15,28 @@ module Kwalify
|
|
15
15
|
|
16
16
|
|
17
17
|
@@messages[:command_help] = <<END
|
18
|
-
kwalify -
|
19
|
-
Usage1:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
-
|
26
|
-
-
|
27
|
-
-
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
|
18
|
+
kwalify - schema validator and data binding tool for YAML and JSON
|
19
|
+
## Usage1: validate yaml document
|
20
|
+
kwalify [..options..] -f schema.yaml doc.yaml [doc2.yaml ...]
|
21
|
+
## Usage2: validate schema definition
|
22
|
+
kwalify [..options..] -m schema.yaml [schema2.yaml ...]
|
23
|
+
## Usage3: do action
|
24
|
+
kwalify [..options..] -a action -f schema.yaml [schema2.yaml ...]
|
25
|
+
-h, --help : help
|
26
|
+
-v : version
|
27
|
+
-q : quiet
|
28
|
+
-s : silent (obsolete, use '-q' instead)
|
29
|
+
-f schema.yaml : schema definition file
|
30
|
+
-m : meta-validation mode
|
31
|
+
-t : expand tab characters
|
32
|
+
-l : show linenumber when errored (experimental)
|
33
|
+
-E : show errors in emacs-style (experimental, implies '-l')
|
34
|
+
-a action : action ('genclass-ruby', 'genclass-php', 'genclass-java')
|
35
|
+
(try '-ha genclass-ruby' for details)
|
36
|
+
-I path : template path (for '-a')
|
37
|
+
-P : allow preceding alias
|
32
38
|
END
|
39
|
+
# -z : syntax checking of schema file
|
33
40
|
# -I path : path for template of action
|
34
41
|
|
35
42
|
|
@@ -40,12 +47,12 @@ END
|
|
40
47
|
@@messages[:command_option_noaction] = "command-line option '-f' or '-m' required."
|
41
48
|
@@messages[:command_option_notemplate] = "%s: invalid action (template not found).\n"
|
42
49
|
@@messages[:schema_empty] = "%s: empty schema.\n"
|
50
|
+
@@messages[:validation_empty] = "%s#%d: empty."
|
43
51
|
@@messages[:validation_empty] = "%s#%d: empty.\n"
|
44
|
-
@@messages[:validation_valid] = "%s#%d: valid
|
45
|
-
@@messages[:
|
46
|
-
@@messages[:
|
47
|
-
@@messages[:
|
48
|
-
@@messages[:command_option_notpath] = "-%s: template path required."
|
52
|
+
@@messages[:validation_valid] = "%s#%d: valid."
|
53
|
+
@@messages[:command_option_schema_required] = "-%s: schema filename required."
|
54
|
+
@@messages[:command_option_action_required] = "-%s: action required."
|
55
|
+
@@messages[:command_option_tpath_required] = "-%s: template path required."
|
49
56
|
@@messages[:command_property_invalid] = "%s: invalid property."
|
50
57
|
@@messages[:command_option_invalid] = "-%s: invalid command option."
|
51
58
|
# --
|
@@ -54,7 +61,7 @@ END
|
|
54
61
|
@@messages[:key_unknown] = "unknown key."
|
55
62
|
@@messages[:type_notstr] = "not a string."
|
56
63
|
@@messages[:type_unknown] = "unknown type."
|
57
|
-
@@messages[:
|
64
|
+
@@messages[:class_notmap] = "available only with map type."
|
58
65
|
@@messages[:required_notbool] = "not a boolean."
|
59
66
|
@@messages[:pattern_notstr] = "not a string (or regexp)"
|
60
67
|
@@messages[:pattern_notmatch] = "should be '/..../'."
|
@@ -93,6 +100,9 @@ END
|
|
93
100
|
@@messages[:unique_notbool] = "not a boolean."
|
94
101
|
@@messages[:unique_notscalar] = "is available only with a scalar type."
|
95
102
|
@@messages[:unique_onroot] = "is not available on root element."
|
103
|
+
@@messages[:default_nonscalarval] = "not a scalar."
|
104
|
+
@@messages[:default_notscalar] = "is available only with a scalar type."
|
105
|
+
@@messages[:default_unmatch] = "not a %s."
|
96
106
|
@@messages[:sequence_notseq] = "not a sequence."
|
97
107
|
@@messages[:sequence_noelem] = "required one element."
|
98
108
|
@@messages[:sequence_toomany] = "required just one element."
|
@@ -104,10 +114,14 @@ END
|
|
104
114
|
@@messages[:map_conflict] = "not available with mapping."
|
105
115
|
@@messages[:scalar_conflict] = "not available with scalar type."
|
106
116
|
@@messages[:enum_conflict] = "not available with 'enum:'."
|
117
|
+
@@messages[:default_conflict] = "not available when 'required:' is true."
|
107
118
|
# --
|
108
119
|
# filename: lib/kwalify/validator.rb
|
109
120
|
@@messages[:required_novalue] = "value required but none."
|
110
121
|
@@messages[:type_unmatch] = "not a %s."
|
122
|
+
@@messages[:key_undefined] = "key '%s' is undefined."
|
123
|
+
@@messages[:required_nokey] = "key '%s:' is required."
|
124
|
+
@@messages[:value_notunique] = "is already used at '%s'."
|
111
125
|
@@messages[:assert_failed] = "assertion expression failed (%s)."
|
112
126
|
@@messages[:enum_notexist] = "invalid %s value."
|
113
127
|
@@messages[:pattern_unmatch] = "not matched to pattern %s."
|
@@ -119,18 +133,18 @@ END
|
|
119
133
|
@@messages[:length_tooshort] = "too short (length %d < min %d)."
|
120
134
|
@@messages[:length_toolongex] = "too long (length %d >= max %d)."
|
121
135
|
@@messages[:length_tooshortex] = "too short (length %d <= min %d)."
|
122
|
-
@@messages[:value_notunique] = "is already used at '%s'."
|
123
|
-
@@messages[:required_nokey] = "key '%s:' is required."
|
124
|
-
@@messages[:key_undefined] = "key '%s' is undefined."
|
125
136
|
# --
|
126
137
|
# filename: lib/kwalify/yaml-parser.rb
|
127
138
|
@@messages[:flow_hastail] = "flow style sequence is closed but got '%s'."
|
128
139
|
@@messages[:flow_eof] = "found EOF when parsing flow style."
|
140
|
+
@@messages[:flow_alias_label] = "alias name expected."
|
141
|
+
@@messages[:flow_anchor_label] = "anchor name expected."
|
129
142
|
@@messages[:flow_noseqitem] = "sequence item required (or last comma is extra)."
|
130
143
|
@@messages[:flow_seqnotclosed] = "flow style sequence requires ']'."
|
131
144
|
@@messages[:flow_mapnoitem] = "mapping item required (or last comma is extra)."
|
132
145
|
@@messages[:flow_mapnotclosed] = "flow style mapping requires '}'."
|
133
|
-
@@messages[:flow_nocolon] = "':' expected but got
|
146
|
+
@@messages[:flow_nocolon] = "':' expected but got %s."
|
147
|
+
@@messages[:flow_str_notclosed] = "%s: string not closed."
|
134
148
|
@@messages[:anchor_duplicated] = "anchor '%s' is already used."
|
135
149
|
@@messages[:alias_extradata] = "alias cannot take any data."
|
136
150
|
@@messages[:anchor_notfound] = "anchor '%s' not found"
|
@@ -1,355 +1,275 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
4
|
-
### copyright(c) 2005 kuwata-lab all rights reserved.
|
2
|
+
### $Rev: 95 $
|
3
|
+
### $Release: 0.7.0 $
|
4
|
+
### copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
7
|
require 'kwalify/errors'
|
8
8
|
require 'kwalify/rule'
|
9
9
|
require 'kwalify/validator'
|
10
|
-
require 'yaml'
|
10
|
+
require 'kwalify/parser/yaml'
|
11
|
+
#require 'yaml'
|
11
12
|
|
12
13
|
module Kwalify
|
13
14
|
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
##
|
17
|
+
## ex.
|
18
|
+
## meta_validator = Kwalify::MetaValidator.instance()
|
19
|
+
## schema = File.load_file('schema.yaml')
|
20
|
+
## errors = meta_validator.validate(schema)
|
21
|
+
## if !errors.empty?
|
22
|
+
## errors.each do |error|
|
23
|
+
## puts "[#{error.path}] #{error.message}"
|
24
|
+
## end
|
25
|
+
## end
|
26
|
+
##
|
27
|
+
class MetaValidator < Validator
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
type: map
|
31
|
-
required: yes
|
32
|
-
mapping: &main-rule
|
33
|
-
"name":
|
34
|
-
type: str
|
35
|
-
"desc":
|
36
|
-
type: str
|
37
|
-
"classname":
|
38
|
-
type: str
|
39
|
-
"type":
|
40
|
-
type: str
|
41
|
-
#required: yes
|
42
|
-
enum:
|
43
|
-
- seq
|
44
|
-
#- sequence
|
45
|
-
#- list
|
46
|
-
- map
|
47
|
-
#- mapping
|
48
|
-
#- hash
|
49
|
-
- str
|
50
|
-
#- string
|
51
|
-
- int
|
52
|
-
#- integer
|
53
|
-
- float
|
54
|
-
- number
|
55
|
-
#- numeric
|
56
|
-
- bool
|
57
|
-
#- boolean
|
58
|
-
- text
|
59
|
-
- date
|
60
|
-
- time
|
61
|
-
- timestamp
|
62
|
-
#- object
|
63
|
-
- any
|
64
|
-
- scalar
|
65
|
-
#- collection
|
66
|
-
"required":
|
67
|
-
type: bool
|
68
|
-
"enum":
|
69
|
-
type: seq
|
70
|
-
sequence:
|
71
|
-
- type: scalar
|
72
|
-
unique: yes
|
73
|
-
"pattern":
|
74
|
-
type: str
|
75
|
-
"assert":
|
76
|
-
type: str
|
77
|
-
pattern: /\bval\b/
|
78
|
-
"range":
|
79
|
-
type: map
|
80
|
-
mapping:
|
81
|
-
"max":
|
82
|
-
type: scalar
|
83
|
-
"min":
|
84
|
-
type: scalar
|
85
|
-
"max-ex":
|
86
|
-
type: scalar
|
87
|
-
"min-ex":
|
88
|
-
type: scalar
|
89
|
-
"length":
|
90
|
-
type: map
|
91
|
-
mapping:
|
92
|
-
"max":
|
93
|
-
type: int
|
94
|
-
"min":
|
95
|
-
type: int
|
96
|
-
"max-ex":
|
97
|
-
type: int
|
98
|
-
"min-ex":
|
99
|
-
type: int
|
100
|
-
"ident":
|
101
|
-
type: bool
|
102
|
-
"unique":
|
103
|
-
type: bool
|
104
|
-
"sequence":
|
105
|
-
name: SEQUENCE
|
106
|
-
type: seq
|
107
|
-
sequence:
|
108
|
-
- type: map
|
109
|
-
mapping: *main-rule
|
110
|
-
name: MAIN
|
111
|
-
#required: yes
|
112
|
-
"mapping":
|
113
|
-
name: MAPPING
|
114
|
-
type: map
|
115
|
-
mapping:
|
116
|
-
=:
|
117
|
-
type: map
|
118
|
-
mapping: *main-rule
|
119
|
-
name: MAIN
|
120
|
-
#required: yes
|
121
|
-
END
|
29
|
+
filename = File.join(File.dirname(__FILE__), 'kwalify.schema.yaml')
|
30
|
+
META_SCHEMA = File.read(filename)
|
122
31
|
|
123
|
-
|
124
|
-
|
125
|
-
|
32
|
+
def self.instance()
|
33
|
+
unless @instance
|
34
|
+
schema = Kwalify::Yaml::Parser.new().parse(META_SCHEMA)
|
35
|
+
@instance = MetaValidator.new(schema)
|
126
36
|
end
|
37
|
+
return @instance
|
38
|
+
end
|
127
39
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
#
|
174
|
-
if hash.key?('assert')
|
175
|
-
val = hash['assert']
|
176
|
-
#val =~ /\bval\b/ or errors << validate_error(:assert_noval, rule, "#{path}/assert", val)
|
177
|
-
begin
|
178
|
-
eval "proc { |val| #{val} }"
|
179
|
-
rescue SyntaxError => ex
|
180
|
-
errors << validate_error(:assert_syntaxerr, rule, "#{path}/assert", val)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
#
|
184
|
-
if hash.key?('range')
|
185
|
-
val = hash['range']
|
186
|
-
curr_path = path + "/range"
|
187
|
-
#if ! val.is_a?(Hash)
|
188
|
-
# errors << validate_error(:range_notmap, rule, curr_path, val)
|
189
|
-
#elsif ...
|
190
|
-
if Types.collection_type?(type) || type == 'bool' || type == 'any'
|
191
|
-
errors << validate_error(:range_notscalar, rule, path, 'range:')
|
192
|
-
else
|
193
|
-
val.each do |rkey, rval|
|
194
|
-
#case rkey
|
195
|
-
#when 'max', 'min', 'max-ex', 'min-ex'
|
196
|
-
unless rval.is_a?(klass)
|
197
|
-
typename = Kwalify.word(type) || type
|
198
|
-
errors << validate_error(:range_type_unmatch, rule, "#{curr_path}/#{rkey}", rval, [typename])
|
199
|
-
end
|
200
|
-
#else
|
201
|
-
# errors << validate_error(:range_undefined, rule, curr_path, "#{rkey}:")
|
202
|
-
#end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
if val.key?('max') && val.key?('max-ex')
|
206
|
-
errors << validate_error(:range_twomax, rule, curr_path, nil)
|
207
|
-
end
|
208
|
-
if val.key?('min') && val.key?('min-ex')
|
209
|
-
errors << validate_error(:range_twomin, rule, curr_path, nil)
|
210
|
-
end
|
211
|
-
max, min, max_ex, min_ex = val['max'], val['min'], val['max-ex'], val['min-ex']
|
212
|
-
if max
|
213
|
-
if min && max < min
|
214
|
-
errors << validate_error(:range_maxltmin, rule, curr_path, nil, [max, min])
|
215
|
-
elsif min_ex && max <= min_ex
|
216
|
-
errors << validate_error(:range_maxleminex, rule, curr_path, nil, [max, min_ex])
|
217
|
-
end
|
218
|
-
elsif max_ex
|
219
|
-
if min && max_ex <= min
|
220
|
-
errors << validate_error(:range_maxexlemin, rule, curr_path, nil, [max_ex, min])
|
221
|
-
elsif min_ex && max_ex <= min_ex
|
222
|
-
errors << validate_error(:range_maxexleminex, rule, curr_path, nil, [max_ex, min_ex])
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
#
|
227
|
-
if hash.key?('length')
|
228
|
-
val = hash['length']
|
229
|
-
curr_path = path + "/length"
|
230
|
-
#val.is_a?(Hash) or errors << validate_error(:length_notmap, rule, curr_path, val)
|
231
|
-
unless type == 'str' || type == 'text'
|
232
|
-
errors << validate_error(:length_nottext, rule, path, 'length:')
|
233
|
-
end
|
234
|
-
#val.each do |lkey, lval|
|
235
|
-
# #case lkey
|
236
|
-
# #when 'max', 'min', 'max-ex', 'min-ex'
|
237
|
-
# unless lval.is_a?(Integer)
|
238
|
-
# errors << validate_error(:length_notint, rule, "#{curr_path}/#{lkey}", lval)
|
239
|
-
# end
|
240
|
-
# #else
|
241
|
-
# # errors << validate_error(:length_undefined, rule, curr_path, "#{lkey}:")
|
242
|
-
# #end
|
40
|
+
def initialize(schema, &block)
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_hook(value, rule, path, errors)
|
45
|
+
return if value.nil? ## realy?
|
46
|
+
return unless rule.name == "MAIN"
|
47
|
+
#
|
48
|
+
hash = value
|
49
|
+
type = hash['type']
|
50
|
+
type = Types::DEFAULT_TYPE if type.nil?
|
51
|
+
klass = Types.type_class(type)
|
52
|
+
#unless klass
|
53
|
+
# errors << validate_error(:type_unknown, rule, "#{path}/type", type)
|
54
|
+
#end
|
55
|
+
#
|
56
|
+
if hash.key?('class')
|
57
|
+
val = hash['class']
|
58
|
+
unless val.nil? || type == 'map'
|
59
|
+
errors << validate_error(:class_notmap, rule, "#{path}/class", 'class:')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
#
|
63
|
+
if hash.key?('pattern')
|
64
|
+
val = hash['pattern']
|
65
|
+
pat = (val =~ /\A\/(.*)\/([mi]?[mi]?)\z/ ? $1 : val)
|
66
|
+
begin
|
67
|
+
Regexp.compile(pat)
|
68
|
+
rescue RegexpError => ex
|
69
|
+
errors << validate_error(:pattern_syntaxerr, rule, "#{path}/pattern", val)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
#
|
73
|
+
if hash.key?('enum')
|
74
|
+
if Types.collection_type?(type)
|
75
|
+
errors << validate_error(:enum_notscalar, rule, path, 'enum:')
|
76
|
+
else
|
77
|
+
#elem_table = {}
|
78
|
+
hash['enum'].each do |elem|
|
79
|
+
#if elem_table[elem]
|
80
|
+
# errors << validate_error(:enum_duplicate, rule, "#{path}/enum", elem.to_s)
|
243
81
|
#end
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
if val.key?('min') && val.key?('min-ex')
|
248
|
-
errors << validate_error(:length_twomin, rule, curr_path, nil)
|
249
|
-
end
|
250
|
-
max, min, max_ex, min_ex = val['max'], val['min'], val['max-ex'], val['min-ex']
|
251
|
-
if max
|
252
|
-
if min && max < min
|
253
|
-
errors << validate_error(:length_maxltmin, rule, curr_path, nil, [max, min])
|
254
|
-
elsif min_ex && max <= min_ex
|
255
|
-
errors << validate_error(:length_maxleminex, rule, curr_path, nil, [max, min_ex])
|
256
|
-
end
|
257
|
-
elsif max_ex
|
258
|
-
if min && max_ex <= min
|
259
|
-
errors << validate_error(:length_maxexlemin, rule, curr_path, nil, [max_ex, min])
|
260
|
-
elsif min_ex && max_ex <= min_ex
|
261
|
-
errors << validate_error(:length_maxexleminex, rule, curr_path, nil, [max_ex, min_ex])
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
#
|
266
|
-
if hash.key?('unique')
|
267
|
-
if hash['unique'] && Types.collection_type?(type)
|
268
|
-
errors << validate_error(:unique_notscalar, rule, path, "unique:")
|
269
|
-
end
|
270
|
-
if path.empty?
|
271
|
-
errors << validate_error(:unique_onroot, rule, "/", "unique:")
|
272
|
-
end
|
273
|
-
end
|
274
|
-
#
|
275
|
-
if hash.key?('ident')
|
276
|
-
if hash['ident'] && Types.collection_type?(type)
|
277
|
-
errors << validate_error(:ident_notscalar, rule, path, "ident:")
|
278
|
-
end
|
279
|
-
if path.empty?
|
280
|
-
errors << validate_error(:ident_onroot, rule, "/", "ident:")
|
82
|
+
#elem_table[elem] = true
|
83
|
+
unless elem.is_a?(klass)
|
84
|
+
errors << validate_error(:enum_type_unmatch, rule, "#{path}/enum", elem, [Kwalify.word(type)])
|
281
85
|
end
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
#errors << validate_error(:
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
errors << validate_error(:
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
#
|
90
|
+
if hash.key?('assert')
|
91
|
+
val = hash['assert']
|
92
|
+
#val =~ /\bval\b/ or errors << validate_error(:assert_noval, rule, "#{path}/assert", val)
|
93
|
+
begin
|
94
|
+
eval "proc { |val| #{val} }"
|
95
|
+
rescue ::SyntaxError => ex
|
96
|
+
errors << validate_error(:assert_syntaxerr, rule, "#{path}/assert", val)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
#
|
100
|
+
if hash.key?('range')
|
101
|
+
val = hash['range']
|
102
|
+
curr_path = path + "/range"
|
103
|
+
#if ! val.is_a?(Hash)
|
104
|
+
# errors << validate_error(:range_notmap, rule, curr_path, val)
|
105
|
+
#elsif ...
|
106
|
+
if Types.collection_type?(type) || type == 'bool' || type == 'any'
|
107
|
+
errors << validate_error(:range_notscalar, rule, path, 'range:')
|
108
|
+
else
|
109
|
+
val.each do |rkey, rval|
|
110
|
+
#case rkey
|
111
|
+
#when 'max', 'min', 'max-ex', 'min-ex'
|
112
|
+
unless rval.is_a?(klass)
|
113
|
+
typename = Kwalify.word(type) || type
|
114
|
+
errors << validate_error(:range_type_unmatch, rule, "#{curr_path}/#{rkey}", rval, [typename])
|
115
|
+
end
|
116
|
+
#else
|
117
|
+
# errors << validate_error(:range_undefined, rule, curr_path, "#{rkey}:")
|
118
|
+
#end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
if val.key?('max') && val.key?('max-ex')
|
122
|
+
errors << validate_error(:range_twomax, rule, curr_path, nil)
|
123
|
+
end
|
124
|
+
if val.key?('min') && val.key?('min-ex')
|
125
|
+
errors << validate_error(:range_twomin, rule, curr_path, nil)
|
126
|
+
end
|
127
|
+
max, min, max_ex, min_ex = val['max'], val['min'], val['max-ex'], val['min-ex']
|
128
|
+
if max
|
129
|
+
if min && max < min
|
130
|
+
errors << validate_error(:range_maxltmin, rule, curr_path, nil, [max, min])
|
131
|
+
elsif min_ex && max <= min_ex
|
132
|
+
errors << validate_error(:range_maxleminex, rule, curr_path, nil, [max, min_ex])
|
133
|
+
end
|
134
|
+
elsif max_ex
|
135
|
+
if min && max_ex <= min
|
136
|
+
errors << validate_error(:range_maxexlemin, rule, curr_path, nil, [max_ex, min])
|
137
|
+
elsif min_ex && max_ex <= min_ex
|
138
|
+
errors << validate_error(:range_maxexleminex, rule, curr_path, nil, [max_ex, min_ex])
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
#
|
143
|
+
if hash.key?('length')
|
144
|
+
val = hash['length']
|
145
|
+
curr_path = path + "/length"
|
146
|
+
#val.is_a?(Hash) or errors << validate_error(:length_notmap, rule, curr_path, val)
|
147
|
+
unless type == 'str' || type == 'text'
|
148
|
+
errors << validate_error(:length_nottext, rule, path, 'length:')
|
149
|
+
end
|
150
|
+
#val.each do |lkey, lval|
|
151
|
+
# #case lkey
|
152
|
+
# #when 'max', 'min', 'max-ex', 'min-ex'
|
153
|
+
# unless lval.is_a?(Integer)
|
154
|
+
# errors << validate_error(:length_notint, rule, "#{curr_path}/#{lkey}", lval)
|
155
|
+
# end
|
156
|
+
# #else
|
157
|
+
# # errors << validate_error(:length_undefined, rule, curr_path, "#{lkey}:")
|
158
|
+
# #end
|
159
|
+
#end
|
160
|
+
if val.key?('max') && val.key?('max-ex')
|
161
|
+
errors << validate_error(:length_twomax, rule, curr_path, nil)
|
162
|
+
end
|
163
|
+
if val.key?('min') && val.key?('min-ex')
|
164
|
+
errors << validate_error(:length_twomin, rule, curr_path, nil)
|
165
|
+
end
|
166
|
+
max, min, max_ex, min_ex = val['max'], val['min'], val['max-ex'], val['min-ex']
|
167
|
+
if max
|
168
|
+
if min && max < min
|
169
|
+
errors << validate_error(:length_maxltmin, rule, curr_path, nil, [max, min])
|
170
|
+
elsif min_ex && max <= min_ex
|
171
|
+
errors << validate_error(:length_maxleminex, rule, curr_path, nil, [max, min_ex])
|
172
|
+
end
|
173
|
+
elsif max_ex
|
174
|
+
if min && max_ex <= min
|
175
|
+
errors << validate_error(:length_maxexlemin, rule, curr_path, nil, [max_ex, min])
|
176
|
+
elsif min_ex && max_ex <= min_ex
|
177
|
+
errors << validate_error(:length_maxexleminex, rule, curr_path, nil, [max_ex, min_ex])
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
#
|
182
|
+
if hash.key?('unique')
|
183
|
+
if hash['unique'] && Types.collection_type?(type)
|
184
|
+
errors << validate_error(:unique_notscalar, rule, path, "unique:")
|
185
|
+
end
|
186
|
+
if path.empty?
|
187
|
+
errors << validate_error(:unique_onroot, rule, "/", "unique:")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
#
|
191
|
+
if hash.key?('ident')
|
192
|
+
if hash['ident'] && Types.collection_type?(type)
|
193
|
+
errors << validate_error(:ident_notscalar, rule, path, "ident:")
|
194
|
+
end
|
195
|
+
if path.empty?
|
196
|
+
errors << validate_error(:ident_onroot, rule, "/", "ident:")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
#
|
200
|
+
if hash.key?('default')
|
201
|
+
val = hash['default']
|
202
|
+
if Types.collection_type?(type)
|
203
|
+
errors << validate_error(:default_notscalar, rule, path, "default:")
|
204
|
+
elsif !val.nil? && !val.is_a?(klass)
|
205
|
+
errors << validate_error(:default_unmatch, rule, "#{path}/default", val, [Kwalify.word(type)])
|
206
|
+
end
|
343
207
|
end
|
208
|
+
#
|
209
|
+
if hash.key?('sequence')
|
210
|
+
val = hash['sequence']
|
211
|
+
#if !val.nil? && !val.is_a?(Array)
|
212
|
+
# errors << validate_error(:sequence_notseq, rule, "#{path}/sequence", val)
|
213
|
+
#elsif ...
|
214
|
+
if val.nil? || val.empty?
|
215
|
+
errors << validate_error(:sequence_noelem, rule, "#{path}/sequence", val)
|
216
|
+
elsif val.length > 1
|
217
|
+
errors << validate_error(:sequence_toomany, rule, "#{path}/sequence", val)
|
218
|
+
else
|
219
|
+
elem = val[0]
|
220
|
+
assert_error("elem.class=#{elem.class}") unless elem.is_a?(Hash)
|
221
|
+
if elem['ident'] && elem['type'] != 'map'
|
222
|
+
errors << validate_error(:ident_notmap, nil, "#{path}/sequence/0", 'ident:')
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
#
|
227
|
+
if hash.key?('mapping')
|
228
|
+
val = hash['mapping']
|
229
|
+
if !val.nil? && !val.is_a?(Hash)
|
230
|
+
errors << validate_error(:mapping_notmap, rule, "#{path}/mapping", val)
|
231
|
+
elsif val.nil? || (val.empty? && !val.default)
|
232
|
+
errors << validate_error(:mapping_noelem, rule, "#{path}/mapping", val)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
#
|
236
|
+
if type == 'seq'
|
237
|
+
errors << validate_error(:seq_nosequence, rule, path, nil) unless hash.key?('sequence')
|
238
|
+
#errors << validate_error(:seq_conflict, rule, path, 'enum:') if hash.key?('enum')
|
239
|
+
errors << validate_error(:seq_conflict, rule, path, 'pattern:') if hash.key?('pattern')
|
240
|
+
errors << validate_error(:seq_conflict, rule, path, 'mapping:') if hash.key?('mapping')
|
241
|
+
#errors << validate_error(:seq_conflict, rule, path, 'range:') if hash.key?('range')
|
242
|
+
#errors << validate_error(:seq_conflict, rule, path, 'length:') if hash.key?('length')
|
243
|
+
elsif type == 'map'
|
244
|
+
errors << validate_error(:map_nomapping, rule, path, nil) unless hash.key?('mapping')
|
245
|
+
#errors << validate_error(:map_conflict, rule, path, 'enum:') if hash.key?('enum')
|
246
|
+
errors << validate_error(:map_conflict, rule, path, 'pattern:') if hash.key?('pattern')
|
247
|
+
errors << validate_error(:map_conflict, rule, path, 'sequence:') if hash.key?('sequence')
|
248
|
+
#errors << validate_error(:map_conflict, rule, path, 'range:') if hash.key?('range')
|
249
|
+
#errors << validate_error(:map_conflict, rule, path, 'length:') if hash.key?('length')
|
250
|
+
else
|
251
|
+
errors << validate_error(:scalar_conflict, rule, path, 'sequence:') if hash.key?('sequence')
|
252
|
+
errors << validate_error(:scalar_conflict, rule, path, 'mapping:') if hash.key?('mapping')
|
253
|
+
if hash.key?('enum')
|
254
|
+
errors << validate_error(:enum_conflict, rule, path, 'range:') if hash.key?('range')
|
255
|
+
errors << validate_error(:enum_conflict, rule, path, 'length:') if hash.key?('length')
|
256
|
+
errors << validate_error(:enum_conflict, rule, path, 'pattern:') if hash.key?('pattern')
|
257
|
+
end
|
258
|
+
if hash.key?('default')
|
259
|
+
errors << validate_error(:default_conflict, rule, path, 'default:') if hash['required']
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
end # end of def validate_hook()
|
344
264
|
|
345
265
|
|
346
|
-
|
266
|
+
end # end of class MetaValidator
|
347
267
|
|
348
268
|
|
349
|
-
|
269
|
+
META_VALIDATOR = MetaValidator.instance()
|
350
270
|
|
351
|
-
|
352
|
-
|
353
|
-
|
271
|
+
def self.meta_validator # obsolete
|
272
|
+
return META_VALIDATOR
|
273
|
+
end
|
354
274
|
|
355
275
|
end
|