json-schema 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/lib/json-schema/attribute.rb +13 -14
  4. data/lib/json-schema/attributes/additionalitems.rb +1 -0
  5. data/lib/json-schema/attributes/additionalproperties.rb +3 -6
  6. data/lib/json-schema/attributes/allof.rb +2 -2
  7. data/lib/json-schema/attributes/anyof.rb +2 -2
  8. data/lib/json-schema/attributes/dependencies.rb +1 -0
  9. data/lib/json-schema/attributes/disallow.rb +2 -1
  10. data/lib/json-schema/attributes/enum.rb +2 -2
  11. data/lib/json-schema/attributes/extends.rb +6 -6
  12. data/lib/json-schema/attributes/format.rb +2 -1
  13. data/lib/json-schema/attributes/formats/date.rb +1 -0
  14. data/lib/json-schema/attributes/formats/date_time.rb +2 -1
  15. data/lib/json-schema/attributes/formats/date_time_v4.rb +1 -0
  16. data/lib/json-schema/attributes/formats/uri.rb +1 -0
  17. data/lib/json-schema/attributes/items.rb +1 -0
  18. data/lib/json-schema/attributes/limits/numeric.rb +1 -1
  19. data/lib/json-schema/attributes/maxdecimal.rb +1 -1
  20. data/lib/json-schema/attributes/not.rb +2 -2
  21. data/lib/json-schema/attributes/oneof.rb +2 -4
  22. data/lib/json-schema/attributes/patternproperties.rb +1 -0
  23. data/lib/json-schema/attributes/properties.rb +4 -4
  24. data/lib/json-schema/attributes/propertynames.rb +23 -0
  25. data/lib/json-schema/attributes/ref.rb +7 -7
  26. data/lib/json-schema/attributes/required.rb +3 -2
  27. data/lib/json-schema/attributes/type.rb +3 -2
  28. data/lib/json-schema/attributes/type_v4.rb +1 -1
  29. data/lib/json-schema/errors/validation_error.rb +4 -5
  30. data/lib/json-schema/schema/reader.rb +2 -0
  31. data/lib/json-schema/schema/validator.rb +3 -3
  32. data/lib/json-schema/schema.rb +3 -4
  33. data/lib/json-schema/util/array_set.rb +1 -1
  34. data/lib/json-schema/util/uri.rb +7 -7
  35. data/lib/json-schema/util/uuid.rb +227 -226
  36. data/lib/json-schema/validator.rb +84 -82
  37. data/lib/json-schema/validators/draft1.rb +21 -23
  38. data/lib/json-schema/validators/draft2.rb +22 -24
  39. data/lib/json-schema/validators/draft3.rb +26 -28
  40. data/lib/json-schema/validators/draft4.rb +34 -36
  41. data/lib/json-schema/validators/draft6.rb +36 -37
  42. data/lib/json-schema/validators/hyper-draft1.rb +2 -3
  43. data/lib/json-schema/validators/hyper-draft2.rb +2 -3
  44. data/lib/json-schema/validators/hyper-draft3.rb +2 -3
  45. data/lib/json-schema/validators/hyper-draft4.rb +2 -3
  46. data/lib/json-schema/validators/hyper-draft6.rb +2 -3
  47. data/lib/json-schema.rb +2 -2
  48. data/resources/draft-06.json +12 -12
  49. metadata +7 -6
@@ -2,55 +2,53 @@ require 'json-schema/schema/validator'
2
2
 
3
3
  module JSON
4
4
  class Schema
5
-
6
5
  class Draft4 < Validator
7
6
  def initialize
8
7
  super
9
8
  @attributes = {
10
- "type" => JSON::Schema::TypeV4Attribute,
11
- "allOf" => JSON::Schema::AllOfAttribute,
12
- "anyOf" => JSON::Schema::AnyOfAttribute,
13
- "oneOf" => JSON::Schema::OneOfAttribute,
14
- "not" => JSON::Schema::NotAttribute,
15
- "disallow" => JSON::Schema::DisallowAttribute,
16
- "format" => JSON::Schema::FormatAttribute,
17
- "maximum" => JSON::Schema::MaximumAttribute,
18
- "minimum" => JSON::Schema::MinimumAttribute,
19
- "minItems" => JSON::Schema::MinItemsAttribute,
20
- "maxItems" => JSON::Schema::MaxItemsAttribute,
21
- "minProperties" => JSON::Schema::MinPropertiesAttribute,
22
- "maxProperties" => JSON::Schema::MaxPropertiesAttribute,
23
- "uniqueItems" => JSON::Schema::UniqueItemsAttribute,
24
- "minLength" => JSON::Schema::MinLengthAttribute,
25
- "maxLength" => JSON::Schema::MaxLengthAttribute,
26
- "multipleOf" => JSON::Schema::MultipleOfAttribute,
27
- "enum" => JSON::Schema::EnumAttribute,
28
- "properties" => JSON::Schema::PropertiesV4Attribute,
29
- "required" => JSON::Schema::RequiredAttribute,
30
- "pattern" => JSON::Schema::PatternAttribute,
31
- "patternProperties" => JSON::Schema::PatternPropertiesAttribute,
32
- "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute,
33
- "items" => JSON::Schema::ItemsAttribute,
34
- "additionalItems" => JSON::Schema::AdditionalItemsAttribute,
35
- "dependencies" => JSON::Schema::DependenciesV4Attribute,
36
- "extends" => JSON::Schema::ExtendsAttribute,
37
- "$ref" => JSON::Schema::RefAttribute
9
+ 'type' => JSON::Schema::TypeV4Attribute,
10
+ 'allOf' => JSON::Schema::AllOfAttribute,
11
+ 'anyOf' => JSON::Schema::AnyOfAttribute,
12
+ 'oneOf' => JSON::Schema::OneOfAttribute,
13
+ 'not' => JSON::Schema::NotAttribute,
14
+ 'disallow' => JSON::Schema::DisallowAttribute,
15
+ 'format' => JSON::Schema::FormatAttribute,
16
+ 'maximum' => JSON::Schema::MaximumAttribute,
17
+ 'minimum' => JSON::Schema::MinimumAttribute,
18
+ 'minItems' => JSON::Schema::MinItemsAttribute,
19
+ 'maxItems' => JSON::Schema::MaxItemsAttribute,
20
+ 'minProperties' => JSON::Schema::MinPropertiesAttribute,
21
+ 'maxProperties' => JSON::Schema::MaxPropertiesAttribute,
22
+ 'uniqueItems' => JSON::Schema::UniqueItemsAttribute,
23
+ 'minLength' => JSON::Schema::MinLengthAttribute,
24
+ 'maxLength' => JSON::Schema::MaxLengthAttribute,
25
+ 'multipleOf' => JSON::Schema::MultipleOfAttribute,
26
+ 'enum' => JSON::Schema::EnumAttribute,
27
+ 'properties' => JSON::Schema::PropertiesV4Attribute,
28
+ 'required' => JSON::Schema::RequiredAttribute,
29
+ 'pattern' => JSON::Schema::PatternAttribute,
30
+ 'patternProperties' => JSON::Schema::PatternPropertiesAttribute,
31
+ 'additionalProperties' => JSON::Schema::AdditionalPropertiesAttribute,
32
+ 'items' => JSON::Schema::ItemsAttribute,
33
+ 'additionalItems' => JSON::Schema::AdditionalItemsAttribute,
34
+ 'dependencies' => JSON::Schema::DependenciesV4Attribute,
35
+ 'extends' => JSON::Schema::ExtendsAttribute,
36
+ '$ref' => JSON::Schema::RefAttribute,
38
37
  }
39
38
  @default_formats = {
40
39
  'date-time' => DateTimeV4Format,
41
40
  'ipv4' => IP4Format,
42
41
  'ipv6' => IP6Format,
43
- 'uri' => UriFormat
42
+ 'uri' => UriFormat,
44
43
  }
45
44
  @formats = @default_formats.clone
46
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft-04/schema#")
47
- @names = ["draft4", "http://json-schema.org/draft-04/schema#"]
48
- @metaschema_name = "draft-04.json"
45
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-04/schema#')
46
+ @names = ['draft4', 'http://json-schema.org/draft-04/schema#']
47
+ @metaschema_name = 'draft-04.json'
49
48
  end
50
49
 
51
- JSON::Validator.register_validator(self.new)
52
- JSON::Validator.register_default_validator(self.new)
50
+ JSON::Validator.register_validator(new)
51
+ JSON::Validator.register_default_validator(new)
53
52
  end
54
-
55
53
  end
56
54
  end
@@ -2,56 +2,55 @@ require 'json-schema/schema/validator'
2
2
 
3
3
  module JSON
4
4
  class Schema
5
-
6
5
  class Draft6 < Validator
7
6
  def initialize
8
7
  super
9
8
  @attributes = {
10
- "type" => JSON::Schema::TypeV4Attribute,
11
- "allOf" => JSON::Schema::AllOfAttribute,
12
- "anyOf" => JSON::Schema::AnyOfAttribute,
13
- "oneOf" => JSON::Schema::OneOfAttribute,
14
- "not" => JSON::Schema::NotAttribute,
15
- "disallow" => JSON::Schema::DisallowAttribute,
16
- "format" => JSON::Schema::FormatAttribute,
17
- "maximum" => JSON::Schema::MaximumAttribute,
18
- "minimum" => JSON::Schema::MinimumAttribute,
19
- "minItems" => JSON::Schema::MinItemsAttribute,
20
- "maxItems" => JSON::Schema::MaxItemsAttribute,
21
- "minProperties" => JSON::Schema::MinPropertiesAttribute,
22
- "maxProperties" => JSON::Schema::MaxPropertiesAttribute,
23
- "uniqueItems" => JSON::Schema::UniqueItemsAttribute,
24
- "minLength" => JSON::Schema::MinLengthAttribute,
25
- "maxLength" => JSON::Schema::MaxLengthAttribute,
26
- "multipleOf" => JSON::Schema::MultipleOfAttribute,
27
- "enum" => JSON::Schema::EnumAttribute,
28
- "properties" => JSON::Schema::PropertiesV4Attribute,
29
- "required" => JSON::Schema::RequiredAttribute,
30
- "pattern" => JSON::Schema::PatternAttribute,
31
- "patternProperties" => JSON::Schema::PatternPropertiesAttribute,
32
- "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute,
33
- "items" => JSON::Schema::ItemsAttribute,
34
- "additionalItems" => JSON::Schema::AdditionalItemsAttribute,
35
- "dependencies" => JSON::Schema::DependenciesV4Attribute,
36
- "extends" => JSON::Schema::ExtendsAttribute,
37
- "const" => JSON::Schema::ConstAttribute,
38
- "$ref" => JSON::Schema::RefAttribute
9
+ 'type' => JSON::Schema::TypeV4Attribute,
10
+ 'allOf' => JSON::Schema::AllOfAttribute,
11
+ 'anyOf' => JSON::Schema::AnyOfAttribute,
12
+ 'oneOf' => JSON::Schema::OneOfAttribute,
13
+ 'not' => JSON::Schema::NotAttribute,
14
+ 'disallow' => JSON::Schema::DisallowAttribute,
15
+ 'format' => JSON::Schema::FormatAttribute,
16
+ 'maximum' => JSON::Schema::MaximumAttribute,
17
+ 'minimum' => JSON::Schema::MinimumAttribute,
18
+ 'minItems' => JSON::Schema::MinItemsAttribute,
19
+ 'maxItems' => JSON::Schema::MaxItemsAttribute,
20
+ 'minProperties' => JSON::Schema::MinPropertiesAttribute,
21
+ 'maxProperties' => JSON::Schema::MaxPropertiesAttribute,
22
+ 'uniqueItems' => JSON::Schema::UniqueItemsAttribute,
23
+ 'minLength' => JSON::Schema::MinLengthAttribute,
24
+ 'maxLength' => JSON::Schema::MaxLengthAttribute,
25
+ 'multipleOf' => JSON::Schema::MultipleOfAttribute,
26
+ 'enum' => JSON::Schema::EnumAttribute,
27
+ 'properties' => JSON::Schema::PropertiesV4Attribute,
28
+ 'required' => JSON::Schema::RequiredAttribute,
29
+ 'pattern' => JSON::Schema::PatternAttribute,
30
+ 'patternProperties' => JSON::Schema::PatternPropertiesAttribute,
31
+ 'additionalProperties' => JSON::Schema::AdditionalPropertiesAttribute,
32
+ 'items' => JSON::Schema::ItemsAttribute,
33
+ 'additionalItems' => JSON::Schema::AdditionalItemsAttribute,
34
+ 'dependencies' => JSON::Schema::DependenciesV4Attribute,
35
+ 'extends' => JSON::Schema::ExtendsAttribute,
36
+ 'const' => JSON::Schema::ConstAttribute,
37
+ '$ref' => JSON::Schema::RefAttribute,
38
+ 'propertyNames' => JSON::Schema::PropertyNames,
39
39
  }
40
40
  @default_formats = {
41
41
  'date-time' => DateTimeV4Format,
42
42
  'ipv4' => IP4Format,
43
43
  'ipv6' => IP6Format,
44
- 'uri' => UriFormat
44
+ 'uri' => UriFormat,
45
45
  }
46
46
  @formats = @default_formats.clone
47
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft/schema#")
48
- @names = ["draft6", "http://json-schema.org/draft/schema#"]
49
- @metaschema_name = "draft-06.json"
47
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-06/schema#')
48
+ @names = ['draft6', 'http://json-schema.org/draft-06/schema#']
49
+ @metaschema_name = 'draft-06.json'
50
50
  end
51
51
 
52
- JSON::Validator.register_validator(self.new)
53
- JSON::Validator.register_default_validator(self.new)
52
+ JSON::Validator.register_validator(new)
53
+ JSON::Validator.register_default_validator(new)
54
54
  end
55
-
56
55
  end
57
56
  end
@@ -1,13 +1,12 @@
1
1
  module JSON
2
2
  class Schema
3
-
4
3
  class HyperDraft1 < Draft1
5
4
  def initialize
6
5
  super
7
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft-01/hyper-schema#")
6
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-01/hyper-schema#')
8
7
  end
9
8
 
10
- JSON::Validator.register_validator(self.new)
9
+ JSON::Validator.register_validator(new)
11
10
  end
12
11
  end
13
12
  end
@@ -1,13 +1,12 @@
1
1
  module JSON
2
2
  class Schema
3
-
4
3
  class HyperDraft2 < Draft2
5
4
  def initialize
6
5
  super
7
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft-02/hyper-schema#")
6
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-02/hyper-schema#')
8
7
  end
9
8
 
10
- JSON::Validator.register_validator(self.new)
9
+ JSON::Validator.register_validator(new)
11
10
  end
12
11
  end
13
12
  end
@@ -1,13 +1,12 @@
1
1
  module JSON
2
2
  class Schema
3
-
4
3
  class HyperDraft3 < Draft3
5
4
  def initialize
6
5
  super
7
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft-03/hyper-schema#")
6
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-03/hyper-schema#')
8
7
  end
9
8
 
10
- JSON::Validator.register_validator(self.new)
9
+ JSON::Validator.register_validator(new)
11
10
  end
12
11
  end
13
12
  end
@@ -1,13 +1,12 @@
1
1
  module JSON
2
2
  class Schema
3
-
4
3
  class HyperDraft4 < Draft4
5
4
  def initialize
6
5
  super
7
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft-04/hyper-schema#")
6
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-04/hyper-schema#')
8
7
  end
9
8
 
10
- JSON::Validator.register_validator(self.new)
9
+ JSON::Validator.register_validator(new)
11
10
  end
12
11
  end
13
12
  end
@@ -1,13 +1,12 @@
1
1
  module JSON
2
2
  class Schema
3
-
4
3
  class HyperDraft6 < Draft6
5
4
  def initialize
6
5
  super
7
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft-06/hyper-schema#")
6
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-06/hyper-schema#')
8
7
  end
9
8
 
10
- JSON::Validator.register_validator(self.new)
9
+ JSON::Validator.register_validator(new)
11
10
  end
12
11
  end
13
12
  end
data/lib/json-schema.rb CHANGED
@@ -14,5 +14,5 @@ require 'json-schema/schema'
14
14
  require 'json-schema/schema/reader'
15
15
  require 'json-schema/validator'
16
16
 
17
- Dir[File.join(File.dirname(__FILE__), "json-schema/attributes/**/*.rb")].each {|file| require file }
18
- Dir[File.join(File.dirname(__FILE__), "json-schema/validators/*.rb")].sort!.each {|file| require file }
17
+ Dir[File.join(File.dirname(__FILE__), 'json-schema/attributes/**/*.rb')].each { |file| require file }
18
+ Dir[File.join(File.dirname(__FILE__), 'json-schema/validators/*.rb')].sort!.each { |file| require file }
@@ -1,6 +1,6 @@
1
1
  {
2
- "$schema": "http://json-schema.org/draft/schema#",
3
- "$id": "http://json-schema.org/draft/schema#",
2
+ "$schema": "http://json-schema.org/draft-06/schema#",
3
+ "$id": "http://json-schema.org/draft-06/schema#",
4
4
  "title": "Core schema meta-schema",
5
5
  "definitions": {
6
6
  "schemaArray": {
@@ -8,13 +8,13 @@
8
8
  "minItems": 1,
9
9
  "items": { "$ref": "#" }
10
10
  },
11
- "positiveInteger": {
11
+ "nonNegativeInteger": {
12
12
  "type": "integer",
13
13
  "minimum": 0
14
14
  },
15
- "positiveIntegerDefault0": {
15
+ "nonNegativeIntegerDefault0": {
16
16
  "allOf": [
17
- { "$ref": "#/definitions/positiveInteger" },
17
+ { "$ref": "#/definitions/nonNegativeInteger" },
18
18
  { "default": 0 }
19
19
  ]
20
20
  },
@@ -33,7 +33,7 @@
33
33
  "type": "array",
34
34
  "items": { "type": "string" },
35
35
  "uniqueItems": true,
36
- "defaultItems": []
36
+ "default": []
37
37
  }
38
38
  },
39
39
  "type": ["object", "boolean"],
@@ -73,8 +73,8 @@
73
73
  "exclusiveMinimum": {
74
74
  "type": "number"
75
75
  },
76
- "maxLength": { "$ref": "#/definitions/positiveInteger" },
77
- "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
76
+ "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
77
+ "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
78
78
  "pattern": {
79
79
  "type": "string",
80
80
  "format": "regex"
@@ -87,15 +87,15 @@
87
87
  ],
88
88
  "default": {}
89
89
  },
90
- "maxItems": { "$ref": "#/definitions/positiveInteger" },
91
- "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
90
+ "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
91
+ "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
92
92
  "uniqueItems": {
93
93
  "type": "boolean",
94
94
  "default": false
95
95
  },
96
96
  "contains": { "$ref": "#" },
97
- "maxProperties": { "$ref": "#/definitions/positiveInteger" },
98
- "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
97
+ "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
98
+ "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
99
99
  "required": { "$ref": "#/definitions/stringArray" },
100
100
  "additionalProperties": { "$ref": "#" },
101
101
  "definitions": {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenny Hoxworth
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-03 00:00:00.000000000 Z
12
+ date: 2023-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rake
15
+ name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '5.0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: webmock
43
+ name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: bundler
57
+ name: webmock
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -137,6 +137,7 @@ files:
137
137
  - lib/json-schema/attributes/properties.rb
138
138
  - lib/json-schema/attributes/properties_optional.rb
139
139
  - lib/json-schema/attributes/properties_v4.rb
140
+ - lib/json-schema/attributes/propertynames.rb
140
141
  - lib/json-schema/attributes/ref.rb
141
142
  - lib/json-schema/attributes/required.rb
142
143
  - lib/json-schema/attributes/type.rb
@@ -190,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  - !ruby/object:Gem::Version
191
192
  version: '2.5'
192
193
  requirements: []
193
- rubygems_version: 3.3.7
194
+ rubygems_version: 3.3.26
194
195
  signing_key:
195
196
  specification_version: 4
196
197
  summary: Ruby JSON Schema Validator