jsi 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +11 -6
  5. data/jsi.gemspec +30 -0
  6. data/lib/jsi/base/node.rb +183 -0
  7. data/lib/jsi/base.rb +135 -161
  8. data/lib/jsi/jsi_coder.rb +3 -3
  9. data/lib/jsi/metaschema.rb +0 -1
  10. data/lib/jsi/metaschema_node/bootstrap_schema.rb +9 -8
  11. data/lib/jsi/metaschema_node.rb +48 -51
  12. data/lib/jsi/ptr.rb +28 -17
  13. data/lib/jsi/schema/application/child_application/contains.rb +11 -2
  14. data/lib/jsi/schema/application/child_application/items.rb +3 -3
  15. data/lib/jsi/schema/application/child_application/properties.rb +3 -3
  16. data/lib/jsi/schema/application/child_application.rb +1 -3
  17. data/lib/jsi/schema/application/inplace_application/dependencies.rb +1 -1
  18. data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +3 -3
  19. data/lib/jsi/schema/application/inplace_application/ref.rb +1 -1
  20. data/lib/jsi/schema/application/inplace_application/someof.rb +26 -11
  21. data/lib/jsi/schema/application/inplace_application.rb +1 -6
  22. data/lib/jsi/schema/ref.rb +3 -2
  23. data/lib/jsi/schema/schema_ancestor_node.rb +11 -17
  24. data/lib/jsi/schema/validation/array.rb +3 -3
  25. data/lib/jsi/schema/validation/const.rb +1 -1
  26. data/lib/jsi/schema/validation/contains.rb +1 -1
  27. data/lib/jsi/schema/validation/dependencies.rb +1 -1
  28. data/lib/jsi/schema/validation/draft04/minmax.rb +6 -6
  29. data/lib/jsi/schema/validation/enum.rb +1 -1
  30. data/lib/jsi/schema/validation/ifthenelse.rb +5 -5
  31. data/lib/jsi/schema/validation/items.rb +4 -4
  32. data/lib/jsi/schema/validation/not.rb +1 -1
  33. data/lib/jsi/schema/validation/numeric.rb +5 -5
  34. data/lib/jsi/schema/validation/object.rb +2 -2
  35. data/lib/jsi/schema/validation/pattern.rb +1 -1
  36. data/lib/jsi/schema/validation/properties.rb +3 -3
  37. data/lib/jsi/schema/validation/property_names.rb +1 -1
  38. data/lib/jsi/schema/validation/ref.rb +1 -1
  39. data/lib/jsi/schema/validation/required.rb +1 -1
  40. data/lib/jsi/schema/validation/someof.rb +3 -3
  41. data/lib/jsi/schema/validation/string.rb +2 -2
  42. data/lib/jsi/schema/validation/type.rb +1 -1
  43. data/lib/jsi/schema/validation.rb +1 -1
  44. data/lib/jsi/schema.rb +91 -85
  45. data/lib/jsi/schema_classes.rb +70 -45
  46. data/lib/jsi/schema_registry.rb +15 -5
  47. data/lib/jsi/schema_set.rb +42 -2
  48. data/lib/jsi/simple_wrap.rb +23 -4
  49. data/lib/jsi/util/{attr_struct.rb → private/attr_struct.rb} +40 -19
  50. data/lib/jsi/util/private.rb +204 -0
  51. data/lib/jsi/{typelike_modules.rb → util/typelike.rb} +56 -82
  52. data/lib/jsi/util.rb +68 -148
  53. data/lib/jsi/version.rb +1 -1
  54. data/lib/jsi.rb +1 -17
  55. data/lib/schemas/json-schema.org/draft-04/schema.rb +3 -1
  56. data/lib/schemas/json-schema.org/draft-06/schema.rb +3 -1
  57. data/lib/schemas/json-schema.org/draft-07/schema.rb +3 -1
  58. metadata +11 -9
  59. data/lib/jsi/pathed_node.rb +0 -116
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Const
5
5
  # @private
6
6
  def internal_validate_const(result_builder)
7
- if schema_content.key?('const')
7
+ if keyword?('const')
8
8
  value = schema_content['const']
9
9
  # The value of this keyword MAY be of any type, including null.
10
10
  # An instance validates successfully against this keyword if its value is equal to the value of
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Contains
5
5
  # @private
6
6
  def internal_validate_contains(result_builder)
7
- if schema_content.key?('contains')
7
+ if keyword?('contains')
8
8
  # An array instance is valid against "contains" if at least one of its elements is valid against
9
9
  # the given schema.
10
10
  if result_builder.instance.respond_to?(:to_ary)
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Dependencies
5
5
  # @private
6
6
  def internal_validate_dependencies(result_builder)
7
- if schema_content.key?('dependencies')
7
+ if keyword?('dependencies')
8
8
  value = schema_content['dependencies']
9
9
  # This keyword's value MUST be an object. Each property specifies a dependency. Each dependency
10
10
  # value MUST be an array or a valid JSON Schema.
@@ -4,18 +4,18 @@ module JSI
4
4
  module Schema::Validation::Draft04::MinMax
5
5
  # @private
6
6
  def internal_validate_maximum(result_builder)
7
- if schema_content.key?('exclusiveMaximum')
7
+ if keyword?('exclusiveMaximum')
8
8
  value = schema_content['exclusiveMaximum']
9
9
  # The value of "exclusiveMaximum" MUST be a boolean.
10
10
  unless [true, false].include?(value)
11
11
  result_builder.schema_error('`exclusiveMaximum` is not true or false', 'exclusiveMaximum')
12
12
  end
13
- if !schema_content.key?('maximum')
13
+ if !keyword?('maximum')
14
14
  result_builder.schema_error('`exclusiveMaximum` has no effect without adjacent `maximum` keyword', 'exclusiveMaximum')
15
15
  end
16
16
  end
17
17
 
18
- if schema_content.key?('maximum')
18
+ if keyword?('maximum')
19
19
  value = schema_content['maximum']
20
20
  # The value of "maximum" MUST be a JSON number.
21
21
  if value.is_a?(Numeric)
@@ -47,18 +47,18 @@ module JSI
47
47
 
48
48
  # @private
49
49
  def internal_validate_minimum(result_builder)
50
- if schema_content.key?('exclusiveMinimum')
50
+ if keyword?('exclusiveMinimum')
51
51
  value = schema_content['exclusiveMinimum']
52
52
  # The value of "exclusiveMinimum" MUST be a boolean.
53
53
  unless [true, false].include?(value)
54
54
  result_builder.schema_error('`exclusiveMinimum` is not true or false', 'exclusiveMinimum')
55
55
  end
56
- if !schema_content.key?('minimum')
56
+ if !keyword?('minimum')
57
57
  result_builder.schema_error('`exclusiveMinimum` has no effect without adjacent `minimum` keyword', 'exclusiveMinimum')
58
58
  end
59
59
  end
60
60
 
61
- if schema_content.key?('minimum')
61
+ if keyword?('minimum')
62
62
  value = schema_content['minimum']
63
63
  # The value of "minimum" MUST be a JSON number.
64
64
  if value.is_a?(Numeric)
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Enum
5
5
  # @private
6
6
  def internal_validate_enum(result_builder)
7
- if schema_content.key?('enum')
7
+ if keyword?('enum')
8
8
  value = schema_content['enum']
9
9
  # The value of this keyword MUST be an array. This array SHOULD have at least one element.
10
10
  # Elements in the array SHOULD be unique.
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::IfThenElse
5
5
  # @private
6
6
  def internal_validate_ifthenelse(result_builder)
7
- if schema_content.key?('if')
7
+ if keyword?('if')
8
8
  # This keyword's value MUST be a valid JSON Schema.
9
9
  # This validation outcome of this keyword's subschema has no direct effect on the overall validation
10
10
  # result. Rather, it controls which of the "then" or "else" keywords are evaluated.
@@ -13,7 +13,7 @@ module JSI
13
13
  result_builder.merge_schema_issues(if_result)
14
14
 
15
15
  if if_result.valid?
16
- if schema_content.key?('then')
16
+ if keyword?('then')
17
17
  then_result = result_builder.inplace_subschema_validate(['then'])
18
18
  result_builder.validate(
19
19
  then_result.valid?,
@@ -23,7 +23,7 @@ module JSI
23
23
  )
24
24
  end
25
25
  else
26
- if schema_content.key?('else')
26
+ if keyword?('else')
27
27
  else_result = result_builder.inplace_subschema_validate(['else'])
28
28
  result_builder.validate(
29
29
  else_result.valid?,
@@ -34,10 +34,10 @@ module JSI
34
34
  end
35
35
  end
36
36
  else
37
- if schema_content.key?('then')
37
+ if keyword?('then')
38
38
  result_builder.schema_warning('`then` has no effect without adjacent `if` keyword', 'then')
39
39
  end
40
- if schema_content.key?('else')
40
+ if keyword?('else')
41
41
  result_builder.schema_warning('`else` has no effect without adjacent `if` keyword', 'else')
42
42
  end
43
43
  end
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Items
5
5
  # @private
6
6
  def internal_validate_items(result_builder)
7
- if schema_content.key?('items')
7
+ if keyword?('items')
8
8
  value = schema_content['items']
9
9
  # The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas.
10
10
  if value.respond_to?(:to_ary)
@@ -15,7 +15,7 @@ module JSI
15
15
  result_builder.instance.each_index do |i|
16
16
  if i < value.size
17
17
  results[i] = result_builder.child_subschema_validate(['items', i], [i])
18
- elsif schema_content.key?('additionalItems')
18
+ elsif keyword?('additionalItems')
19
19
  results[i] = result_builder.child_subschema_validate(['additionalItems'], [i])
20
20
  end
21
21
  end
@@ -40,12 +40,12 @@ module JSI
40
40
  results: results,
41
41
  )
42
42
  end
43
- if schema_content.key?('additionalItems')
43
+ if keyword?('additionalItems')
44
44
  result_builder.schema_warning('`additionalItems` has no effect when adjacent `items` keyword is not an array', 'items')
45
45
  end
46
46
  end
47
47
  else
48
- if schema_content.key?('additionalItems')
48
+ if keyword?('additionalItems')
49
49
  result_builder.schema_warning('`additionalItems` has no effect without adjacent `items` keyword', 'items')
50
50
  end
51
51
  end
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Not
5
5
  # @private
6
6
  def internal_validate_not(result_builder)
7
- if schema_content.key?('not')
7
+ if keyword?('not')
8
8
  # This keyword's value MUST be a valid JSON Schema.
9
9
  # An instance is valid against this keyword if it fails to validate successfully against the schema
10
10
  # defined by this keyword.
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::MultipleOf
5
5
  # @private
6
6
  def internal_validate_multipleOf(result_builder)
7
- if schema_content.key?('multipleOf')
7
+ if keyword?('multipleOf')
8
8
  value = schema_content['multipleOf']
9
9
  # The value of "multipleOf" MUST be a number, strictly greater than 0.
10
10
  if value.is_a?(Numeric) && value > 0
@@ -36,7 +36,7 @@ module JSI
36
36
  module Schema::Validation::MinMax
37
37
  # @private
38
38
  def internal_validate_maximum(result_builder)
39
- if schema_content.key?('maximum')
39
+ if keyword?('maximum')
40
40
  value = schema_content['maximum']
41
41
  # The value of "maximum" MUST be a number, representing an inclusive upper limit for a numeric instance.
42
42
  if value.is_a?(Numeric)
@@ -57,7 +57,7 @@ module JSI
57
57
 
58
58
  # @private
59
59
  def internal_validate_exclusiveMaximum(result_builder)
60
- if schema_content.key?('exclusiveMaximum')
60
+ if keyword?('exclusiveMaximum')
61
61
  value = schema_content['exclusiveMaximum']
62
62
  # The value of "exclusiveMaximum" MUST be number, representing an exclusive upper limit for a numeric instance.
63
63
  if value.is_a?(Numeric)
@@ -78,7 +78,7 @@ module JSI
78
78
 
79
79
  # @private
80
80
  def internal_validate_minimum(result_builder)
81
- if schema_content.key?('minimum')
81
+ if keyword?('minimum')
82
82
  value = schema_content['minimum']
83
83
  # The value of "minimum" MUST be a number, representing an inclusive lower limit for a numeric instance.
84
84
  if value.is_a?(Numeric)
@@ -99,7 +99,7 @@ module JSI
99
99
 
100
100
  # @private
101
101
  def internal_validate_exclusiveMinimum(result_builder)
102
- if schema_content.key?('exclusiveMinimum')
102
+ if keyword?('exclusiveMinimum')
103
103
  value = schema_content['exclusiveMinimum']
104
104
  # The value of "exclusiveMinimum" MUST be number, representing an exclusive lower limit for a numeric instance.
105
105
  if value.is_a?(Numeric)
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::MinMaxProperties
5
5
  # @private
6
6
  def internal_validate_maxProperties(result_builder)
7
- if schema_content.key?('maxProperties')
7
+ if keyword?('maxProperties')
8
8
  value = schema_content['maxProperties']
9
9
  # The value of this keyword MUST be a non-negative integer.
10
10
  if internal_integer?(value) && value >= 0
@@ -24,7 +24,7 @@ module JSI
24
24
 
25
25
  # @private
26
26
  def internal_validate_minProperties(result_builder)
27
- if schema_content.key?('minProperties')
27
+ if keyword?('minProperties')
28
28
  value = schema_content['minProperties']
29
29
  # The value of this keyword MUST be a non-negative integer.
30
30
  if internal_integer?(value) && value >= 0
@@ -4,7 +4,7 @@ module JSI
4
4
  module Schema::Validation::Pattern
5
5
  # @private
6
6
  def internal_validate_pattern(result_builder)
7
- if schema_content.key?('pattern')
7
+ if keyword?('pattern')
8
8
  value = schema_content['pattern']
9
9
  # The value of this keyword MUST be a string.
10
10
  if value.respond_to?(:to_str)
@@ -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)
@@ -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
@@ -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)
@@ -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,7 +6,7 @@ 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)
@@ -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
@@ -15,7 +15,6 @@ module JSI
15
15
  autoload :AllOf, 'jsi/schema/validation/someof'
16
16
  autoload :AnyOf, 'jsi/schema/validation/someof'
17
17
  autoload :OneOf, 'jsi/schema/validation/someof'
18
- autoload :Not, 'jsi/schema/validation/not'
19
18
  autoload :IfThenElse, 'jsi/schema/validation/ifthenelse'
20
19
 
21
20
  # child subschema application
@@ -30,6 +29,7 @@ module JSI
30
29
  autoload :Type, 'jsi/schema/validation/type'
31
30
  autoload :Enum, 'jsi/schema/validation/enum'
32
31
  autoload :Const, 'jsi/schema/validation/const'
32
+ autoload :Not, 'jsi/schema/validation/not'
33
33
 
34
34
  # object validation
35
35
  autoload :Required, 'jsi/schema/validation/required'