jsi-dev 0.0.8 → 0.0.9
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 → Glossary.md} +84 -52
- 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 +592 -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 +244 -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/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
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module JSI
|
|
4
|
+
module Schema::Elements
|
|
5
|
+
def self.element_map(&block)
|
|
6
|
+
Util::MemoMap::Immutable.new(&block)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module Schema::Elements
|
|
11
|
+
# the schema itself
|
|
12
|
+
autoload(:SELF, 'jsi/schema/elements/self')
|
|
13
|
+
|
|
14
|
+
# $schema
|
|
15
|
+
autoload(:XSCHEMA, 'jsi/schema/elements/xschema')
|
|
16
|
+
|
|
17
|
+
# $vocabulary
|
|
18
|
+
autoload(:XVOCABULARY, 'jsi/schema/elements/xvocabulary')
|
|
19
|
+
|
|
20
|
+
# id
|
|
21
|
+
autoload(:ID, 'jsi/schema/elements/id')
|
|
22
|
+
|
|
23
|
+
# anchor
|
|
24
|
+
autoload(:ANCHOR, 'jsi/schema/elements/anchor')
|
|
25
|
+
|
|
26
|
+
# definitions
|
|
27
|
+
autoload(:DEFINITIONS, 'jsi/schema/elements/definitions')
|
|
28
|
+
|
|
29
|
+
# $comment
|
|
30
|
+
autoload(:COMMENT, 'jsi/schema/elements/comment')
|
|
31
|
+
|
|
32
|
+
# ref in-place application
|
|
33
|
+
autoload(:REF, 'jsi/schema/elements/ref')
|
|
34
|
+
autoload(:DYNAMIC_REF, 'jsi/schema/elements/dynamic_ref')
|
|
35
|
+
|
|
36
|
+
# in-place subschema application
|
|
37
|
+
autoload(:IF_THEN_ELSE, 'jsi/schema/elements/if_then_else')
|
|
38
|
+
autoload(:DEPENDENCIES, 'jsi/schema/elements/dependencies')
|
|
39
|
+
autoload(:DEPENDENT_SCHEMAS, 'jsi/schema/elements/dependent_schemas')
|
|
40
|
+
autoload(:ALL_OF, 'jsi/schema/elements/some_of')
|
|
41
|
+
autoload(:ANY_OF, 'jsi/schema/elements/some_of')
|
|
42
|
+
autoload(:ONE_OF, 'jsi/schema/elements/some_of')
|
|
43
|
+
|
|
44
|
+
# child subschema application
|
|
45
|
+
autoload(:ITEMS, 'jsi/schema/elements/items')
|
|
46
|
+
autoload(:ITEMS_PREFIXED, 'jsi/schema/elements/items_prefixed')
|
|
47
|
+
autoload(:CONTAINS, 'jsi/schema/elements/contains')
|
|
48
|
+
autoload(:CONTAINS_MINMAX, 'jsi/schema/elements/contains_minmax')
|
|
49
|
+
autoload(:PROPERTIES, 'jsi/schema/elements/properties')
|
|
50
|
+
autoload(:UNEVALUATED_PROPERTIES, 'jsi/schema/elements/unevaluated_properties')
|
|
51
|
+
autoload(:UNEVALUATED_ITEMS, 'jsi/schema/elements/unevaluated_items')
|
|
52
|
+
|
|
53
|
+
# property names subschema application
|
|
54
|
+
autoload(:PROPERTY_NAMES, 'jsi/schema/elements/property_names')
|
|
55
|
+
|
|
56
|
+
# any type validation
|
|
57
|
+
autoload(:TYPE, 'jsi/schema/elements/type')
|
|
58
|
+
autoload(:ENUM, 'jsi/schema/elements/enum')
|
|
59
|
+
autoload(:CONST, 'jsi/schema/elements/const')
|
|
60
|
+
autoload(:NOT, 'jsi/schema/elements/not')
|
|
61
|
+
|
|
62
|
+
# object validation
|
|
63
|
+
autoload(:REQUIRED, 'jsi/schema/elements/required')
|
|
64
|
+
autoload(:DEPENDENT_REQUIRED, 'jsi/schema/elements/dependent_required')
|
|
65
|
+
autoload(:MAX_PROPERTIES, 'jsi/schema/elements/object_validation')
|
|
66
|
+
autoload(:MIN_PROPERTIES, 'jsi/schema/elements/object_validation')
|
|
67
|
+
|
|
68
|
+
# array validation
|
|
69
|
+
autoload(:MAX_ITEMS, 'jsi/schema/elements/array_validation')
|
|
70
|
+
autoload(:MIN_ITEMS, 'jsi/schema/elements/array_validation')
|
|
71
|
+
autoload(:UNIQUE_ITEMS, 'jsi/schema/elements/array_validation')
|
|
72
|
+
|
|
73
|
+
# string validation
|
|
74
|
+
autoload(:MAX_LENGTH, 'jsi/schema/elements/string_validation')
|
|
75
|
+
autoload(:MIN_LENGTH, 'jsi/schema/elements/string_validation')
|
|
76
|
+
autoload(:PATTERN, 'jsi/schema/elements/pattern')
|
|
77
|
+
|
|
78
|
+
# numeric validation
|
|
79
|
+
autoload(:MULTIPLE_OF, 'jsi/schema/elements/numeric')
|
|
80
|
+
autoload(:MAXIMUM, 'jsi/schema/elements/numeric')
|
|
81
|
+
autoload(:EXCLUSIVE_MAXIMUM, 'jsi/schema/elements/numeric')
|
|
82
|
+
autoload(:MINIMUM, 'jsi/schema/elements/numeric')
|
|
83
|
+
autoload(:EXCLUSIVE_MINIMUM, 'jsi/schema/elements/numeric')
|
|
84
|
+
autoload(:MAXIMUM_BOOLEAN_EXCLUSIVE, 'jsi/schema/elements/numeric_draft04')
|
|
85
|
+
autoload(:MINIMUM_BOOLEAN_EXCLUSIVE, 'jsi/schema/elements/numeric_draft04')
|
|
86
|
+
|
|
87
|
+
# format
|
|
88
|
+
autoload(:FORMAT, 'jsi/schema/elements/format')
|
|
89
|
+
|
|
90
|
+
# content
|
|
91
|
+
autoload(:CONTENT_ENCODING, 'jsi/schema/elements/content_encoding')
|
|
92
|
+
autoload(:CONTENT_MEDIA_TYPE, 'jsi/schema/elements/content_media_type')
|
|
93
|
+
autoload(:CONTENT_SCHEMA, 'jsi/schema/elements/content_schema')
|
|
94
|
+
|
|
95
|
+
# metadata
|
|
96
|
+
autoload(:INFO_STRING, 'jsi/schema/elements/info_string')
|
|
97
|
+
autoload(:INFO_BOOL, 'jsi/schema/elements/info_bool')
|
|
98
|
+
autoload(:DEFAULT, 'jsi/schema/elements/default')
|
|
99
|
+
autoload(:EXAMPLES, 'jsi/schema/elements/examples')
|
|
100
|
+
end
|
|
101
|
+
end
|
data/lib/jsi/schema/issue.rb
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module JSI
|
|
4
4
|
module Schema
|
|
5
|
-
Issue =
|
|
5
|
+
Issue = Struct.subclass(*%i(
|
|
6
6
|
level
|
|
7
7
|
message
|
|
8
8
|
keyword
|
|
9
9
|
schema
|
|
10
|
-
)
|
|
10
|
+
))
|
|
11
11
|
|
|
12
12
|
# an issue or problem with a schema.
|
|
13
13
|
#
|
|
@@ -30,7 +30,6 @@ module JSI
|
|
|
30
30
|
# @!attribute schema
|
|
31
31
|
# the schema that has an issue
|
|
32
32
|
# @return [JSI::Schema]
|
|
33
|
-
class Issue
|
|
34
|
-
end
|
|
33
|
+
class Issue end
|
|
35
34
|
end
|
|
36
35
|
end
|
|
@@ -16,74 +16,122 @@ module JSI
|
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
#
|
|
20
|
-
# this is
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
|
|
19
|
+
# Base URI for URI resolution - always an absolute URI (with no fragment).
|
|
20
|
+
# If this node is a resource, its {#jsi_resource_uri} (i.e. its `$id`) is resolved against this URI, if that is relative.
|
|
21
|
+
#
|
|
22
|
+
# At the root this comes from param `base_uri` of {SchemaSet#new_jsi new_jsi}/{JSI.new_schema new_schema},
|
|
23
|
+
# or from a configured {Base::Conf#root_uri root_uri}.
|
|
24
|
+
# Below the root this comes from the parent's {#jsi_next_base_uri}.
|
|
25
|
+
# @return [URI, nil]
|
|
26
|
+
attr_reader(:jsi_base_uri)
|
|
27
|
+
|
|
28
|
+
# @deprecated after v0.8
|
|
29
|
+
def jsi_schema_base_uri
|
|
30
|
+
jsi_base_uri
|
|
31
|
+
end
|
|
25
32
|
|
|
26
33
|
# resources which are ancestors of this JSI in the document. this does not include self.
|
|
27
34
|
# @api private
|
|
28
35
|
# @return [Array<JSI::Schema>]
|
|
29
36
|
attr_reader :jsi_schema_resource_ancestors
|
|
30
37
|
|
|
31
|
-
#
|
|
32
|
-
# @
|
|
33
|
-
attr_reader(:
|
|
38
|
+
# @return [Schema::DynamicAnchorMap]
|
|
39
|
+
# @api private
|
|
40
|
+
attr_reader(:jsi_schema_dynamic_anchor_map)
|
|
34
41
|
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# or nil if not contained by a resource with a URI.
|
|
39
|
-
# @return [Addressable::URI, nil]
|
|
40
|
-
def jsi_resource_ancestor_uri
|
|
41
|
-
(is_a?(Schema) && schema_absolute_uri) || jsi_schema_base_uri
|
|
42
|
+
# @deprecated after v0.8
|
|
43
|
+
def jsi_schema_registry
|
|
44
|
+
jsi_registry
|
|
42
45
|
end
|
|
43
46
|
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
# See {Base#jsi_resource_root}
|
|
48
|
+
# @return [Schema::SchemaAncestorNode, nil]
|
|
49
|
+
def jsi_resource_root
|
|
50
|
+
# overridden by Base. may be nil from MetaSchemaNode::BootstrapSchema.
|
|
51
|
+
jsi_is_resource_root? ? self : jsi_schema_resource_ancestors.last
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @return [Boolean]
|
|
55
|
+
def jsi_is_resource_root?
|
|
56
|
+
# overridden by Schema
|
|
57
|
+
jsi_ptr.root?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# An absolute URI identifying this node, if this node is a resource root.
|
|
61
|
+
# Typically from a schema's `$id` keyword.
|
|
62
|
+
# @return [URI, nil]
|
|
63
|
+
def jsi_resource_uri
|
|
64
|
+
jsi_resource_uris.first
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Absolute URIs identifying this node - typically one URI if this is a resource root, otherwise none.
|
|
68
|
+
# @return [Enumerable<URI>]
|
|
69
|
+
def jsi_resource_uris
|
|
70
|
+
@resource_uris_map[content: jsi_node_content]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @yield [URI]
|
|
74
|
+
private def jsi_each_resource_uri_compute
|
|
75
|
+
yield jsi_root_uri if jsi_ptr.root? && jsi_root_uri
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# URI for resolution of relative URIs at or below this node - always an absolute URI (with no fragment).
|
|
79
|
+
# Mainly used to resolve relative `$ref`s.
|
|
80
|
+
# This is self's {#jsi_resource_uri} if this node is a resource; otherwise {#jsi_base_uri}.
|
|
81
|
+
# @return [URI, nil]
|
|
82
|
+
def jsi_next_base_uri
|
|
83
|
+
jsi_resource_uri || jsi_base_uri
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# @private
|
|
87
|
+
# @param dynamic_anchor_map [Schema::DynamicAnchorMap]
|
|
88
|
+
# @return [Schema::SchemaAncestorNode]
|
|
89
|
+
def jsi_with_schema_dynamic_anchor_map(dynamic_anchor_map)
|
|
90
|
+
if dynamic_anchor_map == jsi_schema_dynamic_anchor_map
|
|
91
|
+
return self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
if jsi_resource_root
|
|
95
|
+
# it might seem to make more sense to keep dynamic scope from the resource_root, merged with given scope, e.g.:
|
|
96
|
+
#new_dynamic_anchor_map = resource_root.jsi_next_schema_dynamic_anchor_map.merge(dynamic_anchor_map).without_node(resource_root)
|
|
97
|
+
# except the json schema test suite has (optional) tests "$dynamicRef skips over intermediate resources"
|
|
98
|
+
new_dynamic_anchor_map = dynamic_anchor_map.without_node(jsi_resource_root)
|
|
99
|
+
if new_dynamic_anchor_map == jsi_schema_dynamic_anchor_map
|
|
100
|
+
return self
|
|
101
|
+
end
|
|
52
102
|
else
|
|
53
|
-
|
|
103
|
+
new_dynamic_anchor_map = dynamic_anchor_map
|
|
54
104
|
end
|
|
105
|
+
|
|
106
|
+
jsi_dynamic_root_descendent(new_dynamic_anchor_map)
|
|
55
107
|
end
|
|
56
108
|
|
|
57
109
|
# All schemas at or below this node with the given anchor.
|
|
58
110
|
#
|
|
59
111
|
# @return [Set<JSI::Schema>]
|
|
60
112
|
def jsi_anchor_subschemas(anchor)
|
|
61
|
-
@anchor_subschemas_map[anchor: anchor]
|
|
113
|
+
@anchor_subschemas_map[anchor: anchor, content: jsi_node_content]
|
|
62
114
|
end
|
|
63
115
|
|
|
64
116
|
private
|
|
65
117
|
|
|
66
|
-
|
|
67
|
-
@anchor_subschemas_map = jsi_memomap(&method(:jsi_anchor_subschemas_compute))
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
attr_writer :jsi_document
|
|
118
|
+
BY_ANCHOR = proc { |i| i[:anchor] }
|
|
71
119
|
|
|
72
|
-
def
|
|
73
|
-
|
|
74
|
-
@
|
|
120
|
+
def jsi_schema_ancestor_node_initialize
|
|
121
|
+
@resource_uris_map = jsi_memomap(key_by: Schema::KEY_BY_NONE) { Set.new(to_enum(:jsi_each_resource_uri_compute)).freeze }
|
|
122
|
+
@anchor_subschemas_map = jsi_memomap(key_by: BY_ANCHOR, &method(:jsi_anchor_subschemas_compute))
|
|
75
123
|
end
|
|
76
124
|
|
|
77
|
-
def
|
|
78
|
-
#chkbug
|
|
79
|
-
#chkbug
|
|
80
|
-
#chkbug
|
|
125
|
+
def jsi_base_uri=(jsi_base_uri)
|
|
126
|
+
#chkbug fail(Bug) if jsi_base_uri && !jsi_base_uri.is_a?(URI)
|
|
127
|
+
#chkbug fail(Bug) if jsi_base_uri && !jsi_base_uri.absolute?
|
|
128
|
+
#chkbug fail(Bug) if jsi_base_uri && jsi_base_uri.fragment
|
|
81
129
|
|
|
82
|
-
@
|
|
130
|
+
@jsi_base_uri = jsi_base_uri
|
|
83
131
|
end
|
|
84
132
|
|
|
85
133
|
def jsi_schema_resource_ancestors=(jsi_schema_resource_ancestors)
|
|
86
|
-
#chkbug
|
|
134
|
+
#chkbug fail(Bug) unless jsi_schema_resource_ancestors.respond_to?(:to_ary)
|
|
87
135
|
#chkbug jsi_schema_resource_ancestors.each { |a| Schema.ensure_schema(a) }
|
|
88
136
|
#chkbug # sanity check the ancestors are in order
|
|
89
137
|
#chkbug last_anc_ptr = nil
|
|
@@ -91,14 +139,14 @@ module JSI
|
|
|
91
139
|
#chkbug if last_anc_ptr.nil?
|
|
92
140
|
#chkbug # pass
|
|
93
141
|
#chkbug elsif last_anc_ptr == anc.jsi_ptr
|
|
94
|
-
#chkbug
|
|
95
|
-
#chkbug elsif !last_anc_ptr.
|
|
96
|
-
#chkbug
|
|
142
|
+
#chkbug fail(Bug, "duplicate ancestors in #{jsi_schema_resource_ancestors.pretty_inspect}")
|
|
143
|
+
#chkbug elsif !last_anc_ptr.ancestor_of?(anc.jsi_ptr)
|
|
144
|
+
#chkbug fail(Bug, "ancestor ptr #{anc.jsi_ptr} not descendent of previous: #{last_anc_ptr} in #{jsi_schema_resource_ancestors.pretty_inspect}")
|
|
97
145
|
#chkbug end
|
|
98
146
|
#chkbug if anc.jsi_ptr == jsi_ptr
|
|
99
|
-
#chkbug
|
|
100
|
-
#chkbug elsif !anc.jsi_ptr.
|
|
101
|
-
#chkbug
|
|
147
|
+
#chkbug fail(Bug, "ancestor is self")
|
|
148
|
+
#chkbug elsif !anc.jsi_ptr.ancestor_of?(jsi_ptr)
|
|
149
|
+
#chkbug fail(Bug, "ancestor does not contain self")
|
|
102
150
|
#chkbug end
|
|
103
151
|
#chkbug last_anc_ptr = anc.jsi_ptr
|
|
104
152
|
#chkbug end
|
|
@@ -106,17 +154,22 @@ module JSI
|
|
|
106
154
|
@jsi_schema_resource_ancestors = jsi_schema_resource_ancestors
|
|
107
155
|
end
|
|
108
156
|
|
|
109
|
-
|
|
157
|
+
def jsi_schema_dynamic_anchor_map=(dynamic_anchor_map)
|
|
158
|
+
#chkbug fail if !dynamic_anchor_map.is_a?(Schema::DynamicAnchorMap)
|
|
159
|
+
#chkbug fail if !dynamic_anchor_map.frozen?
|
|
160
|
+
#chkbug fail if dynamic_anchor_map != dynamic_anchor_map.without_node(self)
|
|
161
|
+
@jsi_schema_dynamic_anchor_map = dynamic_anchor_map
|
|
162
|
+
end
|
|
110
163
|
|
|
111
|
-
def jsi_anchor_subschemas_compute(anchor: )
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
164
|
+
def jsi_anchor_subschemas_compute(anchor: , content: )
|
|
165
|
+
SchemaSet.new(jsi_each_descendent_schema_same_resource.select do |schema|
|
|
166
|
+
schema.anchors.include?(anchor)
|
|
167
|
+
end)
|
|
115
168
|
end
|
|
116
169
|
|
|
117
170
|
# @return [Util::MemoMap]
|
|
118
171
|
def jsi_memomap(**options, &block)
|
|
119
|
-
|
|
172
|
+
jsi_memomap_class.new(**options, &block)
|
|
120
173
|
end
|
|
121
174
|
end
|
|
122
175
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module JSI
|
|
4
|
+
module Schema
|
|
5
|
+
class Vocabulary
|
|
6
|
+
include(Util::Pretty)
|
|
7
|
+
|
|
8
|
+
# @param id [#to_str, nil]
|
|
9
|
+
# @param elements [Enumerable<Schema::Element>]
|
|
10
|
+
def initialize(id: nil, elements: )
|
|
11
|
+
@id = Util.uri(id, nnil: false, yabs: true, ynorm: true)
|
|
12
|
+
raise(TypeError, "elements: #{elements}") unless elements.all? { |e| e.is_a?(Schema::Element) }
|
|
13
|
+
@elements = Set.new(elements).freeze
|
|
14
|
+
|
|
15
|
+
freeze
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @return [URI, nil]
|
|
19
|
+
attr_reader(:id)
|
|
20
|
+
|
|
21
|
+
# @return [Set<Schema::Element>]
|
|
22
|
+
attr_reader(:elements)
|
|
23
|
+
|
|
24
|
+
# @param q
|
|
25
|
+
def pretty_print(q)
|
|
26
|
+
if id
|
|
27
|
+
jsi_pp_object_group(q, [self.class.name, -"id: <#{id}>"])
|
|
28
|
+
else
|
|
29
|
+
jsi_pp_object_group(q) do
|
|
30
|
+
q.seplist(elements) { |e| q.pp(e) }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|