jsi 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/LICENSE.md +1 -1
- data/README.md +11 -6
- data/jsi.gemspec +30 -0
- data/lib/jsi/base/node.rb +183 -0
- data/lib/jsi/base.rb +135 -161
- data/lib/jsi/jsi_coder.rb +3 -3
- data/lib/jsi/metaschema.rb +0 -1
- data/lib/jsi/metaschema_node/bootstrap_schema.rb +9 -8
- data/lib/jsi/metaschema_node.rb +48 -51
- data/lib/jsi/ptr.rb +28 -17
- data/lib/jsi/schema/application/child_application/contains.rb +11 -2
- data/lib/jsi/schema/application/child_application/items.rb +3 -3
- data/lib/jsi/schema/application/child_application/properties.rb +3 -3
- data/lib/jsi/schema/application/child_application.rb +1 -3
- data/lib/jsi/schema/application/inplace_application/dependencies.rb +1 -1
- data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +3 -3
- data/lib/jsi/schema/application/inplace_application/ref.rb +1 -1
- data/lib/jsi/schema/application/inplace_application/someof.rb +26 -11
- data/lib/jsi/schema/application/inplace_application.rb +1 -6
- data/lib/jsi/schema/ref.rb +3 -2
- data/lib/jsi/schema/schema_ancestor_node.rb +11 -17
- data/lib/jsi/schema/validation/array.rb +3 -3
- data/lib/jsi/schema/validation/const.rb +1 -1
- data/lib/jsi/schema/validation/contains.rb +1 -1
- data/lib/jsi/schema/validation/dependencies.rb +1 -1
- data/lib/jsi/schema/validation/draft04/minmax.rb +6 -6
- data/lib/jsi/schema/validation/enum.rb +1 -1
- data/lib/jsi/schema/validation/ifthenelse.rb +5 -5
- data/lib/jsi/schema/validation/items.rb +4 -4
- data/lib/jsi/schema/validation/not.rb +1 -1
- data/lib/jsi/schema/validation/numeric.rb +5 -5
- data/lib/jsi/schema/validation/object.rb +2 -2
- data/lib/jsi/schema/validation/pattern.rb +1 -1
- data/lib/jsi/schema/validation/properties.rb +3 -3
- data/lib/jsi/schema/validation/property_names.rb +1 -1
- data/lib/jsi/schema/validation/ref.rb +1 -1
- data/lib/jsi/schema/validation/required.rb +1 -1
- data/lib/jsi/schema/validation/someof.rb +3 -3
- data/lib/jsi/schema/validation/string.rb +2 -2
- data/lib/jsi/schema/validation/type.rb +1 -1
- data/lib/jsi/schema/validation.rb +1 -1
- data/lib/jsi/schema.rb +91 -85
- data/lib/jsi/schema_classes.rb +70 -45
- data/lib/jsi/schema_registry.rb +15 -5
- data/lib/jsi/schema_set.rb +42 -2
- data/lib/jsi/simple_wrap.rb +23 -4
- data/lib/jsi/util/{attr_struct.rb → private/attr_struct.rb} +40 -19
- data/lib/jsi/util/private.rb +204 -0
- data/lib/jsi/{typelike_modules.rb → util/typelike.rb} +56 -82
- data/lib/jsi/util.rb +68 -148
- data/lib/jsi/version.rb +1 -1
- data/lib/jsi.rb +1 -17
- data/lib/schemas/json-schema.org/draft-04/schema.rb +3 -1
- data/lib/schemas/json-schema.org/draft-06/schema.rb +3 -1
- data/lib/schemas/json-schema.org/draft-07/schema.rb +3 -1
- metadata +11 -9
- 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
|
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
|
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
|
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
|
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 !
|
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
|
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
|
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 !
|
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
|
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
|
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
|
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
|
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
|
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
|
37
|
+
if keyword?('then')
|
38
38
|
result_builder.schema_warning('`then` has no effect without adjacent `if` keyword', 'then')
|
39
39
|
end
|
40
|
-
if
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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'
|