jsi-dev 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/CHANGELOG.md +101 -0
- data/LICENSE.md +613 -0
- data/README.md +303 -0
- data/docs/glossary.md +281 -0
- data/jsi.gemspec +30 -0
- data/lib/jsi/base/node.rb +373 -0
- data/lib/jsi/base.rb +738 -0
- data/lib/jsi/jsi_coder.rb +92 -0
- data/lib/jsi/metaschema.rb +6 -0
- data/lib/jsi/metaschema_node/bootstrap_schema.rb +126 -0
- data/lib/jsi/metaschema_node.rb +262 -0
- data/lib/jsi/ptr.rb +314 -0
- data/lib/jsi/schema/application/child_application/contains.rb +25 -0
- data/lib/jsi/schema/application/child_application/draft04.rb +21 -0
- data/lib/jsi/schema/application/child_application/draft06.rb +28 -0
- data/lib/jsi/schema/application/child_application/draft07.rb +28 -0
- data/lib/jsi/schema/application/child_application/items.rb +18 -0
- data/lib/jsi/schema/application/child_application/properties.rb +25 -0
- data/lib/jsi/schema/application/child_application.rb +13 -0
- data/lib/jsi/schema/application/draft04.rb +8 -0
- data/lib/jsi/schema/application/draft06.rb +8 -0
- data/lib/jsi/schema/application/draft07.rb +8 -0
- data/lib/jsi/schema/application/inplace_application/dependencies.rb +28 -0
- data/lib/jsi/schema/application/inplace_application/draft04.rb +25 -0
- data/lib/jsi/schema/application/inplace_application/draft06.rb +26 -0
- data/lib/jsi/schema/application/inplace_application/draft07.rb +32 -0
- data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +20 -0
- data/lib/jsi/schema/application/inplace_application/ref.rb +18 -0
- data/lib/jsi/schema/application/inplace_application/someof.rb +44 -0
- data/lib/jsi/schema/application/inplace_application.rb +14 -0
- data/lib/jsi/schema/application.rb +12 -0
- data/lib/jsi/schema/draft04.rb +13 -0
- data/lib/jsi/schema/draft06.rb +13 -0
- data/lib/jsi/schema/draft07.rb +13 -0
- data/lib/jsi/schema/issue.rb +36 -0
- data/lib/jsi/schema/ref.rb +183 -0
- data/lib/jsi/schema/schema_ancestor_node.rb +122 -0
- data/lib/jsi/schema/validation/array.rb +69 -0
- data/lib/jsi/schema/validation/const.rb +20 -0
- data/lib/jsi/schema/validation/contains.rb +25 -0
- data/lib/jsi/schema/validation/dependencies.rb +49 -0
- data/lib/jsi/schema/validation/draft04/minmax.rb +91 -0
- data/lib/jsi/schema/validation/draft04.rb +110 -0
- data/lib/jsi/schema/validation/draft06.rb +120 -0
- data/lib/jsi/schema/validation/draft07.rb +157 -0
- data/lib/jsi/schema/validation/enum.rb +25 -0
- data/lib/jsi/schema/validation/ifthenelse.rb +46 -0
- data/lib/jsi/schema/validation/items.rb +54 -0
- data/lib/jsi/schema/validation/not.rb +20 -0
- data/lib/jsi/schema/validation/numeric.rb +121 -0
- data/lib/jsi/schema/validation/object.rb +45 -0
- data/lib/jsi/schema/validation/pattern.rb +34 -0
- data/lib/jsi/schema/validation/properties.rb +101 -0
- data/lib/jsi/schema/validation/property_names.rb +32 -0
- data/lib/jsi/schema/validation/ref.rb +40 -0
- data/lib/jsi/schema/validation/required.rb +27 -0
- data/lib/jsi/schema/validation/someof.rb +90 -0
- data/lib/jsi/schema/validation/string.rb +47 -0
- data/lib/jsi/schema/validation/type.rb +49 -0
- data/lib/jsi/schema/validation.rb +49 -0
- data/lib/jsi/schema.rb +792 -0
- data/lib/jsi/schema_classes.rb +357 -0
- data/lib/jsi/schema_registry.rb +190 -0
- data/lib/jsi/schema_set.rb +219 -0
- data/lib/jsi/simple_wrap.rb +26 -0
- data/lib/jsi/util/private/attr_struct.rb +130 -0
- data/lib/jsi/util/private/memo_map.rb +75 -0
- data/lib/jsi/util/private.rb +202 -0
- data/lib/jsi/util/typelike.rb +225 -0
- data/lib/jsi/util.rb +227 -0
- data/lib/jsi/validation/error.rb +34 -0
- data/lib/jsi/validation/result.rb +212 -0
- data/lib/jsi/validation.rb +15 -0
- data/lib/jsi/version.rb +5 -0
- data/lib/jsi.rb +105 -0
- data/lib/schemas/json-schema.org/draft-04/schema.rb +169 -0
- data/lib/schemas/json-schema.org/draft-06/schema.rb +171 -0
- data/lib/schemas/json-schema.org/draft-07/schema.rb +198 -0
- data/readme.rb +138 -0
- data/{resources}/schemas/json-schema.org/draft-04/schema.json +149 -0
- data/{resources}/schemas/json-schema.org/draft-06/schema.json +154 -0
- data/{resources}/schemas/json-schema.org/draft-07/schema.json +168 -0
- metadata +155 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSI
|
4
|
+
module Schema::Validation::Draft04::MinMax
|
5
|
+
# @private
|
6
|
+
def internal_validate_maximum(result_builder)
|
7
|
+
if keyword?('exclusiveMaximum')
|
8
|
+
value = schema_content['exclusiveMaximum']
|
9
|
+
# The value of "exclusiveMaximum" MUST be a boolean.
|
10
|
+
unless [true, false].include?(value)
|
11
|
+
result_builder.schema_error('`exclusiveMaximum` is not true or false', 'exclusiveMaximum')
|
12
|
+
end
|
13
|
+
if !keyword?('maximum')
|
14
|
+
result_builder.schema_error('`exclusiveMaximum` has no effect without adjacent `maximum` keyword', 'exclusiveMaximum')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if keyword?('maximum')
|
19
|
+
value = schema_content['maximum']
|
20
|
+
# The value of "maximum" MUST be a JSON number.
|
21
|
+
if value.is_a?(Numeric)
|
22
|
+
if result_builder.instance.is_a?(Numeric)
|
23
|
+
# Successful validation depends on the presence and value of "exclusiveMaximum":
|
24
|
+
if schema_content['exclusiveMaximum'] == true
|
25
|
+
# if "exclusiveMaximum" has boolean value true, the instance is valid if it is strictly lower
|
26
|
+
# than the value of "maximum".
|
27
|
+
result_builder.validate(
|
28
|
+
result_builder.instance < value,
|
29
|
+
'instance is not less than `maximum` value with `exclusiveMaximum` = true',
|
30
|
+
keyword: 'maximum',
|
31
|
+
)
|
32
|
+
else
|
33
|
+
# if "exclusiveMaximum" is not present, or has boolean value false, then the instance is
|
34
|
+
# valid if it is lower than, or equal to, the value of "maximum"
|
35
|
+
result_builder.validate(
|
36
|
+
result_builder.instance <= value,
|
37
|
+
'instance is not less than or equal to `maximum` value',
|
38
|
+
keyword: 'maximum',
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
else
|
43
|
+
result_builder.schema_error('`maximum` is not a number', 'maximum')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# @private
|
49
|
+
def internal_validate_minimum(result_builder)
|
50
|
+
if keyword?('exclusiveMinimum')
|
51
|
+
value = schema_content['exclusiveMinimum']
|
52
|
+
# The value of "exclusiveMinimum" MUST be a boolean.
|
53
|
+
unless [true, false].include?(value)
|
54
|
+
result_builder.schema_error('`exclusiveMinimum` is not true or false', 'exclusiveMinimum')
|
55
|
+
end
|
56
|
+
if !keyword?('minimum')
|
57
|
+
result_builder.schema_error('`exclusiveMinimum` has no effect without adjacent `minimum` keyword', 'exclusiveMinimum')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if keyword?('minimum')
|
62
|
+
value = schema_content['minimum']
|
63
|
+
# The value of "minimum" MUST be a JSON number.
|
64
|
+
if value.is_a?(Numeric)
|
65
|
+
if result_builder.instance.is_a?(Numeric)
|
66
|
+
# Successful validation depends on the presence and value of "exclusiveMinimum":
|
67
|
+
if schema_content['exclusiveMinimum'] == true
|
68
|
+
# if "exclusiveMinimum" is present and has boolean value true, the instance is valid if it is
|
69
|
+
# strictly greater than the value of "minimum".
|
70
|
+
result_builder.validate(
|
71
|
+
result_builder.instance > value,
|
72
|
+
'instance is not greater than `minimum` value with `exclusiveMinimum` = true',
|
73
|
+
keyword: 'minimum',
|
74
|
+
)
|
75
|
+
else
|
76
|
+
# if "exclusiveMinimum" is not present, or has boolean value false, then the instance is
|
77
|
+
# valid if it is greater than, or equal to, the value of "minimum"
|
78
|
+
result_builder.validate(
|
79
|
+
result_builder.instance >= value,
|
80
|
+
'instance is not greater than or equal to `minimum` value',
|
81
|
+
keyword: 'minimum',
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
else
|
86
|
+
result_builder.schema_error('`minimum` is not a number', 'minimum')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSI
|
4
|
+
module Schema::Validation::Draft04
|
5
|
+
autoload :MinMax, 'jsi/schema/validation/draft04/minmax'
|
6
|
+
|
7
|
+
include Schema::Validation::Ref
|
8
|
+
|
9
|
+
include Schema::Validation::MultipleOf
|
10
|
+
include Schema::Validation::Draft04::MinMax
|
11
|
+
|
12
|
+
include Schema::Validation::StringLength
|
13
|
+
include Schema::Validation::Pattern
|
14
|
+
|
15
|
+
include Schema::Validation::Items
|
16
|
+
include Schema::Validation::ArrayLength
|
17
|
+
include Schema::Validation::UniqueItems
|
18
|
+
|
19
|
+
include Schema::Validation::MinMaxProperties
|
20
|
+
include Schema::Validation::Required
|
21
|
+
include Schema::Validation::Properties
|
22
|
+
include Schema::Validation::Dependencies
|
23
|
+
|
24
|
+
include Schema::Validation::Enum
|
25
|
+
include Schema::Validation::Type
|
26
|
+
|
27
|
+
include Schema::Validation::AllOf
|
28
|
+
include Schema::Validation::AnyOf
|
29
|
+
include Schema::Validation::OneOf
|
30
|
+
include Schema::Validation::Not
|
31
|
+
|
32
|
+
# @private
|
33
|
+
def internal_validate_keywords(result_builder)
|
34
|
+
internal_validate_ref(result_builder, throw_result: true)
|
35
|
+
|
36
|
+
# 5.1. Validation keywords for numeric instances (number and integer)
|
37
|
+
|
38
|
+
# 5.1.1. multipleOf
|
39
|
+
internal_validate_multipleOf(result_builder)
|
40
|
+
|
41
|
+
# 5.1.2. maximum and exclusiveMaximum
|
42
|
+
internal_validate_maximum(result_builder)
|
43
|
+
|
44
|
+
# 5.1.3. minimum and exclusiveMinimum
|
45
|
+
internal_validate_minimum(result_builder)
|
46
|
+
|
47
|
+
# 5.2. Validation keywords for strings
|
48
|
+
|
49
|
+
# 5.2.1. maxLength
|
50
|
+
internal_validate_maxLength(result_builder)
|
51
|
+
|
52
|
+
# 5.2.2. minLength
|
53
|
+
internal_validate_minLength(result_builder)
|
54
|
+
|
55
|
+
# 5.2.3. pattern
|
56
|
+
internal_validate_pattern(result_builder)
|
57
|
+
|
58
|
+
# 5.3. Validation keywords for arrays
|
59
|
+
|
60
|
+
# 5.3.1. additionalItems and items
|
61
|
+
internal_validate_items(result_builder)
|
62
|
+
|
63
|
+
# 5.3.2. maxItems
|
64
|
+
internal_validate_maxItems(result_builder)
|
65
|
+
|
66
|
+
# 5.3.3. minItems
|
67
|
+
internal_validate_minItems(result_builder)
|
68
|
+
|
69
|
+
# 5.3.4. uniqueItems
|
70
|
+
internal_validate_uniqueItems(result_builder)
|
71
|
+
|
72
|
+
# 5.4. Validation keywords for objects
|
73
|
+
|
74
|
+
# 5.4.1. maxProperties
|
75
|
+
internal_validate_maxProperties(result_builder)
|
76
|
+
|
77
|
+
# 5.4.2. minProperties
|
78
|
+
internal_validate_minProperties(result_builder)
|
79
|
+
|
80
|
+
# 5.4.3. required
|
81
|
+
internal_validate_required(result_builder)
|
82
|
+
|
83
|
+
# 5.4.4. additionalProperties, properties and patternProperties
|
84
|
+
internal_validate_properties(result_builder)
|
85
|
+
|
86
|
+
# 5.4.5. dependencies
|
87
|
+
internal_validate_dependencies(result_builder)
|
88
|
+
|
89
|
+
# 5.5. Validation keywords for any instance type
|
90
|
+
|
91
|
+
# 5.5.1. enum
|
92
|
+
internal_validate_enum(result_builder)
|
93
|
+
|
94
|
+
# 5.5.2. type
|
95
|
+
internal_validate_type(result_builder)
|
96
|
+
|
97
|
+
# 5.5.3. allOf
|
98
|
+
internal_validate_allOf(result_builder)
|
99
|
+
|
100
|
+
# 5.5.4. anyOf
|
101
|
+
internal_validate_anyOf(result_builder)
|
102
|
+
|
103
|
+
# 5.5.5. oneOf
|
104
|
+
internal_validate_oneOf(result_builder)
|
105
|
+
|
106
|
+
# 5.5.6. not
|
107
|
+
internal_validate_not(result_builder)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSI
|
4
|
+
module Schema::Validation::Draft06
|
5
|
+
include Schema::Validation::Ref
|
6
|
+
include Schema::Validation::AllOf
|
7
|
+
include Schema::Validation::AnyOf
|
8
|
+
include Schema::Validation::OneOf
|
9
|
+
include Schema::Validation::Not
|
10
|
+
|
11
|
+
include Schema::Validation::Items
|
12
|
+
include Schema::Validation::Contains
|
13
|
+
include Schema::Validation::Properties
|
14
|
+
|
15
|
+
include Schema::Validation::MultipleOf
|
16
|
+
include Schema::Validation::MinMax
|
17
|
+
|
18
|
+
include Schema::Validation::StringLength
|
19
|
+
|
20
|
+
include Schema::Validation::Pattern
|
21
|
+
|
22
|
+
include Schema::Validation::ArrayLength
|
23
|
+
include Schema::Validation::UniqueItems
|
24
|
+
|
25
|
+
include Schema::Validation::MinMaxProperties
|
26
|
+
include Schema::Validation::Required
|
27
|
+
include Schema::Validation::Dependencies
|
28
|
+
include Schema::Validation::PropertyNames
|
29
|
+
|
30
|
+
include Schema::Validation::Const
|
31
|
+
include Schema::Validation::Enum
|
32
|
+
|
33
|
+
include Schema::Validation::Type
|
34
|
+
|
35
|
+
# @private
|
36
|
+
def internal_validate_keywords(result_builder)
|
37
|
+
# json-schema 8. Schema references with $ref
|
38
|
+
internal_validate_ref(result_builder, throw_result: true)
|
39
|
+
|
40
|
+
# json-schema-validation 6.1. multipleOf
|
41
|
+
internal_validate_multipleOf(result_builder)
|
42
|
+
|
43
|
+
# json-schema-validation 6.2. maximum
|
44
|
+
internal_validate_maximum(result_builder)
|
45
|
+
|
46
|
+
# json-schema-validation 6.3. exclusiveMaximum
|
47
|
+
internal_validate_exclusiveMaximum(result_builder)
|
48
|
+
|
49
|
+
# json-schema-validation 6.4. minimum
|
50
|
+
internal_validate_minimum(result_builder)
|
51
|
+
|
52
|
+
# json-schema-validation 6.5. exclusiveMinimum
|
53
|
+
internal_validate_exclusiveMinimum(result_builder)
|
54
|
+
|
55
|
+
# json-schema-validation 6.6. maxLength
|
56
|
+
internal_validate_maxLength(result_builder)
|
57
|
+
|
58
|
+
# json-schema-validation 6.7. minLength
|
59
|
+
internal_validate_minLength(result_builder)
|
60
|
+
|
61
|
+
# json-schema-validation 6.8. pattern
|
62
|
+
internal_validate_pattern(result_builder)
|
63
|
+
|
64
|
+
# json-schema-validation 6.9. items
|
65
|
+
# json-schema-validation 6.10. additionalItems
|
66
|
+
internal_validate_items(result_builder)
|
67
|
+
|
68
|
+
# json-schema-validation 6.11. maxItems
|
69
|
+
internal_validate_maxItems(result_builder)
|
70
|
+
|
71
|
+
# json-schema-validation 6.12. minItems
|
72
|
+
internal_validate_minItems(result_builder)
|
73
|
+
|
74
|
+
# json-schema-validation 6.13. uniqueItems
|
75
|
+
internal_validate_uniqueItems(result_builder)
|
76
|
+
|
77
|
+
# json-schema-validation 6.14. contains
|
78
|
+
internal_validate_contains(result_builder)
|
79
|
+
|
80
|
+
# json-schema-validation 6.15. maxProperties
|
81
|
+
internal_validate_maxProperties(result_builder)
|
82
|
+
|
83
|
+
# json-schema-validation 6.16. minProperties
|
84
|
+
internal_validate_minProperties(result_builder)
|
85
|
+
|
86
|
+
# json-schema-validation 6.17. required
|
87
|
+
internal_validate_required(result_builder)
|
88
|
+
|
89
|
+
# json-schema-validation 6.18. properties
|
90
|
+
# json-schema-validation 6.19. patternProperties
|
91
|
+
# json-schema-validation 6.20. additionalProperties
|
92
|
+
internal_validate_properties(result_builder)
|
93
|
+
|
94
|
+
# json-schema-validation 6.21. dependencies
|
95
|
+
internal_validate_dependencies(result_builder)
|
96
|
+
|
97
|
+
# json-schema-validation 6.22. propertyNames
|
98
|
+
internal_validate_propertyNames(result_builder)
|
99
|
+
|
100
|
+
# json-schema-validation 6.23. enum
|
101
|
+
internal_validate_enum(result_builder)
|
102
|
+
|
103
|
+
# json-schema-validation 6.24. const
|
104
|
+
internal_validate_const(result_builder)
|
105
|
+
|
106
|
+
# json-schema-validation 6.25. type
|
107
|
+
internal_validate_type(result_builder)
|
108
|
+
|
109
|
+
# json-schema-validation 6.26. allOf
|
110
|
+
internal_validate_allOf(result_builder)
|
111
|
+
# json-schema-validation 6.27. anyOf
|
112
|
+
internal_validate_anyOf(result_builder)
|
113
|
+
# json-schema-validation 6.28. oneOf
|
114
|
+
internal_validate_oneOf(result_builder)
|
115
|
+
|
116
|
+
# json-schema-validation 6.29. not
|
117
|
+
internal_validate_not(result_builder)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSI
|
4
|
+
module Schema::Validation::Draft07
|
5
|
+
include Schema::Validation::Ref
|
6
|
+
|
7
|
+
include Schema::Validation::Type
|
8
|
+
include Schema::Validation::Enum
|
9
|
+
include Schema::Validation::Const
|
10
|
+
|
11
|
+
include Schema::Validation::MultipleOf
|
12
|
+
include Schema::Validation::MinMax
|
13
|
+
|
14
|
+
include Schema::Validation::StringLength
|
15
|
+
include Schema::Validation::Pattern
|
16
|
+
|
17
|
+
include Schema::Validation::Items
|
18
|
+
include Schema::Validation::ArrayLength
|
19
|
+
include Schema::Validation::UniqueItems
|
20
|
+
include Schema::Validation::Contains
|
21
|
+
|
22
|
+
include Schema::Validation::MinMaxProperties
|
23
|
+
include Schema::Validation::Required
|
24
|
+
|
25
|
+
include Schema::Validation::Properties
|
26
|
+
include Schema::Validation::Dependencies
|
27
|
+
include Schema::Validation::PropertyNames
|
28
|
+
|
29
|
+
include Schema::Validation::IfThenElse
|
30
|
+
include Schema::Validation::AllOf
|
31
|
+
include Schema::Validation::AnyOf
|
32
|
+
include Schema::Validation::OneOf
|
33
|
+
include Schema::Validation::Not
|
34
|
+
|
35
|
+
# @private
|
36
|
+
def internal_validate_keywords(result_builder)
|
37
|
+
internal_validate_ref(result_builder, throw_result: true)
|
38
|
+
|
39
|
+
# 6.1. Validation Keywords for Any Instance Type
|
40
|
+
|
41
|
+
# 6.1.1. type
|
42
|
+
internal_validate_type(result_builder)
|
43
|
+
|
44
|
+
# 6.1.2. enum
|
45
|
+
internal_validate_enum(result_builder)
|
46
|
+
|
47
|
+
# 6.1.3. const
|
48
|
+
internal_validate_const(result_builder)
|
49
|
+
|
50
|
+
# 6.2. Validation Keywords for Numeric Instances (number and integer)
|
51
|
+
|
52
|
+
# 6.2.1. multipleOf
|
53
|
+
internal_validate_multipleOf(result_builder)
|
54
|
+
|
55
|
+
# 6.2.2. maximum
|
56
|
+
internal_validate_maximum(result_builder)
|
57
|
+
|
58
|
+
# 6.2.3. exclusiveMaximum
|
59
|
+
internal_validate_exclusiveMaximum(result_builder)
|
60
|
+
|
61
|
+
# 6.2.4. minimum
|
62
|
+
internal_validate_minimum(result_builder)
|
63
|
+
|
64
|
+
# 6.2.5. exclusiveMinimum
|
65
|
+
internal_validate_exclusiveMinimum(result_builder)
|
66
|
+
|
67
|
+
# 6.3. Validation Keywords for Strings
|
68
|
+
|
69
|
+
# 6.3.1. maxLength
|
70
|
+
internal_validate_maxLength(result_builder)
|
71
|
+
|
72
|
+
# 6.3.2. minLength
|
73
|
+
internal_validate_minLength(result_builder)
|
74
|
+
|
75
|
+
# 6.3.3. pattern
|
76
|
+
internal_validate_pattern(result_builder)
|
77
|
+
|
78
|
+
# 6.4. Validation Keywords for Arrays
|
79
|
+
|
80
|
+
# 6.4.1. items
|
81
|
+
# 6.4.2. additionalItems
|
82
|
+
internal_validate_items(result_builder)
|
83
|
+
|
84
|
+
# 6.4.3. maxItems
|
85
|
+
internal_validate_maxItems(result_builder)
|
86
|
+
|
87
|
+
# 6.4.4. minItems
|
88
|
+
internal_validate_minItems(result_builder)
|
89
|
+
|
90
|
+
# 6.4.5. uniqueItems
|
91
|
+
internal_validate_uniqueItems(result_builder)
|
92
|
+
|
93
|
+
# 6.4.6. contains
|
94
|
+
internal_validate_contains(result_builder)
|
95
|
+
|
96
|
+
# 6.5. Validation Keywords for Objects
|
97
|
+
|
98
|
+
# 6.5.1. maxProperties
|
99
|
+
internal_validate_maxProperties(result_builder)
|
100
|
+
|
101
|
+
# 6.5.2. minProperties
|
102
|
+
internal_validate_minProperties(result_builder)
|
103
|
+
|
104
|
+
# 6.5.3. required
|
105
|
+
internal_validate_required(result_builder)
|
106
|
+
|
107
|
+
# 6.5.4. properties
|
108
|
+
# 6.5.5. patternProperties
|
109
|
+
# 6.5.6. additionalProperties
|
110
|
+
internal_validate_properties(result_builder)
|
111
|
+
|
112
|
+
# 6.5.7. dependencies
|
113
|
+
internal_validate_dependencies(result_builder)
|
114
|
+
|
115
|
+
# 6.5.8. propertyNames
|
116
|
+
internal_validate_propertyNames(result_builder)
|
117
|
+
|
118
|
+
# 6.6. Keywords for Applying Subschemas Conditionally
|
119
|
+
|
120
|
+
# 6.6.1. if
|
121
|
+
# 6.6.2. then
|
122
|
+
# 6.6.3. else
|
123
|
+
internal_validate_ifthenelse(result_builder)
|
124
|
+
|
125
|
+
# 6.7. Keywords for Applying Subschemas With Boolean Logic
|
126
|
+
|
127
|
+
# 6.7.1. allOf
|
128
|
+
internal_validate_allOf(result_builder)
|
129
|
+
|
130
|
+
# 6.7.2. anyOf
|
131
|
+
internal_validate_anyOf(result_builder)
|
132
|
+
|
133
|
+
# 6.7.3. oneOf
|
134
|
+
internal_validate_oneOf(result_builder)
|
135
|
+
|
136
|
+
# 6.7.4. not
|
137
|
+
internal_validate_not(result_builder)
|
138
|
+
|
139
|
+
# 7. Semantic Validation With "format"
|
140
|
+
# TODO
|
141
|
+
|
142
|
+
# 10. Schema Annotations
|
143
|
+
|
144
|
+
# 10.1. "title" and "description"
|
145
|
+
# TODO
|
146
|
+
|
147
|
+
# 10.2. "default"
|
148
|
+
# TODO
|
149
|
+
|
150
|
+
# 10.3. "readOnly" and "writeOnly"
|
151
|
+
# TODO
|
152
|
+
|
153
|
+
# 10.4. "examples"
|
154
|
+
# TODO
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSI
|
4
|
+
module Schema::Validation::Enum
|
5
|
+
# @private
|
6
|
+
def internal_validate_enum(result_builder)
|
7
|
+
if keyword?('enum')
|
8
|
+
value = schema_content['enum']
|
9
|
+
# The value of this keyword MUST be an array. This array SHOULD have at least one element.
|
10
|
+
# Elements in the array SHOULD be unique.
|
11
|
+
if value.respond_to?(:to_ary)
|
12
|
+
# An instance validates successfully against this keyword if its value is equal to one of the
|
13
|
+
# elements in this keyword's array value.
|
14
|
+
result_builder.validate(
|
15
|
+
value.include?(result_builder.instance),
|
16
|
+
'instance is not equal to any `enum` value',
|
17
|
+
keyword: 'enum',
|
18
|
+
)
|
19
|
+
else
|
20
|
+
result_builder.schema_error('`enum` is not an array', 'enum')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSI
|
4
|
+
module Schema::Validation::IfThenElse
|
5
|
+
# @private
|
6
|
+
def internal_validate_ifthenelse(result_builder)
|
7
|
+
if keyword?('if')
|
8
|
+
# This keyword's value MUST be a valid JSON Schema.
|
9
|
+
# This validation outcome of this keyword's subschema has no direct effect on the overall validation
|
10
|
+
# result. Rather, it controls which of the "then" or "else" keywords are evaluated.
|
11
|
+
if_result = result_builder.inplace_subschema_validate(['if'])
|
12
|
+
|
13
|
+
result_builder.merge_schema_issues(if_result)
|
14
|
+
|
15
|
+
if if_result.valid?
|
16
|
+
if keyword?('then')
|
17
|
+
then_result = result_builder.inplace_subschema_validate(['then'])
|
18
|
+
result_builder.validate(
|
19
|
+
then_result.valid?,
|
20
|
+
'instance did not validate against the schema defined by `then` value after validating against the schema defined by the `if` value',
|
21
|
+
keyword: 'if',
|
22
|
+
results: [then_result],
|
23
|
+
)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
if keyword?('else')
|
27
|
+
else_result = result_builder.inplace_subschema_validate(['else'])
|
28
|
+
result_builder.validate(
|
29
|
+
else_result.valid?,
|
30
|
+
'instance did not validate against the schema defined by `else` value after not validating against the schema defined by the `if` value',
|
31
|
+
keyword: 'if',
|
32
|
+
results: [else_result],
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
if keyword?('then')
|
38
|
+
result_builder.schema_warning('`then` has no effect without adjacent `if` keyword', 'then')
|
39
|
+
end
|
40
|
+
if keyword?('else')
|
41
|
+
result_builder.schema_warning('`else` has no effect without adjacent `if` keyword', 'else')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSI
|
4
|
+
module Schema::Validation::Items
|
5
|
+
# @private
|
6
|
+
def internal_validate_items(result_builder)
|
7
|
+
if keyword?('items')
|
8
|
+
value = schema_content['items']
|
9
|
+
# The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas.
|
10
|
+
if value.respond_to?(:to_ary)
|
11
|
+
# If "items" is an array of schemas, validation succeeds if each element of the instance validates
|
12
|
+
# against the schema at the same position, if any.
|
13
|
+
if result_builder.instance.respond_to?(:to_ary)
|
14
|
+
results = {}
|
15
|
+
result_builder.instance.each_index do |i|
|
16
|
+
if i < value.size
|
17
|
+
results[i] = result_builder.child_subschema_validate(i, ['items', i])
|
18
|
+
elsif keyword?('additionalItems')
|
19
|
+
results[i] = result_builder.child_subschema_validate(i, ['additionalItems'])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
result_builder.validate(
|
23
|
+
results.values.all?(&:valid?),
|
24
|
+
'instance array items are not all valid against corresponding `items` or `additionalItems` schema values',
|
25
|
+
keyword: 'items',
|
26
|
+
results: results.values,
|
27
|
+
)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
# If "items" is a schema, validation succeeds if all elements in the array successfully validate
|
31
|
+
# against that schema.
|
32
|
+
if result_builder.instance.respond_to?(:to_ary)
|
33
|
+
results = result_builder.instance.each_index.map do |i|
|
34
|
+
result_builder.child_subschema_validate(i, ['items'])
|
35
|
+
end
|
36
|
+
result_builder.validate(
|
37
|
+
results.all?(&:valid?),
|
38
|
+
'instance array items are not all valid against `items` schema value',
|
39
|
+
keyword: 'items',
|
40
|
+
results: results,
|
41
|
+
)
|
42
|
+
end
|
43
|
+
if keyword?('additionalItems')
|
44
|
+
result_builder.schema_warning('`additionalItems` has no effect when adjacent `items` keyword is not an array', 'items')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
if keyword?('additionalItems')
|
49
|
+
result_builder.schema_warning('`additionalItems` has no effect without adjacent `items` keyword', 'items')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSI
|
4
|
+
module Schema::Validation::Not
|
5
|
+
# @private
|
6
|
+
def internal_validate_not(result_builder)
|
7
|
+
if keyword?('not')
|
8
|
+
# This keyword's value MUST be a valid JSON Schema.
|
9
|
+
# An instance is valid against this keyword if it fails to validate successfully against the schema
|
10
|
+
# defined by this keyword.
|
11
|
+
not_valid = result_builder.inplace_subschema_validate(['not']).valid?
|
12
|
+
result_builder.validate(
|
13
|
+
!not_valid,
|
14
|
+
'instance is valid against the schema specified as `not` value',
|
15
|
+
keyword: 'not',
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|