seomoz-json-schema 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/README.textile +216 -0
  2. data/lib/json-schema.rb +13 -0
  3. data/lib/json-schema/attributes/additionalitems.rb +23 -0
  4. data/lib/json-schema/attributes/additionalproperties.rb +39 -0
  5. data/lib/json-schema/attributes/dependencies.rb +30 -0
  6. data/lib/json-schema/attributes/disallow.rb +11 -0
  7. data/lib/json-schema/attributes/divisibleby.rb +16 -0
  8. data/lib/json-schema/attributes/enum.rb +24 -0
  9. data/lib/json-schema/attributes/extends.rb +14 -0
  10. data/lib/json-schema/attributes/format.rb +113 -0
  11. data/lib/json-schema/attributes/items.rb +25 -0
  12. data/lib/json-schema/attributes/maxdecimal.rb +15 -0
  13. data/lib/json-schema/attributes/maximum.rb +15 -0
  14. data/lib/json-schema/attributes/maximum_inclusive.rb +15 -0
  15. data/lib/json-schema/attributes/maxitems.rb +12 -0
  16. data/lib/json-schema/attributes/maxlength.rb +14 -0
  17. data/lib/json-schema/attributes/minimum.rb +15 -0
  18. data/lib/json-schema/attributes/minimum_inclusive.rb +15 -0
  19. data/lib/json-schema/attributes/minitems.rb +12 -0
  20. data/lib/json-schema/attributes/minlength.rb +14 -0
  21. data/lib/json-schema/attributes/pattern.rb +15 -0
  22. data/lib/json-schema/attributes/patternproperties.rb +23 -0
  23. data/lib/json-schema/attributes/properties.rb +23 -0
  24. data/lib/json-schema/attributes/properties_optional.rb +23 -0
  25. data/lib/json-schema/attributes/ref.rb +55 -0
  26. data/lib/json-schema/attributes/type.rb +71 -0
  27. data/lib/json-schema/attributes/uniqueitems.rb +16 -0
  28. data/lib/json-schema/schema.rb +50 -0
  29. data/lib/json-schema/uri/file.rb +32 -0
  30. data/lib/json-schema/uri/uuid.rb +285 -0
  31. data/lib/json-schema/validator.rb +425 -0
  32. data/lib/json-schema/validators/draft1.rb +32 -0
  33. data/lib/json-schema/validators/draft2.rb +33 -0
  34. data/lib/json-schema/validators/draft3.rb +38 -0
  35. data/resources/draft-01.json +155 -0
  36. data/resources/draft-02.json +166 -0
  37. data/resources/draft-03.json +174 -0
  38. data/test/data/bad_data_1.json +3 -0
  39. data/test/data/good_data_1.json +3 -0
  40. data/test/schemas/good_schema_1.json +10 -0
  41. data/test/schemas/good_schema_2.json +10 -0
  42. data/test/test_extended_schema.rb +68 -0
  43. data/test/test_files.rb +35 -0
  44. data/test/test_full_validation.rb +38 -0
  45. data/test/test_jsonschema_draft1.rb +703 -0
  46. data/test/test_jsonschema_draft2.rb +775 -0
  47. data/test/test_jsonschema_draft3.rb +972 -0
  48. data/test/test_schema_validation.rb +43 -0
  49. metadata +137 -0
@@ -0,0 +1,32 @@
1
+ module JSON
2
+ class Schema
3
+
4
+ class Draft1 < Validator
5
+ def initialize
6
+ super
7
+ @attributes = {
8
+ "type" => JSON::Schema::TypeAttribute,
9
+ "disallow" => JSON::Schema::DisallowAttribute,
10
+ "format" => JSON::Schema::FormatAttribute,
11
+ "maximum" => JSON::Schema::MaximumInclusiveAttribute,
12
+ "minimum" => JSON::Schema::MinimumInclusiveAttribute,
13
+ "minItems" => JSON::Schema::MinItemsAttribute,
14
+ "maxItems" => JSON::Schema::MaxItemsAttribute,
15
+ "minLength" => JSON::Schema::MinLengthAttribute,
16
+ "maxLength" => JSON::Schema::MaxLengthAttribute,
17
+ "maxDecimal" => JSON::Schema::MaxDecimalAttribute,
18
+ "enum" => JSON::Schema::EnumAttribute,
19
+ "properties" => JSON::Schema::PropertiesOptionalAttribute,
20
+ "pattern" => JSON::Schema::PatternAttribute,
21
+ "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute,
22
+ "items" => JSON::Schema::ItemsAttribute,
23
+ "extends" => JSON::Schema::ExtendsAttribute
24
+ }
25
+ @uri = URI.parse("http://json-schema.org/draft-01/schema#")
26
+ end
27
+
28
+ JSON::Validator.register_validator(self.new)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module JSON
2
+ class Schema
3
+
4
+ class Draft2 < Validator
5
+ def initialize
6
+ super
7
+ @attributes = {
8
+ "type" => JSON::Schema::TypeAttribute,
9
+ "disallow" => JSON::Schema::DisallowAttribute,
10
+ "format" => JSON::Schema::FormatAttribute,
11
+ "maximum" => JSON::Schema::MaximumInclusiveAttribute,
12
+ "minimum" => JSON::Schema::MinimumInclusiveAttribute,
13
+ "minItems" => JSON::Schema::MinItemsAttribute,
14
+ "maxItems" => JSON::Schema::MaxItemsAttribute,
15
+ "uniqueItems" => JSON::Schema::UniqueItemsAttribute,
16
+ "minLength" => JSON::Schema::MinLengthAttribute,
17
+ "maxLength" => JSON::Schema::MaxLengthAttribute,
18
+ "divisibleBy" => JSON::Schema::DivisibleByAttribute,
19
+ "enum" => JSON::Schema::EnumAttribute,
20
+ "properties" => JSON::Schema::PropertiesOptionalAttribute,
21
+ "pattern" => JSON::Schema::PatternAttribute,
22
+ "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute,
23
+ "items" => JSON::Schema::ItemsAttribute,
24
+ "extends" => JSON::Schema::ExtendsAttribute
25
+ }
26
+ @uri = URI.parse("http://json-schema.org/draft-02/schema#")
27
+ end
28
+
29
+ JSON::Validator.register_validator(self.new)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ module JSON
2
+ class Schema
3
+
4
+ class Draft3 < Validator
5
+ def initialize
6
+ super
7
+ @attributes = {
8
+ "type" => JSON::Schema::TypeAttribute,
9
+ "disallow" => JSON::Schema::DisallowAttribute,
10
+ "format" => JSON::Schema::FormatAttribute,
11
+ "maximum" => JSON::Schema::MaximumAttribute,
12
+ "minimum" => JSON::Schema::MinimumAttribute,
13
+ "minItems" => JSON::Schema::MinItemsAttribute,
14
+ "maxItems" => JSON::Schema::MaxItemsAttribute,
15
+ "uniqueItems" => JSON::Schema::UniqueItemsAttribute,
16
+ "minLength" => JSON::Schema::MinLengthAttribute,
17
+ "maxLength" => JSON::Schema::MaxLengthAttribute,
18
+ "divisibleBy" => JSON::Schema::DivisibleByAttribute,
19
+ "enum" => JSON::Schema::EnumAttribute,
20
+ "properties" => JSON::Schema::PropertiesAttribute,
21
+ "pattern" => JSON::Schema::PatternAttribute,
22
+ "patternProperties" => JSON::Schema::PatternPropertiesAttribute,
23
+ "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute,
24
+ "items" => JSON::Schema::ItemsAttribute,
25
+ "additionalItems" => JSON::Schema::AdditionalItemsAttribute,
26
+ "dependencies" => JSON::Schema::DependenciesAttribute,
27
+ "extends" => JSON::Schema::ExtendsAttribute,
28
+ "$ref" => JSON::Schema::RefAttribute
29
+ }
30
+ @uri = URI.parse("http://json-schema.org/draft-03/schema#")
31
+ end
32
+
33
+ JSON::Validator.register_validator(self.new)
34
+ JSON::Validator.register_default_validator(self.new)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,155 @@
1
+ {
2
+ "$schema" : "http://json-schema.org/draft-01/hyper-schema#",
3
+ "id" : "http://json-schema.org/draft-01/schema#",
4
+ "type" : "object",
5
+
6
+ "properties" : {
7
+ "type" : {
8
+ "type" : ["string", "array"],
9
+ "items" : {
10
+ "type" : ["string", {"$ref" : "#"}]
11
+ },
12
+ "optional" : true,
13
+ "default" : "any"
14
+ },
15
+
16
+ "properties" : {
17
+ "type" : "object",
18
+ "additionalProperties" : {"$ref" : "#"},
19
+ "optional" : true,
20
+ "default" : {}
21
+ },
22
+
23
+ "items" : {
24
+ "type" : [{"$ref" : "#"}, "array"],
25
+ "items" : {"$ref" : "#"},
26
+ "optional" : true,
27
+ "default" : {}
28
+ },
29
+
30
+ "optional" : {
31
+ "type" : "boolean",
32
+ "optional" : true,
33
+ "default" : false
34
+ },
35
+
36
+ "additionalProperties" : {
37
+ "type" : [{"$ref" : "#"}, "boolean"],
38
+ "optional" : true,
39
+ "default" : {}
40
+ },
41
+
42
+ "requires" : {
43
+ "type" : ["string", {"$ref" : "#"}],
44
+ "optional" : true
45
+ },
46
+
47
+ "minimum" : {
48
+ "type" : "number",
49
+ "optional" : true
50
+ },
51
+
52
+ "maximum" : {
53
+ "type" : "number",
54
+ "optional" : true
55
+ },
56
+
57
+ "minimumCanEqual" : {
58
+ "type" : "boolean",
59
+ "optional" : true,
60
+ "requires" : "minimum",
61
+ "default" : true
62
+ },
63
+
64
+ "maximumCanEqual" : {
65
+ "type" : "boolean",
66
+ "optional" : true,
67
+ "requires" : "maximum",
68
+ "default" : true
69
+ },
70
+
71
+ "minItems" : {
72
+ "type" : "integer",
73
+ "optional" : true,
74
+ "minimum" : 0,
75
+ "default" : 0
76
+ },
77
+
78
+ "maxItems" : {
79
+ "type" : "integer",
80
+ "optional" : true,
81
+ "minimum" : 0
82
+ },
83
+
84
+ "pattern" : {
85
+ "type" : "string",
86
+ "optional" : true,
87
+ "format" : "regex"
88
+ },
89
+
90
+ "minLength" : {
91
+ "type" : "integer",
92
+ "optional" : true,
93
+ "minimum" : 0,
94
+ "default" : 0
95
+ },
96
+
97
+ "maxLength" : {
98
+ "type" : "integer",
99
+ "optional" : true
100
+ },
101
+
102
+ "enum" : {
103
+ "type" : "array",
104
+ "optional" : true,
105
+ "minItems" : 1
106
+ },
107
+
108
+ "title" : {
109
+ "type" : "string",
110
+ "optional" : true
111
+ },
112
+
113
+ "description" : {
114
+ "type" : "string",
115
+ "optional" : true
116
+ },
117
+
118
+ "format" : {
119
+ "type" : "string",
120
+ "optional" : true
121
+ },
122
+
123
+ "contentEncoding" : {
124
+ "type" : "string",
125
+ "optional" : true
126
+ },
127
+
128
+ "default" : {
129
+ "type" : "any",
130
+ "optional" : true
131
+ },
132
+
133
+ "maxDecimal" : {
134
+ "type" : "integer",
135
+ "optional" : true,
136
+ "minimum" : 0
137
+ },
138
+
139
+ "disallow" : {
140
+ "type" : ["string", "array"],
141
+ "items" : {"type" : "string"},
142
+ "optional" : true
143
+ },
144
+
145
+ "extends" : {
146
+ "type" : [{"$ref" : "#"}, "array"],
147
+ "items" : {"$ref" : "#"},
148
+ "optional" : true,
149
+ "default" : {}
150
+ }
151
+ },
152
+
153
+ "optional" : true,
154
+ "default" : {}
155
+ }
@@ -0,0 +1,166 @@
1
+ {
2
+ "$schema" : "http://json-schema.org/draft-02/hyper-schema#",
3
+ "id" : "http://json-schema.org/draft-02/schema#",
4
+ "type" : "object",
5
+
6
+ "properties" : {
7
+ "type" : {
8
+ "type" : ["string", "array"],
9
+ "items" : {
10
+ "type" : ["string", {"$ref" : "#"}]
11
+ },
12
+ "optional" : true,
13
+ "uniqueItems" : true,
14
+ "default" : "any"
15
+ },
16
+
17
+ "properties" : {
18
+ "type" : "object",
19
+ "additionalProperties" : {"$ref" : "#"},
20
+ "optional" : true,
21
+ "default" : {}
22
+ },
23
+
24
+ "items" : {
25
+ "type" : [{"$ref" : "#"}, "array"],
26
+ "items" : {"$ref" : "#"},
27
+ "optional" : true,
28
+ "default" : {}
29
+ },
30
+
31
+ "optional" : {
32
+ "type" : "boolean",
33
+ "optional" : true,
34
+ "default" : false
35
+ },
36
+
37
+ "additionalProperties" : {
38
+ "type" : [{"$ref" : "#"}, "boolean"],
39
+ "optional" : true,
40
+ "default" : {}
41
+ },
42
+
43
+ "requires" : {
44
+ "type" : ["string", {"$ref" : "#"}],
45
+ "optional" : true
46
+ },
47
+
48
+ "minimum" : {
49
+ "type" : "number",
50
+ "optional" : true
51
+ },
52
+
53
+ "maximum" : {
54
+ "type" : "number",
55
+ "optional" : true
56
+ },
57
+
58
+ "minimumCanEqual" : {
59
+ "type" : "boolean",
60
+ "optional" : true,
61
+ "requires" : "minimum",
62
+ "default" : true
63
+ },
64
+
65
+ "maximumCanEqual" : {
66
+ "type" : "boolean",
67
+ "optional" : true,
68
+ "requires" : "maximum",
69
+ "default" : true
70
+ },
71
+
72
+ "minItems" : {
73
+ "type" : "integer",
74
+ "optional" : true,
75
+ "minimum" : 0,
76
+ "default" : 0
77
+ },
78
+
79
+ "maxItems" : {
80
+ "type" : "integer",
81
+ "optional" : true,
82
+ "minimum" : 0
83
+ },
84
+
85
+ "uniqueItems" : {
86
+ "type" : "boolean",
87
+ "optional" : true,
88
+ "default" : false
89
+ },
90
+
91
+ "pattern" : {
92
+ "type" : "string",
93
+ "optional" : true,
94
+ "format" : "regex"
95
+ },
96
+
97
+ "minLength" : {
98
+ "type" : "integer",
99
+ "optional" : true,
100
+ "minimum" : 0,
101
+ "default" : 0
102
+ },
103
+
104
+ "maxLength" : {
105
+ "type" : "integer",
106
+ "optional" : true
107
+ },
108
+
109
+ "enum" : {
110
+ "type" : "array",
111
+ "optional" : true,
112
+ "minItems" : 1,
113
+ "uniqueItems" : true
114
+ },
115
+
116
+ "title" : {
117
+ "type" : "string",
118
+ "optional" : true
119
+ },
120
+
121
+ "description" : {
122
+ "type" : "string",
123
+ "optional" : true
124
+ },
125
+
126
+ "format" : {
127
+ "type" : "string",
128
+ "optional" : true
129
+ },
130
+
131
+ "contentEncoding" : {
132
+ "type" : "string",
133
+ "optional" : true
134
+ },
135
+
136
+ "default" : {
137
+ "type" : "any",
138
+ "optional" : true
139
+ },
140
+
141
+ "divisibleBy" : {
142
+ "type" : "number",
143
+ "minimum" : 0,
144
+ "minimumCanEqual" : false,
145
+ "optional" : true,
146
+ "default" : 1
147
+ },
148
+
149
+ "disallow" : {
150
+ "type" : ["string", "array"],
151
+ "items" : {"type" : "string"},
152
+ "optional" : true,
153
+ "uniqueItems" : true
154
+ },
155
+
156
+ "extends" : {
157
+ "type" : [{"$ref" : "#"}, "array"],
158
+ "items" : {"$ref" : "#"},
159
+ "optional" : true,
160
+ "default" : {}
161
+ }
162
+ },
163
+
164
+ "optional" : true,
165
+ "default" : {}
166
+ }
@@ -0,0 +1,174 @@
1
+ {
2
+ "$schema" : "http://json-schema.org/draft-03/schema#",
3
+ "id" : "http://json-schema.org/draft-03/schema#",
4
+ "type" : "object",
5
+
6
+ "properties" : {
7
+ "type" : {
8
+ "type" : ["string", "array"],
9
+ "items" : {
10
+ "type" : ["string", {"$ref" : "#"}]
11
+ },
12
+ "uniqueItems" : true,
13
+ "default" : "any"
14
+ },
15
+
16
+ "properties" : {
17
+ "type" : "object",
18
+ "additionalProperties" : {"$ref" : "#"},
19
+ "default" : {}
20
+ },
21
+
22
+ "patternProperties" : {
23
+ "type" : "object",
24
+ "additionalProperties" : {"$ref" : "#"},
25
+ "default" : {}
26
+ },
27
+
28
+ "additionalProperties" : {
29
+ "type" : [{"$ref" : "#"}, "boolean"],
30
+ "default" : {}
31
+ },
32
+
33
+ "items" : {
34
+ "type" : [{"$ref" : "#"}, "array"],
35
+ "items" : {"$ref" : "#"},
36
+ "default" : {}
37
+ },
38
+
39
+ "additionalItems" : {
40
+ "type" : [{"$ref" : "#"}, "boolean"],
41
+ "default" : {}
42
+ },
43
+
44
+ "required" : {
45
+ "type" : "boolean",
46
+ "default" : false
47
+ },
48
+
49
+ "dependencies" : {
50
+ "type" : "object",
51
+ "additionalProperties" : {
52
+ "type" : ["string", "array", {"$ref" : "#"}],
53
+ "items" : {
54
+ "type" : "string"
55
+ }
56
+ },
57
+ "default" : {}
58
+ },
59
+
60
+ "minimum" : {
61
+ "type" : "number"
62
+ },
63
+
64
+ "maximum" : {
65
+ "type" : "number"
66
+ },
67
+
68
+ "exclusiveMinimum" : {
69
+ "type" : "boolean",
70
+ "default" : false
71
+ },
72
+
73
+ "exclusiveMaximum" : {
74
+ "type" : "boolean",
75
+ "default" : false
76
+ },
77
+
78
+ "minItems" : {
79
+ "type" : "integer",
80
+ "minimum" : 0,
81
+ "default" : 0
82
+ },
83
+
84
+ "maxItems" : {
85
+ "type" : "integer",
86
+ "minimum" : 0
87
+ },
88
+
89
+ "uniqueItems" : {
90
+ "type" : "boolean",
91
+ "default" : false
92
+ },
93
+
94
+ "pattern" : {
95
+ "type" : "string",
96
+ "format" : "regex"
97
+ },
98
+
99
+ "minLength" : {
100
+ "type" : "integer",
101
+ "minimum" : 0,
102
+ "default" : 0
103
+ },
104
+
105
+ "maxLength" : {
106
+ "type" : "integer"
107
+ },
108
+
109
+ "enum" : {
110
+ "type" : "array",
111
+ "minItems" : 1,
112
+ "uniqueItems" : true
113
+ },
114
+
115
+ "default" : {
116
+ "type" : "any"
117
+ },
118
+
119
+ "title" : {
120
+ "type" : "string"
121
+ },
122
+
123
+ "description" : {
124
+ "type" : "string"
125
+ },
126
+
127
+ "format" : {
128
+ "type" : "string"
129
+ },
130
+
131
+ "divisibleBy" : {
132
+ "type" : "number",
133
+ "minimum" : 0,
134
+ "exclusiveMinimum" : true,
135
+ "default" : 1
136
+ },
137
+
138
+ "disallow" : {
139
+ "type" : ["string", "array"],
140
+ "items" : {
141
+ "type" : ["string", {"$ref" : "#"}]
142
+ },
143
+ "uniqueItems" : true
144
+ },
145
+
146
+ "extends" : {
147
+ "type" : [{"$ref" : "#"}, "array"],
148
+ "items" : {"$ref" : "#"},
149
+ "default" : {}
150
+ },
151
+
152
+ "id" : {
153
+ "type" : "string",
154
+ "format" : "uri"
155
+ },
156
+
157
+ "$ref" : {
158
+ "type" : "string",
159
+ "format" : "uri"
160
+ },
161
+
162
+ "$schema" : {
163
+ "type" : "string",
164
+ "format" : "uri"
165
+ }
166
+ },
167
+
168
+ "dependencies" : {
169
+ "exclusiveMinimum" : "minimum",
170
+ "exclusiveMaximum" : "maximum"
171
+ },
172
+
173
+ "default" : {}
174
+ }