jsi 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -1
  3. data/CHANGELOG.md +33 -0
  4. data/LICENSE.md +1 -1
  5. data/README.md +29 -23
  6. data/jsi.gemspec +29 -0
  7. data/lib/jsi/base/mutability.rb +44 -0
  8. data/lib/jsi/base/node.rb +348 -0
  9. data/lib/jsi/base.rb +497 -339
  10. data/lib/jsi/jsi_coder.rb +19 -17
  11. data/lib/jsi/metaschema_node/bootstrap_schema.rb +61 -26
  12. data/lib/jsi/metaschema_node.rb +161 -133
  13. data/lib/jsi/ptr.rb +80 -47
  14. data/lib/jsi/schema/application/child_application/contains.rb +11 -2
  15. data/lib/jsi/schema/application/child_application/draft04.rb +0 -1
  16. data/lib/jsi/schema/application/child_application/draft06.rb +0 -1
  17. data/lib/jsi/schema/application/child_application/draft07.rb +0 -1
  18. data/lib/jsi/schema/application/child_application/items.rb +3 -3
  19. data/lib/jsi/schema/application/child_application/properties.rb +3 -3
  20. data/lib/jsi/schema/application/child_application.rb +0 -27
  21. data/lib/jsi/schema/application/inplace_application/dependencies.rb +1 -1
  22. data/lib/jsi/schema/application/inplace_application/draft04.rb +0 -1
  23. data/lib/jsi/schema/application/inplace_application/draft06.rb +0 -1
  24. data/lib/jsi/schema/application/inplace_application/draft07.rb +0 -1
  25. data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +3 -3
  26. data/lib/jsi/schema/application/inplace_application/ref.rb +2 -2
  27. data/lib/jsi/schema/application/inplace_application/someof.rb +26 -11
  28. data/lib/jsi/schema/application/inplace_application.rb +0 -32
  29. data/lib/jsi/schema/draft04.rb +0 -1
  30. data/lib/jsi/schema/draft06.rb +0 -1
  31. data/lib/jsi/schema/draft07.rb +0 -1
  32. data/lib/jsi/schema/ref.rb +46 -19
  33. data/lib/jsi/schema/schema_ancestor_node.rb +69 -66
  34. data/lib/jsi/schema/validation/array.rb +3 -3
  35. data/lib/jsi/schema/validation/const.rb +1 -1
  36. data/lib/jsi/schema/validation/contains.rb +2 -2
  37. data/lib/jsi/schema/validation/dependencies.rb +1 -1
  38. data/lib/jsi/schema/validation/draft04/minmax.rb +8 -6
  39. data/lib/jsi/schema/validation/draft04.rb +0 -2
  40. data/lib/jsi/schema/validation/draft06.rb +0 -2
  41. data/lib/jsi/schema/validation/draft07.rb +0 -2
  42. data/lib/jsi/schema/validation/enum.rb +1 -1
  43. data/lib/jsi/schema/validation/ifthenelse.rb +5 -5
  44. data/lib/jsi/schema/validation/items.rb +7 -7
  45. data/lib/jsi/schema/validation/not.rb +1 -1
  46. data/lib/jsi/schema/validation/numeric.rb +5 -5
  47. data/lib/jsi/schema/validation/object.rb +2 -2
  48. data/lib/jsi/schema/validation/pattern.rb +2 -2
  49. data/lib/jsi/schema/validation/properties.rb +7 -7
  50. data/lib/jsi/schema/validation/property_names.rb +1 -1
  51. data/lib/jsi/schema/validation/ref.rb +2 -2
  52. data/lib/jsi/schema/validation/required.rb +1 -1
  53. data/lib/jsi/schema/validation/someof.rb +3 -3
  54. data/lib/jsi/schema/validation/string.rb +2 -2
  55. data/lib/jsi/schema/validation/type.rb +1 -1
  56. data/lib/jsi/schema/validation.rb +1 -3
  57. data/lib/jsi/schema.rb +443 -226
  58. data/lib/jsi/schema_classes.rb +241 -147
  59. data/lib/jsi/schema_registry.rb +78 -19
  60. data/lib/jsi/schema_set.rb +114 -28
  61. data/lib/jsi/simple_wrap.rb +18 -4
  62. data/lib/jsi/util/private/attr_struct.rb +141 -0
  63. data/lib/jsi/util/private/memo_map.rb +75 -0
  64. data/lib/jsi/util/private.rb +185 -0
  65. data/lib/jsi/{typelike_modules.rb → util/typelike.rb} +79 -105
  66. data/lib/jsi/util.rb +157 -153
  67. data/lib/jsi/validation/error.rb +4 -0
  68. data/lib/jsi/validation/result.rb +18 -32
  69. data/lib/jsi/version.rb +1 -1
  70. data/lib/jsi.rb +65 -39
  71. data/lib/schemas/json-schema.org/draft-04/schema.rb +160 -3
  72. data/lib/schemas/json-schema.org/draft-06/schema.rb +162 -3
  73. data/lib/schemas/json-schema.org/draft-07/schema.rb +189 -3
  74. metadata +27 -11
  75. data/lib/jsi/metaschema.rb +0 -7
  76. data/lib/jsi/pathed_node.rb +0 -116
  77. data/lib/jsi/schema/validation/core.rb +0 -39
  78. data/lib/jsi/util/attr_struct.rb +0 -106
@@ -6,7 +6,7 @@ module JSI
6
6
  def internal_validate_properties(result_builder)
7
7
  evaluated_property_names = Set[]
8
8
 
9
- if schema_content.key?('properties')
9
+ if keyword?('properties')
10
10
  value = schema_content['properties']
11
11
  # The value of "properties" MUST be an object. Each value of this object MUST be a valid JSON Schema.
12
12
  if value.respond_to?(:to_hash)
@@ -19,8 +19,8 @@ module JSI
19
19
  if value.key?(property_name)
20
20
  evaluated_property_names << property_name
21
21
  results[property_name] = result_builder.child_subschema_validate(
22
+ property_name,
22
23
  ['properties', property_name],
23
- [property_name],
24
24
  )
25
25
  end
26
26
  end
@@ -36,7 +36,7 @@ module JSI
36
36
  end
37
37
  end
38
38
 
39
- if schema_content.key?('patternProperties')
39
+ if keyword?('patternProperties')
40
40
  value = schema_content['patternProperties']
41
41
  # The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a
42
42
  # valid regular expression, according to the ECMA 262 regular expression dialect. Each property value
@@ -54,8 +54,8 @@ module JSI
54
54
  if value_property_pattern.respond_to?(:to_str) && Regexp.new(value_property_pattern).match(property_name.to_s)
55
55
  evaluated_property_names << property_name
56
56
  results[property_name] = result_builder.child_subschema_validate(
57
+ property_name,
57
58
  ['patternProperties', value_property_pattern],
58
- [property_name],
59
59
  )
60
60
  end
61
61
  rescue ::RegexpError
@@ -75,7 +75,7 @@ module JSI
75
75
  end
76
76
  end
77
77
 
78
- if schema_content.key?('additionalProperties')
78
+ if keyword?('additionalProperties')
79
79
  value = schema_content['additionalProperties']
80
80
  # The value of "additionalProperties" MUST be a valid JSON Schema.
81
81
  if result_builder.instance.respond_to?(:to_hash)
@@ -83,11 +83,11 @@ module JSI
83
83
  result_builder.instance.keys.each do |property_name|
84
84
  if !evaluated_property_names.include?(property_name)
85
85
  results[property_name] = result_builder.child_subschema_validate(
86
+ property_name,
86
87
  ['additionalProperties'],
87
- [property_name],
88
88
  )
89
89
  end
90
- end.compact
90
+ end
91
91
  result_builder.validate(
92
92
  results.values.all?(&:valid?),
93
93
  'instance object additional properties are not all valid against `additionalProperties` schema value',
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::PropertyNames
5
5
  # @private
6
6
  def internal_validate_propertyNames(result_builder)
7
- if schema_content.key?('propertyNames')
7
+ if keyword?('propertyNames')
8
8
  # The value of "propertyNames" MUST be a valid JSON Schema.
9
9
  #
10
10
  # If the instance is an object, this keyword validates if every property name in the instance
@@ -6,11 +6,11 @@ module JSI
6
6
  # @param throw_result [Boolean] if a $ref is present, whether to throw the result being built after
7
7
  # validating the $ref, bypassing subsequent keyword validation
8
8
  def internal_validate_ref(result_builder, throw_result: false)
9
- if schema_content.key?('$ref')
9
+ if keyword?('$ref')
10
10
  value = schema_content['$ref']
11
11
 
12
12
  if value.respond_to?(:to_str)
13
- schema_ref = jsi_memoize(:ref) { Schema::Ref.new(value, self) }
13
+ schema_ref = self.schema_ref('$ref')
14
14
 
15
15
  if result_builder.visited_refs.include?(schema_ref)
16
16
  result_builder.schema_error('self-referential schema structure', '$ref')
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Required
5
5
  # @private
6
6
  def internal_validate_required(result_builder)
7
- if schema_content.key?('required')
7
+ if keyword?('required')
8
8
  value = schema_content['required']
9
9
  # The value of this keyword MUST be an array. Elements of this array, if any, MUST be strings, and MUST be unique.
10
10
  if value.respond_to?(:to_ary)
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::AllOf
5
5
  # @private
6
6
  def internal_validate_allOf(result_builder)
7
- if schema_content.key?('allOf')
7
+ if keyword?('allOf')
8
8
  value = schema_content['allOf']
9
9
  # This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
10
10
  if value.respond_to?(:to_ary)
@@ -29,7 +29,7 @@ module JSI
29
29
  module Schema::Validation::AnyOf
30
30
  # @private
31
31
  def internal_validate_anyOf(result_builder)
32
- if schema_content.key?('anyOf')
32
+ if keyword?('anyOf')
33
33
  value = schema_content['anyOf']
34
34
  # This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
35
35
  if value.respond_to?(:to_ary)
@@ -56,7 +56,7 @@ module JSI
56
56
  module Schema::Validation::OneOf
57
57
  # @private
58
58
  def internal_validate_oneOf(result_builder)
59
- if schema_content.key?('oneOf')
59
+ if keyword?('oneOf')
60
60
  value = schema_content['oneOf']
61
61
  # This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
62
62
  if value.respond_to?(:to_ary)
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::StringLength
5
5
  # @private
6
6
  def internal_validate_maxLength(result_builder)
7
- if schema_content.key?('maxLength')
7
+ if keyword?('maxLength')
8
8
  value = schema_content['maxLength']
9
9
  # The value of this keyword MUST be a non-negative integer.
10
10
  if internal_integer?(value) && value >= 0
@@ -25,7 +25,7 @@ module JSI
25
25
 
26
26
  # @private
27
27
  def internal_validate_minLength(result_builder)
28
- if schema_content.key?('minLength')
28
+ if keyword?('minLength')
29
29
  value = schema_content['minLength']
30
30
  # The value of this keyword MUST be a non-negative integer.
31
31
  if internal_integer?(value) && value >= 0
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Type
5
5
  # @private
6
6
  def internal_validate_type(result_builder)
7
- if schema_content.key?('type')
7
+ if keyword?('type')
8
8
  value = schema_content['type']
9
9
  instance = result_builder.instance
10
10
  # The value of this keyword MUST be either a string or an array. If it is an array, elements of
@@ -2,8 +2,6 @@
2
2
 
3
3
  module JSI
4
4
  module Schema::Validation
5
- autoload :Core, 'jsi/schema/validation/core'
6
-
7
5
  autoload :Draft04, 'jsi/schema/validation/draft04'
8
6
  autoload :Draft06, 'jsi/schema/validation/draft06'
9
7
  autoload :Draft07, 'jsi/schema/validation/draft07'
@@ -15,7 +13,6 @@ module JSI
15
13
  autoload :AllOf, 'jsi/schema/validation/someof'
16
14
  autoload :AnyOf, 'jsi/schema/validation/someof'
17
15
  autoload :OneOf, 'jsi/schema/validation/someof'
18
- autoload :Not, 'jsi/schema/validation/not'
19
16
  autoload :IfThenElse, 'jsi/schema/validation/ifthenelse'
20
17
 
21
18
  # child subschema application
@@ -30,6 +27,7 @@ module JSI
30
27
  autoload :Type, 'jsi/schema/validation/type'
31
28
  autoload :Enum, 'jsi/schema/validation/enum'
32
29
  autoload :Const, 'jsi/schema/validation/const'
30
+ autoload :Not, 'jsi/schema/validation/not'
33
31
 
34
32
  # object validation
35
33
  autoload :Required, 'jsi/schema/validation/required'