jsi-dev 0.0.8 → 0.0.10
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.
- checksums.yaml +4 -4
- data/.yardopts +3 -4
- data/CHANGELOG.md +19 -0
- data/LICENSE.md +2 -3
- data/README.md +87 -43
- data/docs/Glossary.md +313 -0
- data/jsi.gemspec +1 -1
- data/lib/jsi/base/mutability.rb +48 -0
- data/lib/jsi/base/node.rb +66 -52
- data/lib/jsi/base.rb +593 -176
- data/lib/jsi/jsi_coder.rb +4 -2
- data/lib/jsi/metaschema_node/bootstrap_schema.rb +118 -59
- data/lib/jsi/metaschema_node.rb +245 -154
- data/lib/jsi/ptr.rb +45 -17
- data/lib/jsi/ref.rb +197 -0
- data/lib/jsi/registry.rb +311 -0
- data/lib/jsi/schema/cxt/child_application.rb +35 -0
- data/lib/jsi/schema/cxt/inplace_application.rb +37 -0
- data/lib/jsi/schema/cxt.rb +80 -0
- data/lib/jsi/schema/dialect.rb +137 -0
- data/lib/jsi/schema/draft04.rb +113 -5
- data/lib/jsi/schema/draft06.rb +123 -5
- data/lib/jsi/schema/draft07.rb +157 -5
- data/lib/jsi/schema/draft202012.rb +303 -0
- data/lib/jsi/schema/dynamic_anchor_map.rb +63 -0
- data/lib/jsi/schema/element.rb +69 -0
- data/lib/jsi/schema/elements/anchor.rb +13 -0
- data/lib/jsi/schema/elements/array_validation.rb +82 -0
- data/lib/jsi/schema/elements/comment.rb +10 -0
- data/lib/jsi/schema/{validation → elements}/const.rb +11 -7
- data/lib/jsi/schema/elements/contains.rb +59 -0
- data/lib/jsi/schema/elements/contains_minmax.rb +91 -0
- data/lib/jsi/schema/elements/content_encoding.rb +10 -0
- data/lib/jsi/schema/elements/content_media_type.rb +10 -0
- data/lib/jsi/schema/elements/content_schema.rb +16 -0
- data/lib/jsi/schema/elements/default.rb +11 -0
- data/lib/jsi/schema/elements/definitions.rb +19 -0
- data/lib/jsi/schema/elements/dependencies.rb +99 -0
- data/lib/jsi/schema/elements/dependent_required.rb +49 -0
- data/lib/jsi/schema/elements/dependent_schemas.rb +69 -0
- data/lib/jsi/schema/elements/dynamic_ref.rb +69 -0
- data/lib/jsi/schema/elements/enum.rb +26 -0
- data/lib/jsi/schema/elements/examples.rb +10 -0
- data/lib/jsi/schema/elements/format.rb +10 -0
- data/lib/jsi/schema/elements/id.rb +30 -0
- data/lib/jsi/schema/elements/if_then_else.rb +82 -0
- data/lib/jsi/schema/elements/info_bool.rb +10 -0
- data/lib/jsi/schema/elements/info_string.rb +10 -0
- data/lib/jsi/schema/elements/items.rb +93 -0
- data/lib/jsi/schema/elements/items_prefixed.rb +96 -0
- data/lib/jsi/schema/elements/not.rb +31 -0
- data/lib/jsi/schema/elements/numeric.rb +137 -0
- data/lib/jsi/schema/elements/numeric_draft04.rb +77 -0
- data/lib/jsi/schema/elements/object_validation.rb +55 -0
- data/lib/jsi/schema/elements/pattern.rb +35 -0
- data/lib/jsi/schema/elements/properties.rb +145 -0
- data/lib/jsi/schema/elements/property_names.rb +48 -0
- data/lib/jsi/schema/elements/ref.rb +62 -0
- data/lib/jsi/schema/elements/required.rb +34 -0
- data/lib/jsi/schema/elements/self.rb +24 -0
- data/lib/jsi/schema/elements/some_of.rb +180 -0
- data/lib/jsi/schema/elements/string_validation.rb +57 -0
- data/lib/jsi/schema/elements/type.rb +43 -0
- data/lib/jsi/schema/elements/unevaluated_items.rb +54 -0
- data/lib/jsi/schema/elements/unevaluated_properties.rb +54 -0
- data/lib/jsi/schema/elements/xschema.rb +10 -0
- data/lib/jsi/schema/elements/xvocabulary.rb +10 -0
- data/lib/jsi/schema/elements.rb +101 -0
- data/lib/jsi/schema/issue.rb +3 -4
- data/lib/jsi/schema/schema_ancestor_node.rb +105 -52
- data/lib/jsi/schema/vocabulary.rb +36 -0
- data/lib/jsi/schema.rb +598 -383
- data/lib/jsi/schema_classes.rb +195 -141
- data/lib/jsi/schema_set.rb +85 -128
- data/lib/jsi/set.rb +23 -0
- data/lib/jsi/simple_wrap.rb +14 -17
- data/lib/jsi/struct.rb +57 -0
- data/lib/jsi/uri.rb +40 -0
- data/lib/jsi/util/private/memo_map.rb +9 -13
- data/lib/jsi/util/private.rb +59 -31
- data/lib/jsi/util/typelike.rb +19 -60
- data/lib/jsi/util.rb +53 -34
- data/lib/jsi/validation/error.rb +45 -2
- data/lib/jsi/validation/result.rb +121 -90
- data/lib/jsi/validation.rb +1 -6
- data/lib/jsi/version.rb +1 -1
- data/lib/jsi.rb +170 -36
- data/lib/schemas/json-schema.org/draft/2020-12/schema.rb +62 -0
- data/lib/schemas/json-schema.org/draft-04/schema.rb +60 -109
- data/lib/schemas/json-schema.org/draft-06/schema.rb +53 -108
- data/lib/schemas/json-schema.org/draft-07/schema.rb +63 -127
- data/readme.rb +4 -4
- data/{resources}/schemas/2020-12_strict.json +19 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/meta/applicator.json +48 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/meta/content.json +17 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/meta/core.json +51 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/meta/format-annotation.json +14 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/meta/format-assertion.json +14 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/meta/meta-data.json +37 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/meta/unevaluated.json +15 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/meta/validation.json +98 -0
- data/{resources}/schemas/json-schema.org/draft/2020-12/schema.json +58 -0
- metadata +73 -52
- data/docs/glossary.md +0 -281
- data/lib/jsi/metaschema.rb +0 -6
- data/lib/jsi/schema/application/child_application/contains.rb +0 -25
- data/lib/jsi/schema/application/child_application/draft04.rb +0 -21
- data/lib/jsi/schema/application/child_application/draft06.rb +0 -28
- data/lib/jsi/schema/application/child_application/draft07.rb +0 -28
- data/lib/jsi/schema/application/child_application/items.rb +0 -18
- data/lib/jsi/schema/application/child_application/properties.rb +0 -25
- data/lib/jsi/schema/application/child_application.rb +0 -13
- data/lib/jsi/schema/application/draft04.rb +0 -8
- data/lib/jsi/schema/application/draft06.rb +0 -8
- data/lib/jsi/schema/application/draft07.rb +0 -8
- data/lib/jsi/schema/application/inplace_application/dependencies.rb +0 -28
- data/lib/jsi/schema/application/inplace_application/draft04.rb +0 -25
- data/lib/jsi/schema/application/inplace_application/draft06.rb +0 -26
- data/lib/jsi/schema/application/inplace_application/draft07.rb +0 -32
- data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +0 -20
- data/lib/jsi/schema/application/inplace_application/ref.rb +0 -18
- data/lib/jsi/schema/application/inplace_application/someof.rb +0 -44
- data/lib/jsi/schema/application/inplace_application.rb +0 -14
- data/lib/jsi/schema/application.rb +0 -12
- data/lib/jsi/schema/ref.rb +0 -183
- data/lib/jsi/schema/validation/array.rb +0 -69
- data/lib/jsi/schema/validation/contains.rb +0 -25
- data/lib/jsi/schema/validation/dependencies.rb +0 -49
- data/lib/jsi/schema/validation/draft04/minmax.rb +0 -91
- data/lib/jsi/schema/validation/draft04.rb +0 -110
- data/lib/jsi/schema/validation/draft06.rb +0 -120
- data/lib/jsi/schema/validation/draft07.rb +0 -157
- data/lib/jsi/schema/validation/enum.rb +0 -25
- data/lib/jsi/schema/validation/ifthenelse.rb +0 -46
- data/lib/jsi/schema/validation/items.rb +0 -54
- data/lib/jsi/schema/validation/not.rb +0 -20
- data/lib/jsi/schema/validation/numeric.rb +0 -121
- data/lib/jsi/schema/validation/object.rb +0 -45
- data/lib/jsi/schema/validation/pattern.rb +0 -34
- data/lib/jsi/schema/validation/properties.rb +0 -101
- data/lib/jsi/schema/validation/property_names.rb +0 -32
- data/lib/jsi/schema/validation/ref.rb +0 -40
- data/lib/jsi/schema/validation/required.rb +0 -27
- data/lib/jsi/schema/validation/someof.rb +0 -90
- data/lib/jsi/schema/validation/string.rb +0 -47
- data/lib/jsi/schema/validation/type.rb +0 -49
- data/lib/jsi/schema/validation.rb +0 -49
- data/lib/jsi/schema_registry.rb +0 -190
- data/lib/jsi/util/private/attr_struct.rb +0 -130
|
@@ -1,120 +0,0 @@
|
|
|
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
|
|
@@ -1,157 +0,0 @@
|
|
|
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
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JSI
|
|
4
|
-
module Schema::Validation::MultipleOf
|
|
5
|
-
# @private
|
|
6
|
-
def internal_validate_multipleOf(result_builder)
|
|
7
|
-
if keyword?('multipleOf')
|
|
8
|
-
value = schema_content['multipleOf']
|
|
9
|
-
# The value of "multipleOf" MUST be a number, strictly greater than 0.
|
|
10
|
-
if value.is_a?(Numeric) && value > 0
|
|
11
|
-
# A numeric instance is valid only if division by this keyword's value results in an integer.
|
|
12
|
-
if result_builder.instance.is_a?(Numeric)
|
|
13
|
-
if result_builder.instance.is_a?(Integer) && value.is_a?(Integer)
|
|
14
|
-
valid = result_builder.instance % value == 0
|
|
15
|
-
else
|
|
16
|
-
quotient = result_builder.instance / value
|
|
17
|
-
if quotient.finite?
|
|
18
|
-
valid = quotient % 1.0 == 0.0
|
|
19
|
-
else
|
|
20
|
-
valid = BigDecimal(result_builder.instance, Float::DIG) % BigDecimal(value, Float::DIG) == 0
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
result_builder.validate(
|
|
24
|
-
valid,
|
|
25
|
-
'instance is not a multiple of `multipleOf` value',
|
|
26
|
-
keyword: 'multipleOf',
|
|
27
|
-
)
|
|
28
|
-
end
|
|
29
|
-
else
|
|
30
|
-
result_builder.schema_error('`multipleOf` is not a number greater than 0', 'multipleOf')
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
module Schema::Validation::MinMax
|
|
37
|
-
# @private
|
|
38
|
-
def internal_validate_maximum(result_builder)
|
|
39
|
-
if keyword?('maximum')
|
|
40
|
-
value = schema_content['maximum']
|
|
41
|
-
# The value of "maximum" MUST be a number, representing an inclusive upper limit for a numeric instance.
|
|
42
|
-
if value.is_a?(Numeric)
|
|
43
|
-
# If the instance is a number, then this keyword validates only if the instance is less than or
|
|
44
|
-
# exactly equal to "maximum".
|
|
45
|
-
if result_builder.instance.is_a?(Numeric)
|
|
46
|
-
result_builder.validate(
|
|
47
|
-
result_builder.instance <= value,
|
|
48
|
-
'instance is not less than or equal to `maximum` value',
|
|
49
|
-
keyword: 'maximum',
|
|
50
|
-
)
|
|
51
|
-
end
|
|
52
|
-
else
|
|
53
|
-
result_builder.schema_error('`maximum` is not a number', 'maximum')
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# @private
|
|
59
|
-
def internal_validate_exclusiveMaximum(result_builder)
|
|
60
|
-
if keyword?('exclusiveMaximum')
|
|
61
|
-
value = schema_content['exclusiveMaximum']
|
|
62
|
-
# The value of "exclusiveMaximum" MUST be number, representing an exclusive upper limit for a numeric instance.
|
|
63
|
-
if value.is_a?(Numeric)
|
|
64
|
-
# If the instance is a number, then the instance is valid only if it has a value strictly less than
|
|
65
|
-
# (not equal to) "exclusiveMaximum".
|
|
66
|
-
if result_builder.instance.is_a?(Numeric)
|
|
67
|
-
result_builder.validate(
|
|
68
|
-
result_builder.instance < value,
|
|
69
|
-
'instance is not less than `exclusiveMaximum` value',
|
|
70
|
-
keyword: 'exclusiveMaximum',
|
|
71
|
-
)
|
|
72
|
-
end
|
|
73
|
-
else
|
|
74
|
-
result_builder.schema_error('`exclusiveMaximum` is not a number', 'exclusiveMaximum')
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# @private
|
|
80
|
-
def internal_validate_minimum(result_builder)
|
|
81
|
-
if keyword?('minimum')
|
|
82
|
-
value = schema_content['minimum']
|
|
83
|
-
# The value of "minimum" MUST be a number, representing an inclusive lower limit for a numeric instance.
|
|
84
|
-
if value.is_a?(Numeric)
|
|
85
|
-
# If the instance is a number, then this keyword validates only if the instance is greater than or
|
|
86
|
-
# exactly equal to "minimum".
|
|
87
|
-
if result_builder.instance.is_a?(Numeric)
|
|
88
|
-
result_builder.validate(
|
|
89
|
-
result_builder.instance >= value,
|
|
90
|
-
'instance is not greater than or equal to `minimum` value',
|
|
91
|
-
keyword: 'minimum',
|
|
92
|
-
)
|
|
93
|
-
end
|
|
94
|
-
else
|
|
95
|
-
result_builder.schema_error('`minimum` is not a number', 'minimum')
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# @private
|
|
101
|
-
def internal_validate_exclusiveMinimum(result_builder)
|
|
102
|
-
if keyword?('exclusiveMinimum')
|
|
103
|
-
value = schema_content['exclusiveMinimum']
|
|
104
|
-
# The value of "exclusiveMinimum" MUST be number, representing an exclusive lower limit for a numeric instance.
|
|
105
|
-
if value.is_a?(Numeric)
|
|
106
|
-
# If the instance is a number, then the instance is valid only if it has a value strictly greater
|
|
107
|
-
# than (not equal to) "exclusiveMinimum".
|
|
108
|
-
if result_builder.instance.is_a?(Numeric)
|
|
109
|
-
result_builder.validate(
|
|
110
|
-
result_builder.instance > value,
|
|
111
|
-
'instance is not greater than `exclusiveMinimum` value',
|
|
112
|
-
keyword: 'exclusiveMinimum',
|
|
113
|
-
)
|
|
114
|
-
end
|
|
115
|
-
else
|
|
116
|
-
result_builder.schema_error('`exclusiveMinimum` is not a number', 'exclusiveMinimum')
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JSI
|
|
4
|
-
module Schema::Validation::MinMaxProperties
|
|
5
|
-
# @private
|
|
6
|
-
def internal_validate_maxProperties(result_builder)
|
|
7
|
-
if keyword?('maxProperties')
|
|
8
|
-
value = schema_content['maxProperties']
|
|
9
|
-
# The value of this keyword MUST be a non-negative integer.
|
|
10
|
-
if internal_integer?(value) && value >= 0
|
|
11
|
-
if result_builder.instance.respond_to?(:to_hash)
|
|
12
|
-
# An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
|
|
13
|
-
result_builder.validate(
|
|
14
|
-
result_builder.instance.size <= value,
|
|
15
|
-
'instance object contains more properties than `maxProperties` value',
|
|
16
|
-
keyword: 'maxProperties',
|
|
17
|
-
)
|
|
18
|
-
end
|
|
19
|
-
else
|
|
20
|
-
result_builder.schema_error('`maxProperties` is not a non-negative integer', 'maxProperties')
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# @private
|
|
26
|
-
def internal_validate_minProperties(result_builder)
|
|
27
|
-
if keyword?('minProperties')
|
|
28
|
-
value = schema_content['minProperties']
|
|
29
|
-
# The value of this keyword MUST be a non-negative integer.
|
|
30
|
-
if internal_integer?(value) && value >= 0
|
|
31
|
-
if result_builder.instance.respond_to?(:to_hash)
|
|
32
|
-
# An object instance is valid against "minProperties" if its number of properties is greater than, or equal to, the value of this keyword.
|
|
33
|
-
result_builder.validate(
|
|
34
|
-
result_builder.instance.size >= value,
|
|
35
|
-
'instance object contains fewer properties than `minProperties` value',
|
|
36
|
-
keyword: 'minProperties',
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
else
|
|
40
|
-
result_builder.schema_error('`minProperties` is not a non-negative integer', 'minProperties')
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JSI
|
|
4
|
-
module Schema::Validation::Pattern
|
|
5
|
-
# @private
|
|
6
|
-
def internal_validate_pattern(result_builder)
|
|
7
|
-
if keyword?('pattern')
|
|
8
|
-
value = schema_content['pattern']
|
|
9
|
-
# The value of this keyword MUST be a string.
|
|
10
|
-
if value.respond_to?(:to_str)
|
|
11
|
-
if result_builder.instance.respond_to?(:to_str)
|
|
12
|
-
begin
|
|
13
|
-
# This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression
|
|
14
|
-
# dialect.
|
|
15
|
-
# TODO
|
|
16
|
-
regexp = Regexp.new(value)
|
|
17
|
-
# A string instance is considered valid if the regular expression matches the instance
|
|
18
|
-
# succssfully. Recall: regular expressions are not implicitly anchored.
|
|
19
|
-
result_builder.validate(
|
|
20
|
-
regexp.match(result_builder.instance),
|
|
21
|
-
'instance string does not match `pattern` regular expression value',
|
|
22
|
-
keyword: 'pattern',
|
|
23
|
-
)
|
|
24
|
-
rescue RegexpError => e
|
|
25
|
-
result_builder.schema_error(-"`pattern` is not a valid regular expression: #{e.message}", 'pattern')
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
else
|
|
29
|
-
result_builder.schema_error('`pattern` is not a string', 'pattern')
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|