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.
Files changed (148) 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 → Glossary.md} +84 -52
  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 +592 -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 +244 -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/lib/jsi/metaschema.rb +0 -6
  105. data/lib/jsi/schema/application/child_application/contains.rb +0 -25
  106. data/lib/jsi/schema/application/child_application/draft04.rb +0 -21
  107. data/lib/jsi/schema/application/child_application/draft06.rb +0 -28
  108. data/lib/jsi/schema/application/child_application/draft07.rb +0 -28
  109. data/lib/jsi/schema/application/child_application/items.rb +0 -18
  110. data/lib/jsi/schema/application/child_application/properties.rb +0 -25
  111. data/lib/jsi/schema/application/child_application.rb +0 -13
  112. data/lib/jsi/schema/application/draft04.rb +0 -8
  113. data/lib/jsi/schema/application/draft06.rb +0 -8
  114. data/lib/jsi/schema/application/draft07.rb +0 -8
  115. data/lib/jsi/schema/application/inplace_application/dependencies.rb +0 -28
  116. data/lib/jsi/schema/application/inplace_application/draft04.rb +0 -25
  117. data/lib/jsi/schema/application/inplace_application/draft06.rb +0 -26
  118. data/lib/jsi/schema/application/inplace_application/draft07.rb +0 -32
  119. data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +0 -20
  120. data/lib/jsi/schema/application/inplace_application/ref.rb +0 -18
  121. data/lib/jsi/schema/application/inplace_application/someof.rb +0 -44
  122. data/lib/jsi/schema/application/inplace_application.rb +0 -14
  123. data/lib/jsi/schema/application.rb +0 -12
  124. data/lib/jsi/schema/ref.rb +0 -183
  125. data/lib/jsi/schema/validation/array.rb +0 -69
  126. data/lib/jsi/schema/validation/contains.rb +0 -25
  127. data/lib/jsi/schema/validation/dependencies.rb +0 -49
  128. data/lib/jsi/schema/validation/draft04/minmax.rb +0 -91
  129. data/lib/jsi/schema/validation/draft04.rb +0 -110
  130. data/lib/jsi/schema/validation/draft06.rb +0 -120
  131. data/lib/jsi/schema/validation/draft07.rb +0 -157
  132. data/lib/jsi/schema/validation/enum.rb +0 -25
  133. data/lib/jsi/schema/validation/ifthenelse.rb +0 -46
  134. data/lib/jsi/schema/validation/items.rb +0 -54
  135. data/lib/jsi/schema/validation/not.rb +0 -20
  136. data/lib/jsi/schema/validation/numeric.rb +0 -121
  137. data/lib/jsi/schema/validation/object.rb +0 -45
  138. data/lib/jsi/schema/validation/pattern.rb +0 -34
  139. data/lib/jsi/schema/validation/properties.rb +0 -101
  140. data/lib/jsi/schema/validation/property_names.rb +0 -32
  141. data/lib/jsi/schema/validation/ref.rb +0 -40
  142. data/lib/jsi/schema/validation/required.rb +0 -27
  143. data/lib/jsi/schema/validation/someof.rb +0 -90
  144. data/lib/jsi/schema/validation/string.rb +0 -47
  145. data/lib/jsi/schema/validation/type.rb +0 -49
  146. data/lib/jsi/schema/validation.rb +0 -49
  147. data/lib/jsi/schema_registry.rb +0 -190
  148. 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
@@ -2,12 +2,12 @@
2
2
 
3
3
  module JSI
4
4
  module Schema
5
- Issue = Util::AttrStruct[*%w(
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
- # the base URI used to resolve the ids of schemas at or below this JSI.
20
- # this is always an absolute URI (with no fragment).
21
- # this may be the absolute schema URI of a parent schema or the URI from which the document was retrieved.
22
- # @api private
23
- # @return [Addressable::URI, nil]
24
- attr_reader :jsi_schema_base_uri
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
- # See {SchemaSet#new_jsi} param `schema_registry`
32
- # @return [SchemaRegistry]
33
- attr_reader(:jsi_schema_registry)
38
+ # @return [Schema::DynamicAnchorMap]
39
+ # @api private
40
+ attr_reader(:jsi_schema_dynamic_anchor_map)
34
41
 
35
- # the URI of the resource containing this node.
36
- # this is always an absolute URI (with no fragment).
37
- # if this node is a schema with an id, this is its absolute URI; otherwise a parent resource's URI,
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
- # The schema at or below this node with the given anchor.
45
- # If no schema has that anchor (or multiple schemas do, incorrectly), nil.
46
- #
47
- # @return [JSI::Schema, nil]
48
- def jsi_anchor_subschema(anchor)
49
- subschemas = @anchor_subschemas_map[anchor: anchor]
50
- if subschemas.size == 1
51
- subschemas.first
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
- nil
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
- def jsi_schema_ancestor_node_initialize
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 jsi_ptr=(jsi_ptr)
73
- #chkbug raise(Bug, "jsi_ptr not #{Ptr}: #{jsi_ptr}") unless jsi_ptr.is_a?(Ptr)
74
- @jsi_ptr = jsi_ptr
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 jsi_schema_base_uri=(jsi_schema_base_uri)
78
- #chkbug raise(Bug) if jsi_schema_base_uri && !jsi_schema_base_uri.is_a?(Addressable::URI)
79
- #chkbug raise(Bug) if jsi_schema_base_uri && !jsi_schema_base_uri.absolute?
80
- #chkbug raise(Bug) if jsi_schema_base_uri && jsi_schema_base_uri.fragment
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
- @jsi_schema_base_uri = jsi_schema_base_uri
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 raise(Bug) unless jsi_schema_resource_ancestors.respond_to?(:to_ary)
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 raise(Bug, "duplicate ancestors in #{jsi_schema_resource_ancestors.pretty_inspect}")
95
- #chkbug elsif !last_anc_ptr.contains?(anc.jsi_ptr)
96
- #chkbug raise(Bug, "ancestor ptr #{anc.jsi_ptr} not contained by previous: #{last_anc_ptr} in #{jsi_schema_resource_ancestors.pretty_inspect}")
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 raise(Bug, "ancestor is self")
100
- #chkbug elsif !anc.jsi_ptr.contains?(jsi_ptr)
101
- #chkbug raise(Bug, "ancestor does not contain self")
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
- attr_writer(:jsi_schema_registry)
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
- jsi_each_descendent_node.select do |node|
113
- node.is_a?(Schema) && node.respond_to?(:anchor) && node.anchor == anchor
114
- end.to_set.freeze
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
- Util::MemoMap::Mutable.new(**options, &block)
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