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,43 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/json-schema'
3
+
4
+ class JSONSchemaValidation < Test::Unit::TestCase
5
+ def valid_schema
6
+ {
7
+ "$schema" => "http://json-schema.org/draft-03/schema#",
8
+ "type" => "object",
9
+ "properties" => {
10
+ "b" => {
11
+ "required" => true
12
+ }
13
+ }
14
+ }
15
+ end
16
+
17
+ def invalid_schema
18
+ {
19
+ "$schema" => "http://json-schema.org/draft-03/schema#",
20
+ "type" => "object",
21
+ "properties" => {
22
+ "b" => {
23
+ "required" => "true"
24
+ }
25
+ }
26
+ }
27
+ end
28
+
29
+ def test_draft03_validation
30
+ data = {"b" => {"a" => 5}}
31
+ assert(JSON::Validator.validate(valid_schema,data,:validate_schema => true))
32
+ assert(!JSON::Validator.validate(invalid_schema,data,:validate_schema => true))
33
+ end
34
+
35
+ def test_validate_just_schema
36
+ errors = JSON::Validator.fully_validate_schema(valid_schema)
37
+ assert_equal [], errors
38
+
39
+ errors = JSON::Validator.fully_validate_schema(invalid_schema)
40
+ assert_equal 1, errors.size
41
+ assert_match /the property .*required.*did not match/i, errors.first
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seomoz-json-schema
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Kenny Hoxworth
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-13 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: multi_json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 31
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 4
33
+ version: 1.0.4
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description:
37
+ email: hoxworth@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.textile
44
+ files:
45
+ - lib/json-schema/attributes/additionalitems.rb
46
+ - lib/json-schema/attributes/additionalproperties.rb
47
+ - lib/json-schema/attributes/dependencies.rb
48
+ - lib/json-schema/attributes/disallow.rb
49
+ - lib/json-schema/attributes/divisibleby.rb
50
+ - lib/json-schema/attributes/enum.rb
51
+ - lib/json-schema/attributes/extends.rb
52
+ - lib/json-schema/attributes/format.rb
53
+ - lib/json-schema/attributes/items.rb
54
+ - lib/json-schema/attributes/maxdecimal.rb
55
+ - lib/json-schema/attributes/maximum.rb
56
+ - lib/json-schema/attributes/maximum_inclusive.rb
57
+ - lib/json-schema/attributes/maxitems.rb
58
+ - lib/json-schema/attributes/maxlength.rb
59
+ - lib/json-schema/attributes/minimum.rb
60
+ - lib/json-schema/attributes/minimum_inclusive.rb
61
+ - lib/json-schema/attributes/minitems.rb
62
+ - lib/json-schema/attributes/minlength.rb
63
+ - lib/json-schema/attributes/pattern.rb
64
+ - lib/json-schema/attributes/patternproperties.rb
65
+ - lib/json-schema/attributes/properties.rb
66
+ - lib/json-schema/attributes/properties_optional.rb
67
+ - lib/json-schema/attributes/ref.rb
68
+ - lib/json-schema/attributes/type.rb
69
+ - lib/json-schema/attributes/uniqueitems.rb
70
+ - lib/json-schema/schema.rb
71
+ - lib/json-schema/uri/file.rb
72
+ - lib/json-schema/uri/uuid.rb
73
+ - lib/json-schema/validator.rb
74
+ - lib/json-schema/validators/draft1.rb
75
+ - lib/json-schema/validators/draft2.rb
76
+ - lib/json-schema/validators/draft3.rb
77
+ - lib/json-schema.rb
78
+ - resources/draft-01.json
79
+ - resources/draft-02.json
80
+ - resources/draft-03.json
81
+ - README.textile
82
+ - test/test_extended_schema.rb
83
+ - test/test_files.rb
84
+ - test/test_full_validation.rb
85
+ - test/test_jsonschema_draft1.rb
86
+ - test/test_jsonschema_draft2.rb
87
+ - test/test_jsonschema_draft3.rb
88
+ - test/test_schema_validation.rb
89
+ - test/data/bad_data_1.json
90
+ - test/data/good_data_1.json
91
+ - test/schemas/good_schema_1.json
92
+ - test/schemas/good_schema_2.json
93
+ homepage: http://github.com/hoxworth/json-schema/tree/master
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.6
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Ruby JSON Schema Validator
126
+ test_files:
127
+ - test/test_extended_schema.rb
128
+ - test/test_files.rb
129
+ - test/test_full_validation.rb
130
+ - test/test_jsonschema_draft1.rb
131
+ - test/test_jsonschema_draft2.rb
132
+ - test/test_jsonschema_draft3.rb
133
+ - test/test_schema_validation.rb
134
+ - test/data/bad_data_1.json
135
+ - test/data/good_data_1.json
136
+ - test/schemas/good_schema_1.json
137
+ - test/schemas/good_schema_2.json