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.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +3 -4
  3. data/CHANGELOG.md +19 -0
  4. data/LICENSE.md +2 -3
  5. data/README.md +87 -43
  6. data/docs/Glossary.md +313 -0
  7. data/jsi.gemspec +1 -1
  8. data/lib/jsi/base/mutability.rb +48 -0
  9. data/lib/jsi/base/node.rb +66 -52
  10. data/lib/jsi/base.rb +593 -176
  11. data/lib/jsi/jsi_coder.rb +4 -2
  12. data/lib/jsi/metaschema_node/bootstrap_schema.rb +118 -59
  13. data/lib/jsi/metaschema_node.rb +245 -154
  14. data/lib/jsi/ptr.rb +45 -17
  15. data/lib/jsi/ref.rb +197 -0
  16. data/lib/jsi/registry.rb +311 -0
  17. data/lib/jsi/schema/cxt/child_application.rb +35 -0
  18. data/lib/jsi/schema/cxt/inplace_application.rb +37 -0
  19. data/lib/jsi/schema/cxt.rb +80 -0
  20. data/lib/jsi/schema/dialect.rb +137 -0
  21. data/lib/jsi/schema/draft04.rb +113 -5
  22. data/lib/jsi/schema/draft06.rb +123 -5
  23. data/lib/jsi/schema/draft07.rb +157 -5
  24. data/lib/jsi/schema/draft202012.rb +303 -0
  25. data/lib/jsi/schema/dynamic_anchor_map.rb +63 -0
  26. data/lib/jsi/schema/element.rb +69 -0
  27. data/lib/jsi/schema/elements/anchor.rb +13 -0
  28. data/lib/jsi/schema/elements/array_validation.rb +82 -0
  29. data/lib/jsi/schema/elements/comment.rb +10 -0
  30. data/lib/jsi/schema/{validation → elements}/const.rb +11 -7
  31. data/lib/jsi/schema/elements/contains.rb +59 -0
  32. data/lib/jsi/schema/elements/contains_minmax.rb +91 -0
  33. data/lib/jsi/schema/elements/content_encoding.rb +10 -0
  34. data/lib/jsi/schema/elements/content_media_type.rb +10 -0
  35. data/lib/jsi/schema/elements/content_schema.rb +16 -0
  36. data/lib/jsi/schema/elements/default.rb +11 -0
  37. data/lib/jsi/schema/elements/definitions.rb +19 -0
  38. data/lib/jsi/schema/elements/dependencies.rb +99 -0
  39. data/lib/jsi/schema/elements/dependent_required.rb +49 -0
  40. data/lib/jsi/schema/elements/dependent_schemas.rb +69 -0
  41. data/lib/jsi/schema/elements/dynamic_ref.rb +69 -0
  42. data/lib/jsi/schema/elements/enum.rb +26 -0
  43. data/lib/jsi/schema/elements/examples.rb +10 -0
  44. data/lib/jsi/schema/elements/format.rb +10 -0
  45. data/lib/jsi/schema/elements/id.rb +30 -0
  46. data/lib/jsi/schema/elements/if_then_else.rb +82 -0
  47. data/lib/jsi/schema/elements/info_bool.rb +10 -0
  48. data/lib/jsi/schema/elements/info_string.rb +10 -0
  49. data/lib/jsi/schema/elements/items.rb +93 -0
  50. data/lib/jsi/schema/elements/items_prefixed.rb +96 -0
  51. data/lib/jsi/schema/elements/not.rb +31 -0
  52. data/lib/jsi/schema/elements/numeric.rb +137 -0
  53. data/lib/jsi/schema/elements/numeric_draft04.rb +77 -0
  54. data/lib/jsi/schema/elements/object_validation.rb +55 -0
  55. data/lib/jsi/schema/elements/pattern.rb +35 -0
  56. data/lib/jsi/schema/elements/properties.rb +145 -0
  57. data/lib/jsi/schema/elements/property_names.rb +48 -0
  58. data/lib/jsi/schema/elements/ref.rb +62 -0
  59. data/lib/jsi/schema/elements/required.rb +34 -0
  60. data/lib/jsi/schema/elements/self.rb +24 -0
  61. data/lib/jsi/schema/elements/some_of.rb +180 -0
  62. data/lib/jsi/schema/elements/string_validation.rb +57 -0
  63. data/lib/jsi/schema/elements/type.rb +43 -0
  64. data/lib/jsi/schema/elements/unevaluated_items.rb +54 -0
  65. data/lib/jsi/schema/elements/unevaluated_properties.rb +54 -0
  66. data/lib/jsi/schema/elements/xschema.rb +10 -0
  67. data/lib/jsi/schema/elements/xvocabulary.rb +10 -0
  68. data/lib/jsi/schema/elements.rb +101 -0
  69. data/lib/jsi/schema/issue.rb +3 -4
  70. data/lib/jsi/schema/schema_ancestor_node.rb +105 -52
  71. data/lib/jsi/schema/vocabulary.rb +36 -0
  72. data/lib/jsi/schema.rb +598 -383
  73. data/lib/jsi/schema_classes.rb +195 -141
  74. data/lib/jsi/schema_set.rb +85 -128
  75. data/lib/jsi/set.rb +23 -0
  76. data/lib/jsi/simple_wrap.rb +14 -17
  77. data/lib/jsi/struct.rb +57 -0
  78. data/lib/jsi/uri.rb +40 -0
  79. data/lib/jsi/util/private/memo_map.rb +9 -13
  80. data/lib/jsi/util/private.rb +59 -31
  81. data/lib/jsi/util/typelike.rb +19 -60
  82. data/lib/jsi/util.rb +53 -34
  83. data/lib/jsi/validation/error.rb +45 -2
  84. data/lib/jsi/validation/result.rb +121 -90
  85. data/lib/jsi/validation.rb +1 -6
  86. data/lib/jsi/version.rb +1 -1
  87. data/lib/jsi.rb +170 -36
  88. data/lib/schemas/json-schema.org/draft/2020-12/schema.rb +62 -0
  89. data/lib/schemas/json-schema.org/draft-04/schema.rb +60 -109
  90. data/lib/schemas/json-schema.org/draft-06/schema.rb +53 -108
  91. data/lib/schemas/json-schema.org/draft-07/schema.rb +63 -127
  92. data/readme.rb +4 -4
  93. data/{resources}/schemas/2020-12_strict.json +19 -0
  94. data/{resources}/schemas/json-schema.org/draft/2020-12/meta/applicator.json +48 -0
  95. data/{resources}/schemas/json-schema.org/draft/2020-12/meta/content.json +17 -0
  96. data/{resources}/schemas/json-schema.org/draft/2020-12/meta/core.json +51 -0
  97. data/{resources}/schemas/json-schema.org/draft/2020-12/meta/format-annotation.json +14 -0
  98. data/{resources}/schemas/json-schema.org/draft/2020-12/meta/format-assertion.json +14 -0
  99. data/{resources}/schemas/json-schema.org/draft/2020-12/meta/meta-data.json +37 -0
  100. data/{resources}/schemas/json-schema.org/draft/2020-12/meta/unevaluated.json +15 -0
  101. data/{resources}/schemas/json-schema.org/draft/2020-12/meta/validation.json +98 -0
  102. data/{resources}/schemas/json-schema.org/draft/2020-12/schema.json +58 -0
  103. metadata +73 -52
  104. data/docs/glossary.md +0 -281
  105. data/lib/jsi/metaschema.rb +0 -6
  106. data/lib/jsi/schema/application/child_application/contains.rb +0 -25
  107. data/lib/jsi/schema/application/child_application/draft04.rb +0 -21
  108. data/lib/jsi/schema/application/child_application/draft06.rb +0 -28
  109. data/lib/jsi/schema/application/child_application/draft07.rb +0 -28
  110. data/lib/jsi/schema/application/child_application/items.rb +0 -18
  111. data/lib/jsi/schema/application/child_application/properties.rb +0 -25
  112. data/lib/jsi/schema/application/child_application.rb +0 -13
  113. data/lib/jsi/schema/application/draft04.rb +0 -8
  114. data/lib/jsi/schema/application/draft06.rb +0 -8
  115. data/lib/jsi/schema/application/draft07.rb +0 -8
  116. data/lib/jsi/schema/application/inplace_application/dependencies.rb +0 -28
  117. data/lib/jsi/schema/application/inplace_application/draft04.rb +0 -25
  118. data/lib/jsi/schema/application/inplace_application/draft06.rb +0 -26
  119. data/lib/jsi/schema/application/inplace_application/draft07.rb +0 -32
  120. data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +0 -20
  121. data/lib/jsi/schema/application/inplace_application/ref.rb +0 -18
  122. data/lib/jsi/schema/application/inplace_application/someof.rb +0 -44
  123. data/lib/jsi/schema/application/inplace_application.rb +0 -14
  124. data/lib/jsi/schema/application.rb +0 -12
  125. data/lib/jsi/schema/ref.rb +0 -183
  126. data/lib/jsi/schema/validation/array.rb +0 -69
  127. data/lib/jsi/schema/validation/contains.rb +0 -25
  128. data/lib/jsi/schema/validation/dependencies.rb +0 -49
  129. data/lib/jsi/schema/validation/draft04/minmax.rb +0 -91
  130. data/lib/jsi/schema/validation/draft04.rb +0 -110
  131. data/lib/jsi/schema/validation/draft06.rb +0 -120
  132. data/lib/jsi/schema/validation/draft07.rb +0 -157
  133. data/lib/jsi/schema/validation/enum.rb +0 -25
  134. data/lib/jsi/schema/validation/ifthenelse.rb +0 -46
  135. data/lib/jsi/schema/validation/items.rb +0 -54
  136. data/lib/jsi/schema/validation/not.rb +0 -20
  137. data/lib/jsi/schema/validation/numeric.rb +0 -121
  138. data/lib/jsi/schema/validation/object.rb +0 -45
  139. data/lib/jsi/schema/validation/pattern.rb +0 -34
  140. data/lib/jsi/schema/validation/properties.rb +0 -101
  141. data/lib/jsi/schema/validation/property_names.rb +0 -32
  142. data/lib/jsi/schema/validation/ref.rb +0 -40
  143. data/lib/jsi/schema/validation/required.rb +0 -27
  144. data/lib/jsi/schema/validation/someof.rb +0 -90
  145. data/lib/jsi/schema/validation/string.rb +0 -47
  146. data/lib/jsi/schema/validation/type.rb +0 -49
  147. data/lib/jsi/schema/validation.rb +0 -49
  148. data/lib/jsi/schema_registry.rb +0 -190
  149. data/lib/jsi/util/private/attr_struct.rb +0 -130
data/docs/glossary.md DELETED
@@ -1,281 +0,0 @@
1
- # Glossary
2
-
3
-
4
- ## Background
5
-
6
- The terminology JSI uses comes from a number of sources:
7
-
8
- - [JSON Schema](https://json-schema.org/) and its [specifications](https://json-schema.org/specification-links.html)
9
- - The [JSON Schema Glossary](https://json-schema.org/learn/glossary.html)
10
- - [JSON](https://www.json.org/) and its specification
11
- - Tree data structure ([Wikipedia](https://en.wikipedia.org/wiki/Tree_(data_structure)))
12
- - Object-oriented programming ([Wikipedia](https://en.wikipedia.org/wiki/Object-oriented_programming))
13
- - The Ruby programming language
14
- - [JSON Pointer](https://www.rfc-editor.org/rfc/rfc6901)
15
-
16
- The terminology from these can be contradictory, e.g. 'object' in JSON meaning what is a Hash in Ruby, but 'object' in Ruby meaning any object as in object-oriented programming. This glossary aims to clarify any ambiguity and introduce any terms which may not be familiar to the reader.
17
-
18
-
19
- ## Terms
20
-
21
-
22
- - ### JSI
23
-
24
- [JSI]: #JSI
25
- [a JSI]: #JSI
26
-
27
- JSI is the name of this library. As a [countable](https://en.wikipedia.org/wiki/Count_noun), "a JSI" refers to the library's instantiation of an instance of a set of [schema]s. This is a Ruby instance of a subclass of {JSI::Base}.
28
-
29
- The subclass of JSI::Base which a JSI is instantiated as includes the [schema module] of each schema that describes the instance (its {JSI::Base#jsi_schemas}), as well as type-specific modules for [array] and [hash/object] instances.
30
-
31
-
32
- - ### node
33
-
34
- [node]: #node
35
-
36
- A node is an element in a [document] at a location identified by a [pointer].
37
-
38
- In JSI a node generally means [a JSI] - a JSI::Base instance is often referred to just as "a JSI", but is referred to as a node in the context of its relationship to other nodes in its document.
39
-
40
-
41
- - ### node content
42
-
43
- [content]: #node_content
44
-
45
- The content of a [node] is the parsed JSON instance.
46
- It is generally a Ruby Hash, Array, String, Integer, Float or BigDecimal, true, false, or nil.
47
-
48
- This content is referred to as the 'instance' in relation to [schema]s that describe it.
49
-
50
- See {JSI::Base#jsi_node_content} (also aliased as {JSI::Base#jsi_instance}.
51
-
52
-
53
- - ### document
54
-
55
- [document]: #document
56
-
57
- The document is the [content] of the [root] [node].
58
-
59
- See {JSI::Base#jsi_document}.
60
-
61
-
62
- - ### root
63
-
64
- [root]: #root
65
-
66
- A [node] representing the whole of a [document].
67
-
68
- Its [pointer] is empty (has zero [token]s).
69
-
70
- See {JSI::Base#jsi_root_node}.
71
-
72
-
73
- - ### complex
74
-
75
- [complex]: #complex
76
-
77
- A [node] that can have [child]ren is complex. Its [content] is an [array] or a [hash/object].
78
-
79
- Hash and Array nodes can mostly be used like Ruby Hashes and Arrays. JSI defines or delegates the methods of Hash and Array with nearly perfect compatibility, and supports [implicit conversion](https://docs.ruby-lang.org/en/master/implicit_conversion_rdoc.html) with `#to_hash` and `#to_ary`.
80
-
81
- These nodes also support implicit conversion for the instance's content, treating any object responding to `#to_hash` or `#to_ary` like Hash or Array - though it is most common that actual Hash and Array instances will be the content. (This support may be incomplete for node content that is implicitly convertible but does not respond to certain methods, especially `#[]`.)
82
-
83
-
84
- - ### child
85
-
86
- [child]: #child
87
-
88
- A [node] immediately below another node, its [parent]. Identified by one [token] relative to the parent.
89
-
90
- See {JSI::Base#[]}.
91
-
92
-
93
- - ### parent
94
-
95
- [parent]: #parent
96
-
97
- A [node] immediately above some number of other nodes, its [child]ren. A node that can be a parent node must be [complex].
98
-
99
- See {JSI::Base#jsi_parent_node}.
100
-
101
-
102
- - ### descendent
103
-
104
- [descendent]: #descendent
105
-
106
- A [node] anywhere below another node, its [ancestor]. Identified by a relative [pointer]. A node is considered to be a descendent of itself (at an empty relative pointer).
107
-
108
- See {JSI::Base#jsi_descendent_node}, {JSI::Base#jsi_each_descendent_node}.
109
-
110
-
111
- - ### ancestor
112
-
113
- [ancestor]: #ancestor
114
-
115
- A [node] anywhere above another node, its [descendent]. A node is considered to be an ancestor of itself, and the [root] node is an ancestor of every node in the [document].
116
-
117
- See {JSI::Base#jsi_ancestor_nodes}.
118
-
119
-
120
- - ### token
121
-
122
- [token]: #token
123
-
124
- An [array] [index] or [hash/object] [property name/key] that identifies a child node of its parent. Generally a String or non-negative Integer. [JSON Pointer](https://www.rfc-editor.org/rfc/rfc6901) calls this a "reference token".
125
-
126
- A sequence of tokens comprises a [pointer].
127
-
128
-
129
- - ### pointer
130
-
131
- [pointer]: #pointer
132
-
133
- A sequence of [token]s which identifies a [descendent] of a [node], instantiated as a {JSI::Ptr}.
134
-
135
- [JSON Pointers](https://www.rfc-editor.org/rfc/rfc6901) are parsed to JSI pointers.
136
-
137
- A pointer may be referred to as 'absolute' when identifying a descendent of the root node (see {JSI::Base#jsi_ptr}), or 'relative' identifying a descendent of any node (such as the pointer passed to {JSI::Base#jsi_descendent_node}).
138
-
139
-
140
- - ### hash/object
141
-
142
- [hash/object]: #hash_object
143
-
144
- The [content] of a [complex] JSI Hash [node] (see {JSI::Base::HashNode}), representing a JSON object, is typically a Ruby Hash, or [implicitly convertible](https://docs.ruby-lang.org/en/master/implicit_conversion_rdoc.html) with `#to_hash`.
145
-
146
-
147
- - ### array
148
-
149
- [array]: #array
150
-
151
- The [content] of a [complex] JSI Array [node] (see {JSI::Base::ArrayNode}) is typically a Ruby Array, or [implicitly convertible](https://docs.ruby-lang.org/en/master/implicit_conversion_rdoc.html) with `#to_ary`.
152
-
153
-
154
- - ### property name/key
155
-
156
- [property name/key]: #property_name_key
157
-
158
- A [token] identifying a [child] of a [hash/object] [node]. In Ruby, a Hash key; in JSON Schema, an object property name. Property names are expected to be strings, though Ruby Hash keys do not have this limitation. Note that Symbols are not Strings, and Symbols should not be used in JSI [node content].
159
-
160
- Property names can be described by schemas (using the `propertyNames` keyword), and can be JSI instances of those schemas. See {JSI::Base::HashNode#jsi_each_propertyName}.
161
-
162
-
163
- - ### index
164
-
165
- [index]: #index
166
-
167
- A [token] identifying a [child] of an [array] [node]. A non-negative integer.
168
-
169
-
170
- - ### instance
171
-
172
- [instance]: #instance
173
-
174
- A heavily-overloaded term. Context should make it clear in what sense it is being used. 'Instance' can refer to an *object* or a *relationship*, in Ruby or JSON Schema or JSI instantiation:
175
-
176
- - JSON Schema: the _instance_ (JSON data) is an _instance_ (relationship) of [JSON Schemas][schema] that describe it
177
- - Ruby: the _instance_ (an Object) is an _instance_ (relationship) of a Class and included Modules
178
- - JSI: the _instance_ ([a JSI]) is an _instance_ (relationship) of JSI Schemas
179
-
180
- These all operate in parallel in JSI: a JSI instance represents a JSON instance, it is described by JSI Schemas which represent JSON Schemas, and it is a Ruby instance of [JSI Schema Modules][schema module] of each schema that describes it.
181
-
182
-
183
- - ### schema
184
-
185
- [schema]: #schema
186
-
187
- A JSI Schema is [a JSI] that represents a JSON Schema. It is a Ruby instance of the module {JSI::Schema}.
188
-
189
- A schema describes a set of [instance]s. Any JSI instance that is described by a given schema is a Ruby instance of that schema's [schema module].
190
-
191
- A schema is described by a [meta-schema] and is a Ruby instance of that meta-schema's [schema module].
192
-
193
-
194
- - ### schema module
195
-
196
- [schema module]: #schema_module
197
-
198
- A JSI Schema Module is a Ruby module associated with a particular [schema]. Any JSI [instance] that is described by the schema is a Ruby instance of the schema's schema module. This is a {JSI::SchemaModule}.
199
-
200
- See {JSI::Schema#jsi_schema_module}.
201
-
202
- A JSI Schema Module is not to be confused with the module {JSI::Schema} - a schema *is* a Ruby instance of the module JSI::Schema, and it *has* a JSI Schema Module. The module JSI::Schema is included on the JSI Schema module of a [meta-schema].
203
-
204
-
205
- - ### meta-schema
206
-
207
- [meta-schema]: #meta-schema
208
-
209
- A meta-schema is a [schema] that describes schemas, i.e. [instance]s of the meta-schema are schemas.
210
-
211
- As with any other instance, a JSI schema includes the [schema module] of the meta-schema that describes it. The meta-schema's schema module defines the functionality for its instances to behave as schemas, including the module {JSI::Schema} as well as other modules implementing functionality particular to that meta-schema.
212
-
213
- A meta-schema is described by a meta-schema, which may be itself or another meta-schema. Examples of self-describing meta-schemas are the JSON Schema meta-schemas. An example of the latter is the [schema describing the OpenAPI v3.0 Schema object](https://github.com/OAI/OpenAPI-Specification/blob/3.0.3/schemas/v3.0/schema.yaml#L203), which describes schemas in OpenAPI documents, but is itself described by JSON Schema draft 04.
214
-
215
- A self-describing meta-schema is a Ruby instance of its own schema module.
216
-
217
- See {JSI::Schema::DescribesSchema} and {JSI::SchemaModule::DescribesSchemaModule}, {JSI::Schema#describes_schema?} and {JSI::Schema#describes_schema!}
218
-
219
-
220
- - ### resource
221
-
222
- [resource]: #resource
223
-
224
- A resource, or schema resource, is either:
225
-
226
- - A [schema] that is identified by an absolute URI (declared with an id keyword)
227
- - The root of a document containing schemas, whether or not the root is itself a schema. (Technically the root of any document can be considered a resource, but it is only useful when the document contains schemas.)
228
-
229
- The nearest ancestor that is a resource is a node's "resource root" - this is distinct from the [root] node of the whole document.
230
-
231
- Relative URIs and [pointer]s used by a schema (e.g. in `$ref` or `$id`) are resolved relative to its resource root and that resource's id.
232
-
233
- See {JSI::Schema#schema_resource_root}
234
-
235
-
236
- - ### schema application
237
-
238
- [schema application]: #schema_application
239
-
240
- The computation of schemas that apply describing a [node] at a given location. This involves several steps:
241
-
242
- - **root indicated schemas**: Application begins with the schemas (usually just one schema) indicated as describing the [root]. `#new_jsi` is invoked on a {JSI::SchemaSet} of the indicated schemas, or more commonly on one schema or [schema module]. These are the root's {JSI::Base#jsi_indicated_schemas}.
243
- - **root applied schemas**: [in-place application] is performed on each of the root indicated schemas to compute its applied schemas, i.e. its {JSI::Base#jsi_schemas}.
244
- - Descending from the root to the given node, for each [token] of the node's [pointer]:
245
- - **child indicated schemas**: [child application] is performed on each applied schema of the parent on the current token. This results in the child's indicated schemas.
246
- - **child applied schemas**: [in-place application] is performed on each child indicated schema to compute its applied schemas.
247
-
248
- The schemas that apply describing the node are the result of the final in-place application.
249
-
250
-
251
- - ### child application
252
-
253
- [child application]: #child_application
254
-
255
- The computation of subschemas of a given schema that apply to a [child] of a [complex] instance on a given [token]. These come from subschemas defined on child applicator keywords such as `properties` and `items`. The result may be an empty schema set if no such keywords are present or none apply.
256
-
257
-
258
- - ### in-place application
259
-
260
- [in-place application]: #in_place_application
261
-
262
- The resolution or expansion of a schema to a set of **applied schemas** for a given instance. "In-place" means all the schemas apply to the same location in the instance, in contrast to [child application]. This is a recursive process.
263
-
264
- - If the schema contains a `$ref` keyword:
265
- - The reference is resolved and in-place application is performed on the resolved schema.
266
- - The schema containing the reference is _not_ applied.
267
- - No other applicator keywords should be present; if present they are ignored.
268
-
269
- The resulting applied schemas are those of the reference's resolved schema.
270
-
271
- - Otherwise:
272
- - The schema applies itself (it is added to the set of applied schemas).
273
- - Any in-place applicator keywords (`anyOf`, `dependencies`, etc.) are evaluated for subschemas that apply to the instance. For each such subschema, in-place application is performed and the resulting schemas are added to the applied schemas.
274
-
275
- The resulting applied schemas are the given schema plus the results of in-place application of each applicable subschema.
276
-
277
- - ### validation
278
-
279
- [validation]: #validation
280
-
281
- The process of determining whether a given [instance] is valid against the [schema]s that describe it, or collecting validation errors indicating why the instance is not valid. See {JSI::Base#jsi_valid?}, {JSI::Base#jsi_validate}, {JSI::Schema#instance_valid?}, {JSI::Schema#instance_validate}
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Metaschema
5
- end
6
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::ChildApplication::Contains
5
- # @private
6
- def internal_applicate_contains(idx, instance, &block)
7
- if keyword?('contains')
8
- contains_schema = subschema(['contains'])
9
-
10
- child_idx_valid = Hash.new { |h, i| h[i] = contains_schema.instance_valid?(instance[i]) }
11
-
12
- if child_idx_valid[idx]
13
- yield contains_schema
14
- else
15
- instance_valid = instance.each_index.any? { |i| child_idx_valid[i] }
16
-
17
- unless instance_valid
18
- # invalid application: if contains_schema does not validate against any child, it applies to every child
19
- yield contains_schema
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::ChildApplication::Draft04
5
- include Schema::Application::ChildApplication::Items
6
- include Schema::Application::ChildApplication::Properties
7
-
8
- # @private
9
- def internal_child_applicate_keywords(token, instance, &block)
10
- if instance.respond_to?(:to_ary)
11
- # 5.3.1. additionalItems and items
12
- internal_applicate_items(token, &block)
13
- end
14
-
15
- if instance.respond_to?(:to_hash)
16
- # 5.4.4. additionalProperties, properties and patternProperties
17
- internal_applicate_properties(token, &block)
18
- end
19
- end
20
- end
21
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::ChildApplication::Draft06
5
- include Schema::Application::ChildApplication::Items
6
- include Schema::Application::ChildApplication::Contains
7
- include Schema::Application::ChildApplication::Properties
8
-
9
- # @private
10
- def internal_child_applicate_keywords(token, instance, &block)
11
- if instance.respond_to?(:to_ary)
12
- # json-schema-validation 6.9. items
13
- # json-schema-validation 6.10. additionalItems
14
- internal_applicate_items(token, &block)
15
-
16
- # json-schema-validation 6.14. contains
17
- internal_applicate_contains(token, instance, &block)
18
- end
19
-
20
- if instance.respond_to?(:to_hash)
21
- # json-schema-validation 6.18. properties
22
- # json-schema-validation 6.19. patternProperties
23
- # json-schema-validation 6.20. additionalProperties
24
- internal_applicate_properties(token, &block)
25
- end
26
- end
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::ChildApplication::Draft07
5
- include Schema::Application::ChildApplication::Items
6
- include Schema::Application::ChildApplication::Contains
7
- include Schema::Application::ChildApplication::Properties
8
-
9
- # @private
10
- def internal_child_applicate_keywords(token, instance, &block)
11
- if instance.respond_to?(:to_ary)
12
- # 6.4.1. items
13
- # 6.4.2. additionalItems
14
- internal_applicate_items(token, &block)
15
-
16
- # 6.4.6. contains
17
- internal_applicate_contains(token, instance, &block)
18
- end
19
-
20
- if instance.respond_to?(:to_hash)
21
- # 6.5.4. properties
22
- # 6.5.5. patternProperties
23
- # 6.5.6. additionalProperties
24
- internal_applicate_properties(token, &block)
25
- end
26
- end
27
- end
28
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::ChildApplication::Items
5
- # @private
6
- def internal_applicate_items(idx, &block)
7
- if keyword?('items') && schema_content['items'].respond_to?(:to_ary)
8
- if schema_content['items'].each_index.to_a.include?(idx)
9
- yield subschema(['items', idx])
10
- elsif keyword?('additionalItems')
11
- yield subschema(['additionalItems'])
12
- end
13
- elsif keyword?('items')
14
- yield subschema(['items'])
15
- end
16
- end
17
- end
18
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::ChildApplication::Properties
5
- # @private
6
- def internal_applicate_properties(property_name, &block)
7
- apply_additional = true
8
- if keyword?('properties') && schema_content['properties'].respond_to?(:to_hash) && schema_content['properties'].key?(property_name)
9
- apply_additional = false
10
- yield subschema(['properties', property_name])
11
- end
12
- if keyword?('patternProperties') && schema_content['patternProperties'].respond_to?(:to_hash)
13
- schema_content['patternProperties'].each_key do |pattern|
14
- if pattern.respond_to?(:to_str) && property_name.to_s =~ Regexp.new(pattern) # TODO map pattern to ruby syntax
15
- apply_additional = false
16
- yield subschema(['patternProperties', pattern])
17
- end
18
- end
19
- end
20
- if apply_additional && keyword?('additionalProperties')
21
- yield subschema(['additionalProperties'])
22
- end
23
- end
24
- end
25
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::ChildApplication
5
- autoload :Draft04, 'jsi/schema/application/child_application/draft04'
6
- autoload :Draft06, 'jsi/schema/application/child_application/draft06'
7
- autoload :Draft07, 'jsi/schema/application/child_application/draft07'
8
-
9
- autoload :Items, 'jsi/schema/application/child_application/items'
10
- autoload :Contains, 'jsi/schema/application/child_application/contains'
11
- autoload :Properties, 'jsi/schema/application/child_application/properties'
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::Draft04
5
- include Schema::Application::InplaceApplication::Draft04
6
- include Schema::Application::ChildApplication::Draft04
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::Draft06
5
- include Schema::Application::InplaceApplication::Draft06
6
- include Schema::Application::ChildApplication::Draft06
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::Draft07
5
- include Schema::Application::InplaceApplication::Draft07
6
- include Schema::Application::ChildApplication::Draft07
7
- end
8
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::InplaceApplication::Dependencies
5
- # @private
6
- def internal_applicate_dependencies(instance, visited_refs, &block)
7
- if keyword?('dependencies')
8
- value = schema_content['dependencies']
9
- # This keyword's value MUST be an object. Each property specifies a dependency. Each dependency
10
- # value MUST be an array or a valid JSON Schema.
11
- if value.respond_to?(:to_hash)
12
- value.each_pair do |property_name, dependency|
13
- if dependency.respond_to?(:to_ary)
14
- # noop: array-form dependencies has no inplace applicator schema
15
- else
16
- # If the dependency value is a subschema, and the dependency key is a
17
- # property in the instance, the entire instance must validate against
18
- # the dependency value.
19
- if instance.respond_to?(:to_hash) && instance.key?(property_name)
20
- subschema(['dependencies', property_name]).each_inplace_applicator_schema(instance, visited_refs: visited_refs, &block)
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::InplaceApplication::Draft04
5
- include Schema::Application::InplaceApplication::Ref
6
- include Schema::Application::InplaceApplication::Dependencies
7
- include Schema::Application::InplaceApplication::SomeOf
8
-
9
- # @private
10
- def internal_inplace_applicate_keywords(instance, visited_refs, &block)
11
- internal_applicate_ref(instance, visited_refs, throw_done: true, &block)
12
-
13
- # self is the first applicator schema if $ref has not short-circuited it
14
- yield self
15
-
16
- # 5.4.5. dependencies
17
- internal_applicate_dependencies(instance, visited_refs, &block)
18
-
19
- # 5.5.3. allOf
20
- # 5.5.4. anyOf
21
- # 5.5.5. oneOf
22
- internal_applicate_someOf(instance, visited_refs, &block)
23
- end
24
- end
25
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::InplaceApplication::Draft06
5
- include Schema::Application::InplaceApplication::Ref
6
- include Schema::Application::InplaceApplication::Dependencies
7
- include Schema::Application::InplaceApplication::SomeOf
8
-
9
- # @private
10
- def internal_inplace_applicate_keywords(instance, visited_refs, &block)
11
- # json-schema 8. Schema references with $ref
12
- internal_applicate_ref(instance, visited_refs, throw_done: true, &block)
13
-
14
- # self is the first applicator schema if $ref has not short-circuited it
15
- yield self
16
-
17
- # json-schema-validation 6.21. dependencies
18
- internal_applicate_dependencies(instance, visited_refs, &block)
19
-
20
- # json-schema-validation 6.26. allOf
21
- # json-schema-validation 6.27. anyOf
22
- # json-schema-validation 6.28. oneOf
23
- internal_applicate_someOf(instance, visited_refs, &block)
24
- end
25
- end
26
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::InplaceApplication::Draft07
5
- include Schema::Application::InplaceApplication::Ref
6
- include Schema::Application::InplaceApplication::Dependencies
7
- include Schema::Application::InplaceApplication::IfThenElse
8
- include Schema::Application::InplaceApplication::SomeOf
9
-
10
- # @private
11
- def internal_inplace_applicate_keywords(instance, visited_refs, &block)
12
- # json-schema 8. Schema references with $ref
13
- internal_applicate_ref(instance, visited_refs, throw_done: true, &block)
14
-
15
- # self is the first applicator schema if $ref has not short-circuited it
16
- block.call(self)
17
-
18
- # 6.5.7. dependencies
19
- internal_applicate_dependencies(instance, visited_refs, &block)
20
-
21
- # 6.6.1. if
22
- # 6.6.2. then
23
- # 6.6.3. else
24
- internal_applicate_ifthenelse(instance, visited_refs, &block)
25
-
26
- # 6.7.1. allOf
27
- # 6.7.2. anyOf
28
- # 6.7.3. oneOf
29
- internal_applicate_someOf(instance, visited_refs, &block)
30
- end
31
- end
32
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::InplaceApplication::IfThenElse
5
- # @private
6
- def internal_applicate_ifthenelse(instance, visited_refs, &block)
7
- if keyword?('if')
8
- if subschema(['if']).instance_valid?(instance)
9
- if keyword?('then')
10
- subschema(['then']).each_inplace_applicator_schema(instance, visited_refs: visited_refs, &block)
11
- end
12
- else
13
- if keyword?('else')
14
- subschema(['else']).each_inplace_applicator_schema(instance, visited_refs: visited_refs, &block)
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JSI
4
- module Schema::Application::InplaceApplication::Ref
5
- # @private
6
- def internal_applicate_ref(instance, visited_refs, throw_done: false, &block)
7
- if keyword?('$ref') && schema_content['$ref'].respond_to?(:to_str)
8
- ref = schema_ref
9
- unless visited_refs.include?(ref)
10
- ref.deref_schema.each_inplace_applicator_schema(instance, visited_refs: visited_refs + [ref], &block)
11
- if throw_done
12
- throw(:jsi_application_done)
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end