Skip to content

Commit

Permalink
Merge commit '262f2419b'; commit '35a9a31ed' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Jul 20, 2023
2 parents 262f241 + 35a9a31 commit 86ce5de
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 43 deletions.
3 changes: 2 additions & 1 deletion lib/jsi/base.rb
Expand Up @@ -656,7 +656,8 @@ def jsi_fingerprint
private

def jsi_indicated_schemas=(jsi_indicated_schemas)
@jsi_indicated_schemas = SchemaSet.ensure_schema_set(jsi_indicated_schemas)
#chkbug raise(Bug) unless jsi_indicated_schemas.is_a?(SchemaSet)
@jsi_indicated_schemas = jsi_indicated_schemas
end

def jsi_child_node_map
Expand Down
1 change: 1 addition & 0 deletions lib/jsi/metaschema_node/bootstrap_schema.rb
Expand Up @@ -47,6 +47,7 @@ def initialize(
self.jsi_ptr = jsi_ptr
self.jsi_document = jsi_document
self.jsi_schema_base_uri = jsi_schema_base_uri
self.jsi_schema_resource_ancestors = Util::EMPTY_ARY
end

# document containing the schema content
Expand Down
69 changes: 27 additions & 42 deletions lib/jsi/schema/schema_ancestor_node.rb
Expand Up @@ -26,10 +26,7 @@ def initialize(*, **)
# resources which are ancestors of this JSI in the document. this does not include self.
# @api private
# @return [Array<JSI::Schema>]
def jsi_schema_resource_ancestors
return @jsi_schema_resource_ancestors if instance_variable_defined?(:@jsi_schema_resource_ancestors)
Util::EMPTY_ARY
end
attr_reader :jsi_schema_resource_ancestors

# the URI of the resource containing this node.
# this is always an absolute URI (with no fragment).
Expand Down Expand Up @@ -67,52 +64,40 @@ def jsi_schema_ancestor_node_initialize
attr_writer :jsi_document

def jsi_ptr=(jsi_ptr)
raise(Bug, "jsi_ptr not #{Ptr}: #{jsi_ptr.inspect}") unless jsi_ptr.is_a?(Ptr)
#chkbug raise(Bug, "jsi_ptr not #{Ptr}: #{jsi_ptr}") unless jsi_ptr.is_a?(Ptr)
@jsi_ptr = jsi_ptr
end

def jsi_schema_base_uri=(jsi_schema_base_uri)
if jsi_schema_base_uri
unless jsi_schema_base_uri.respond_to?(:to_str)
raise(TypeError, "jsi_schema_base_uri must be string or Addressable::URI; got: #{jsi_schema_base_uri.inspect}")
end
@jsi_schema_base_uri = Util.uri(jsi_schema_base_uri)
unless @jsi_schema_base_uri.absolute? && !@jsi_schema_base_uri.fragment
raise(ArgumentError, "jsi_schema_base_uri must be an absolute URI with no fragment; got: #{jsi_schema_base_uri.inspect}")
end
else
@jsi_schema_base_uri = nil
end
#chkbug raise(Bug) if jsi_schema_base_uri && !jsi_schema_base_uri.is_a?(Addressable::URI)
#chkbug raise(Bug) if jsi_schema_base_uri && !jsi_schema_base_uri.absolute?
#chkbug raise(Bug) if jsi_schema_base_uri && jsi_schema_base_uri.fragment

@jsi_schema_base_uri = jsi_schema_base_uri
end

def jsi_schema_resource_ancestors=(jsi_schema_resource_ancestors)
if jsi_schema_resource_ancestors
unless jsi_schema_resource_ancestors.respond_to?(:to_ary)
raise(TypeError, "jsi_schema_resource_ancestors must be an array; got: #{jsi_schema_resource_ancestors.inspect}")
end
jsi_schema_resource_ancestors.each { |a| Schema.ensure_schema(a) }
# sanity check the ancestors are in order
last_anc_ptr = nil
jsi_schema_resource_ancestors.each do |anc|
if last_anc_ptr.nil?
# pass
elsif last_anc_ptr == anc.jsi_ptr
raise(Bug, "duplicate ancestors in #{jsi_schema_resource_ancestors.pretty_inspect}")
elsif !last_anc_ptr.contains?(anc.jsi_ptr)
raise(Bug, "ancestor ptr #{anc.jsi_ptr} not contained by previous: #{last_anc_ptr} in #{jsi_schema_resource_ancestors.pretty_inspect}")
end
if anc.jsi_ptr == jsi_ptr
raise(Bug, "ancestor is self")
elsif !anc.jsi_ptr.contains?(jsi_ptr)
raise(Bug, "ancestor does not contain self")
end
last_anc_ptr = anc.jsi_ptr
end
#chkbug raise(Bug) unless jsi_schema_resource_ancestors.respond_to?(:to_ary)
#chkbug jsi_schema_resource_ancestors.each { |a| Schema.ensure_schema(a) }
#chkbug # sanity check the ancestors are in order
#chkbug last_anc_ptr = nil
#chkbug jsi_schema_resource_ancestors.each do |anc|
#chkbug if last_anc_ptr.nil?
#chkbug # pass
#chkbug elsif last_anc_ptr == anc.jsi_ptr
#chkbug raise(Bug, "duplicate ancestors in #{jsi_schema_resource_ancestors.pretty_inspect}")
#chkbug elsif !last_anc_ptr.contains?(anc.jsi_ptr)
#chkbug raise(Bug, "ancestor ptr #{anc.jsi_ptr} not contained by previous: #{last_anc_ptr} in #{jsi_schema_resource_ancestors.pretty_inspect}")
#chkbug end
#chkbug if anc.jsi_ptr == jsi_ptr
#chkbug raise(Bug, "ancestor is self")
#chkbug elsif !anc.jsi_ptr.contains?(jsi_ptr)
#chkbug raise(Bug, "ancestor does not contain self")
#chkbug end
#chkbug last_anc_ptr = anc.jsi_ptr
#chkbug end

@jsi_schema_resource_ancestors = jsi_schema_resource_ancestors.to_ary.freeze
else
@jsi_schema_resource_ancestors = Util::EMPTY_ARY
end
@jsi_schema_resource_ancestors = jsi_schema_resource_ancestors
end

def jsi_anchor_subschemas_map
Expand Down
10 changes: 10 additions & 0 deletions lib/jsi/schema_set.rb
Expand Up @@ -92,6 +92,16 @@ def new_jsi(instance,

applied_schemas = inplace_applicator_schemas(instance)

if uri
unless uri.respond_to?(:to_str)
raise(TypeError, "uri must be string or Addressable::URI; got: #{uri.inspect}")
end
uri = Util.uri(uri)
unless uri.absolute? && !uri.fragment
raise(ArgumentError, "uri must be an absolute URI with no fragment; got: #{uri.inspect}")
end
end

jsi_class = JSI::SchemaClasses.class_for_schemas(applied_schemas,
includes: SchemaClasses.includes_for(instance),
)
Expand Down

0 comments on commit 86ce5de

Please sign in to comment.