lutaml-xsd 1.2.92 → 1.2.93

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19a629abe9ac053899019037981e12e3c502bbbd17c0f6456787190dd52b7713
4
- data.tar.gz: a403d2c8184c297216afffa96ff9f236e656f6027d1e8595f9afa794cb5362a6
3
+ metadata.gz: 6ad03adc4f701faa3d3c132f2704c5dc7e01033e7403750352156cbe7a2333a9
4
+ data.tar.gz: b861d33acb72791876fee6e23ba03bc94a662d570b127056803a75de319a2a4a
5
5
  SHA512:
6
- metadata.gz: 76a79f3d5e6ff50291fe0d8e9f29cd53325ae38b7a8eb679ef758829cac8069bb6f3911f4cf2c7739522db3cfe80f6514107c88813316f849ab2cd4e49e5ab74
7
- data.tar.gz: 4f44e60f03e3145daee06ec180e6a4fdbbd0d03618104641c19991989a8d028f23d5a2f4209adbfb05fa80cfb10dc0a6e10450e8debade2208debdb35e93dd49
6
+ metadata.gz: 1d64f1ba11d11333972f2cbdbe32c083d423effecefea95b3aca7b99200c0edc314a0861502129ec0a7f58c77a0e7e34474473f2600fd91e6314d25fb83c2949
7
+ data.tar.gz: 3e1f6cfbda1193da0844c8e25c6579503c1ceab084acb5d00674e1682c344326167ff00e5f07881655c898a21fed46f9c0e316174a63d3f4491341085cf4126a
@@ -604,7 +604,12 @@ module Lutaml
604
604
  return nil unless repository
605
605
 
606
606
  local = particle.ref.to_s.split(":").last
607
- (owner_ns && repository.resolve_global(local, owner_ns)) ||
607
+ exact_ns = repository&.ref_namespace(particle)
608
+ exact_target =
609
+ if exact_ns || owner_ns
610
+ repository.resolve_global(local, exact_ns || owner_ns)
611
+ end
612
+ exact_target ||
608
613
  repository.resolve(local, child.namespace_uri) ||
609
614
  repository.resolve(local, nil)
610
615
  end
@@ -65,6 +65,11 @@ module Lutaml
65
65
  # redefined enumeration). The facet walk never recurses into
66
66
  # named bases, so the body's base reference terminates here.
67
67
  @redefined_simple_bodies = {}
68
+ # Exact namespaces for PREFIXED ref particles, from the
69
+ # owning schema's xmlns declarations (lutaml-model 0.8.167
70
+ # retains them — #1131). The prefix IS the semantics: a ref
71
+ # names the declaration its prefix binds, exactly.
72
+ @ref_namespaces = {}.compare_by_identity
68
73
  @elements = index_elements
69
74
  end
70
75
 
@@ -597,6 +602,96 @@ module Lutaml
597
602
  schema.to_xml]
598
603
  end
599
604
 
605
+ # Exact namespaces for every PREFIXED ref particle in the
606
+ # document, resolved through the document's own xmlns
607
+ # declarations (lutaml-model 0.8.167+ retains them — #1131).
608
+ # The prefix IS the semantics: a ref names the declaration its
609
+ # prefix binds. Documents parsed by older lutaml-models carry
610
+ # no declarations and simply contribute nothing.
611
+ #
612
+ # @return [void]
613
+ def register_ref_namespaces(schema)
614
+ declarations = schema.respond_to?(:xmlns_declarations) &&
615
+ schema.xmlns_declarations
616
+ return unless declarations.is_a?(Hash)
617
+
618
+ descend = lambda do |node, depth|
619
+ return if depth > 10
620
+ return unless node
621
+
622
+ if node.is_a?(Array)
623
+ node.each { |child| descend.call(child, depth) }
624
+ return
625
+ end
626
+
627
+ if node.is_a?(Lutaml::Xml::Schema::Xsd::Element)
628
+ ref = node.ref.to_s
629
+ if ref.include?(":")
630
+ uri = declarations[ref.split(":").first]
631
+ @ref_namespaces[node] = uri if uri
632
+ end
633
+ return
634
+ end
635
+ if node.is_a?(Lutaml::Xml::Schema::Xsd::Group)
636
+ declaration =
637
+ resolve_group((node.ref || node.name).to_s.split(":").last)
638
+ container = declaration &&
639
+ (Array(declaration.sequence).first ||
640
+ Array(declaration.choice).first ||
641
+ Array(declaration.all).first)
642
+ descend.call(container, depth + 1) if container
643
+ return
644
+ end
645
+
646
+ containers = {
647
+ Lutaml::Xml::Schema::Xsd::Schema =>
648
+ %i[element complex_type simple_type attribute
649
+ attribute_group group import include redefine],
650
+ Lutaml::Xml::Schema::Xsd::ComplexType =>
651
+ %i[sequence choice all group complex_content
652
+ simple_content],
653
+ Lutaml::Xml::Schema::Xsd::ExtensionComplexContent =>
654
+ %i[sequence choice all group],
655
+ Lutaml::Xml::Schema::Xsd::RestrictionComplexContent =>
656
+ %i[sequence choice all group],
657
+ Lutaml::Xml::Schema::Xsd::ComplexContent =>
658
+ %i[extension restriction],
659
+ Lutaml::Xml::Schema::Xsd::SimpleContent =>
660
+ %i[extension restriction],
661
+ Lutaml::Xml::Schema::Xsd::Sequence =>
662
+ %i[element any sequence choice group],
663
+ Lutaml::Xsd::Sequence =>
664
+ %i[element any sequence choice group],
665
+ Lutaml::Xml::Schema::Xsd::Choice =>
666
+ %i[element any sequence choice group],
667
+ Lutaml::Xsd::Choice =>
668
+ %i[element any sequence choice group],
669
+ Lutaml::Xml::Schema::Xsd::All => %i[element],
670
+ Lutaml::Xsd::All => %i[element],
671
+ }[node.class]
672
+ return unless containers
673
+
674
+ containers.each do |accessor|
675
+ Array(node.public_send(accessor)).each do |child|
676
+ descend.call(child, depth + 1)
677
+ end
678
+ end
679
+ end
680
+ descend.call(schema, 0)
681
+ end
682
+
683
+ public
684
+
685
+ # The exact namespace a PREFIXED ref particle names, when the
686
+ # owning document's prefix map is retained (0.8.167+); nil
687
+ # otherwise (the owner-namespace heuristic applies).
688
+ #
689
+ # @param particle [Object]
690
+ # @return [String, nil]
691
+ def ref_namespace(particle)
692
+ @ref_namespaces[particle]
693
+ end
694
+
600
695
  def index_schema(index, schema, held_signatures = [],
601
696
  chameleon_namespace = nil,
602
697
  chameleon_includer = nil)
@@ -607,6 +702,7 @@ module Lutaml
607
702
  chameleon = raw_namespace.to_s.empty? && chameleon_namespace
608
703
  namespace = chameleon ? chameleon_namespace : raw_namespace
609
704
  defaults_schema = chameleon ? chameleon_includer : schema
705
+ register_ref_namespaces(schema)
610
706
  Array(schema.element).each do |element|
611
707
  index_element(index, element, namespace, :top, defaults_schema)
612
708
  # A global element's INLINE complexType carries local
@@ -254,9 +254,14 @@ module Lutaml
254
254
  # matches no-namespace declarations, and a hint-loaded
255
255
  # document can supply a foreign namesake. The owner probe
256
256
  # is GLOBAL-only: a ref names a global declaration, and an
257
- # inline namesake must not satisfy it.
257
+ # inline namesake must not satisfy it. A RETAINED prefix
258
+ # map (lutaml-model 0.8.167+, #1131) resolves the ref
259
+ # EXACTLY — the prefix is the semantics.
260
+ exact_ns = repository&.ref_namespace(particle)
258
261
  declaration =
259
- (owner_ns && repository&.resolve_global(local, owner_ns)) ||
262
+ if exact_ns || owner_ns
263
+ repository&.resolve_global(local, exact_ns || owner_ns)
264
+ end ||
260
265
  repository&.resolve(local, child.namespace_uri) ||
261
266
  repository&.resolve(local, nil)
262
267
  # An unresolvable ref (particlesQ032: a no-namespace document
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Xsd
5
- VERSION = "1.2.92"
5
+ VERSION = "1.2.93"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-xsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.92
4
+ version: 1.2.93
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.