lutaml-model 0.8.185 → 0.8.186
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/lib/lutaml/model/schema/xml_compiler/spec_builder/complex_types.rb +3 -2
- data/lib/lutaml/model/schema/xml_compiler/spec_builder.rb +42 -2
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/model_transform.rb +19 -0
- data/lib/lutaml/xml/schema/xsd/complex_type.rb +1 -1
- data/lib/lutaml/xml/schema/xsd/extension_complex_content.rb +1 -1
- data/lib/lutaml/xml/schema/xsd/extension_simple_content.rb +1 -1
- data/lib/lutaml/xml/schema/xsd/restriction_complex_content.rb +1 -1
- data/lib/lutaml/xml/schema/xsd/restriction_simple_content.rb +1 -1
- data/spec/lutaml/xml/adapter_parity_cross_namespace_spec.rb +119 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea63d75c561923cb1286edc3d320fb2e24aa39ed9318a19cabbcf73659f3b9c1
|
|
4
|
+
data.tar.gz: 7dda5b3ee35853aae9dada687a762641bddb5ced2e55dc606c22a8c87b44f451
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78e413d5a78c52d788e6bcea704b4365afb081671bf2886f84deac7b9ff9e44b574ef38256632c894aa4bfb675aadf692f2b260540d3901bc3a868e39a843624
|
|
7
|
+
data.tar.gz: 95f5e0d1466f68e79287c797b0dba6421d045df2806449e179dba73eb6d395c7eb590c031031cc842917f39f74cf80d89adf0871c4554848c680013a4efaee5d
|
|
@@ -25,7 +25,7 @@ module Lutaml
|
|
|
25
25
|
# carry the owning element's name as `root_name` so the
|
|
26
26
|
# generated class serializes the element, not the internal
|
|
27
27
|
# CT_ alias.
|
|
28
|
-
def build(complex_type, root_name: nil)
|
|
28
|
+
def build(complex_type, root_name: nil, schema: nil)
|
|
29
29
|
model = Definitions::Model.new(
|
|
30
30
|
class_name: Utils.camel_case(complex_type.name),
|
|
31
31
|
xml_root: Definitions::XmlRoot.new(
|
|
@@ -33,7 +33,8 @@ module Lutaml
|
|
|
33
33
|
name: root_name || complex_type.name,
|
|
34
34
|
),
|
|
35
35
|
mixed: !!complex_type.mixed,
|
|
36
|
-
namespace_class_name:
|
|
36
|
+
namespace_class_name:
|
|
37
|
+
@parent.namespace_class_name_for(schema),
|
|
37
38
|
)
|
|
38
39
|
|
|
39
40
|
ElementOrder.resolved(complex_type).each do |element|
|
|
@@ -61,6 +61,11 @@ module Lutaml
|
|
|
61
61
|
)
|
|
62
62
|
@namespace_classes[ns.class_name] = ns
|
|
63
63
|
end
|
|
64
|
+
# Per-unit binding (#1212): each schema unit's models bind the
|
|
65
|
+
# unit's own target namespace, so generated children match
|
|
66
|
+
# their declaring schema's elements exactly on every lane.
|
|
67
|
+
@namespace_classes_by_uri = @namespace_classes.values
|
|
68
|
+
.to_h { |ns| [ns.uri, ns.class_name] }
|
|
64
69
|
# Resolve the namespace_class_name once. When the caller
|
|
65
70
|
# passed :namespace, every generated complex type gets this
|
|
66
71
|
# name. Mirrors XmlCompiler::ComplexType#setup_options on main.
|
|
@@ -70,6 +75,40 @@ module Lutaml
|
|
|
70
75
|
end&.class_name
|
|
71
76
|
end
|
|
72
77
|
|
|
78
|
+
# The namespace class for a schema unit's models: the unit's own
|
|
79
|
+
# target namespace when it declares one, else the caller's
|
|
80
|
+
# requested namespace (#1212 per-unit binding). Imported units
|
|
81
|
+
# surface during the walk, after collect_namespaces ran, so the
|
|
82
|
+
# unit's namespace class is created on first encounter and rides
|
|
83
|
+
# the output's namespace entries like the seeded ones.
|
|
84
|
+
def namespace_class_name_for(schema)
|
|
85
|
+
# Per-unit binding rides an explicit namespace request: the
|
|
86
|
+
# caller's option unlocks per-unit resolution for imported
|
|
87
|
+
# units (#1212). Without it, models stay unbound - the
|
|
88
|
+
# legacy bare-emission/parse behavior the compile corpus
|
|
89
|
+
# depends on.
|
|
90
|
+
return @namespace_class_name if @namespace_class_name.nil?
|
|
91
|
+
|
|
92
|
+
uri = schema&.target_namespace
|
|
93
|
+
return @namespace_class_name if uri.nil? || uri.empty?
|
|
94
|
+
|
|
95
|
+
@namespace_classes_by_uri ||= {}
|
|
96
|
+
@namespace_classes_by_uri[uri] ||= begin
|
|
97
|
+
found = @namespace_classes.values.find { |ns| ns.uri == uri }
|
|
98
|
+
if found
|
|
99
|
+
found.class_name
|
|
100
|
+
else
|
|
101
|
+
ns = Definitions::Namespace.new(
|
|
102
|
+
class_name: NamespaceNaming.class_name_for(uri),
|
|
103
|
+
uri: uri,
|
|
104
|
+
prefix_default: NamespaceNaming.prefix_for(uri),
|
|
105
|
+
)
|
|
106
|
+
@namespace_classes[ns.class_name] = ns
|
|
107
|
+
ns.class_name
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
73
112
|
def walk_schemas(schemas)
|
|
74
113
|
return if schemas.empty?
|
|
75
114
|
|
|
@@ -111,10 +150,11 @@ module Lutaml
|
|
|
111
150
|
end
|
|
112
151
|
end
|
|
113
152
|
|
|
114
|
-
def dispatch_complex(item,
|
|
153
|
+
def dispatch_complex(item, schema)
|
|
115
154
|
case item
|
|
116
155
|
when Lutaml::Xml::Schema::Xsd::ComplexType
|
|
117
|
-
@complex_types[item.name] =
|
|
156
|
+
@complex_types[item.name] =
|
|
157
|
+
@complex_types_builder.build(item, schema: schema)
|
|
118
158
|
when Lutaml::Xml::Schema::Xsd::Group
|
|
119
159
|
@group_types[item.name] = @complex_types_builder.build_group(item)
|
|
120
160
|
end
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -337,6 +337,13 @@ module Lutaml
|
|
|
337
337
|
ec.each do |child|
|
|
338
338
|
child_names_set.add(child.namespaced_name)
|
|
339
339
|
child_names_set.add(child.unprefixed_name)
|
|
340
|
+
# URI-qualified spelling: prefix-independent exact matching
|
|
341
|
+
# against the rule's URI-form namespaced name — derived
|
|
342
|
+
# models bind per schema unit while instances spell
|
|
343
|
+
# arbitrary prefixes (#1212).
|
|
344
|
+
if (c_uri = child.namespace_uri)
|
|
345
|
+
child_names_set.add("#{c_uri}:#{child.unprefixed_name}")
|
|
346
|
+
end
|
|
340
347
|
end
|
|
341
348
|
end
|
|
342
349
|
end
|
|
@@ -1285,6 +1292,18 @@ _effective_register)
|
|
|
1285
1292
|
# This handles the case where elements have prefixed names but are in blank namespace
|
|
1286
1293
|
# e.g., <GML:ApplicationSchema xmlns=""> should match the rule expecting GML namespace
|
|
1287
1294
|
child_ns_prefix = child.namespace_prefix
|
|
1295
|
+
# The element declaration lives in the DECLARING model's
|
|
1296
|
+
# namespace (XSD: an element's namespace is its declaring
|
|
1297
|
+
# schema's), even when the rule's spelling follows the
|
|
1298
|
+
# referenced type's namespace unit (b:Limit-type rules spell
|
|
1299
|
+
# the type's target namespace). Accept the parent-bound
|
|
1300
|
+
# spelling by (URI, local) so XmlCompiler-derived children
|
|
1301
|
+
# parse identically on every lane (#1212).
|
|
1302
|
+
if child_uri && child.unprefixed_name == rule_name_str
|
|
1303
|
+
parent_ns_class = session.xml_mapping&.namespace_class
|
|
1304
|
+
parent_uri = parent_ns_class&.uri
|
|
1305
|
+
next true if parent_uri && child_uri == parent_uri
|
|
1306
|
+
end
|
|
1288
1307
|
# Match by prefix AND local name to avoid matching unrelated elements
|
|
1289
1308
|
# with the same namespace prefix (e.g., xsd:attributeGroup should not
|
|
1290
1309
|
# match a rule for xsd:attribute)
|
|
@@ -29,7 +29,7 @@ module Lutaml
|
|
|
29
29
|
attribute :simple_content, :simple_content
|
|
30
30
|
attribute :complex_content, :complex_content
|
|
31
31
|
attribute :assert, :assert, collection: true,
|
|
32
|
-
|
|
32
|
+
initialize_empty: true
|
|
33
33
|
attribute :open_content, :open_content
|
|
34
34
|
attribute :attribute, :attribute, collection: true,
|
|
35
35
|
initialize_empty: true
|
|
@@ -13,7 +13,7 @@ module Lutaml
|
|
|
13
13
|
attribute :sequence, :sequence
|
|
14
14
|
attribute :annotation, :annotation
|
|
15
15
|
attribute :assert, :assert, collection: true,
|
|
16
|
-
|
|
16
|
+
initialize_empty: true
|
|
17
17
|
attribute :any_attribute, :any_attribute
|
|
18
18
|
attribute :attribute, :attribute, collection: true,
|
|
19
19
|
initialize_empty: true
|
|
@@ -9,7 +9,7 @@ module Lutaml
|
|
|
9
9
|
attribute :base, :string
|
|
10
10
|
attribute :annotation, :annotation
|
|
11
11
|
attribute :assert, :assert, collection: true,
|
|
12
|
-
|
|
12
|
+
initialize_empty: true
|
|
13
13
|
attribute :any_attribute, :any_attribute
|
|
14
14
|
attribute :attribute, :attribute, collection: true,
|
|
15
15
|
initialize_empty: true
|
|
@@ -13,7 +13,7 @@ module Lutaml
|
|
|
13
13
|
attribute :sequence, :sequence
|
|
14
14
|
attribute :annotation, :annotation
|
|
15
15
|
attribute :assert, :assert, collection: true,
|
|
16
|
-
|
|
16
|
+
initialize_empty: true
|
|
17
17
|
attribute :any_attribute, :any_attribute
|
|
18
18
|
attribute :attribute, :attribute, collection: true,
|
|
19
19
|
initialize_empty: true
|
|
@@ -9,7 +9,7 @@ module Lutaml
|
|
|
9
9
|
attribute :base, :string
|
|
10
10
|
attribute :annotation, :annotation
|
|
11
11
|
attribute :assert, :assert, collection: true,
|
|
12
|
-
|
|
12
|
+
initialize_empty: true
|
|
13
13
|
attribute :simple_type, :simple_type
|
|
14
14
|
attribute :any_attribute, :any_attribute
|
|
15
15
|
attribute :length, :length, collection: true, initialize_empty: true
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "open3"
|
|
5
|
+
require "rbconfig"
|
|
6
|
+
require "tmpdir"
|
|
7
|
+
|
|
8
|
+
# XmlCompiler-derived models bind one schema namespace at the model
|
|
9
|
+
# level while children legally live in the imported schemas'
|
|
10
|
+
# namespaces. Every adapter must bind such cross-namespace children
|
|
11
|
+
# identically (#1212).
|
|
12
|
+
ADAPTERS = %w[default nokogiri].freeze
|
|
13
|
+
|
|
14
|
+
RSpec.describe "adapter parity for cross-namespace child binding (#1212)" do
|
|
15
|
+
let(:base_xsd) do
|
|
16
|
+
<<~XSD
|
|
17
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
18
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
19
|
+
targetNamespace="http://example.com/p1212-base"
|
|
20
|
+
elementFormDefault="qualified">
|
|
21
|
+
<xs:complexType name="Upper">
|
|
22
|
+
<xs:simpleContent>
|
|
23
|
+
<xs:extension base="xs:string"/>
|
|
24
|
+
</xs:simpleContent>
|
|
25
|
+
</xs:complexType>
|
|
26
|
+
<xs:complexType name="Limit">
|
|
27
|
+
<xs:sequence>
|
|
28
|
+
<xs:element name="lower" type="xs:string"/>
|
|
29
|
+
<xs:element name="upper" type="Upper"/>
|
|
30
|
+
</xs:sequence>
|
|
31
|
+
</xs:complexType>
|
|
32
|
+
</xs:schema>
|
|
33
|
+
XSD
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
let(:main_xsd) do
|
|
37
|
+
<<~XSD
|
|
38
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
39
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
40
|
+
xmlns:b="http://example.com/p1212-base"
|
|
41
|
+
targetNamespace="http://example.com/p1212-main"
|
|
42
|
+
elementFormDefault="qualified">
|
|
43
|
+
<xs:import namespace="http://example.com/p1212-base"
|
|
44
|
+
schemaLocation="base.xsd"/>
|
|
45
|
+
<xs:complexType name="Holder">
|
|
46
|
+
<xs:sequence>
|
|
47
|
+
<xs:element name="limit" type="b:Limit"/>
|
|
48
|
+
</xs:sequence>
|
|
49
|
+
</xs:complexType>
|
|
50
|
+
<xs:element name="root">
|
|
51
|
+
<xs:complexType>
|
|
52
|
+
<xs:sequence>
|
|
53
|
+
<xs:element name="holder" type="Holder"/>
|
|
54
|
+
</xs:sequence>
|
|
55
|
+
</xs:complexType>
|
|
56
|
+
</xs:element>
|
|
57
|
+
</xs:schema>
|
|
58
|
+
XSD
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
let(:instance_xml) do
|
|
62
|
+
<<~XML
|
|
63
|
+
<m:root xmlns:m="http://example.com/p1212-main"
|
|
64
|
+
xmlns:b="http://example.com/p1212-base">
|
|
65
|
+
<m:holder>
|
|
66
|
+
<m:limit>
|
|
67
|
+
<b:lower>0</b:lower>
|
|
68
|
+
<b:upper>5</b:upper>
|
|
69
|
+
</m:limit>
|
|
70
|
+
</m:holder>
|
|
71
|
+
</m:root>
|
|
72
|
+
XML
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
ADAPTERS.each do |adapter|
|
|
76
|
+
it "binds imported-schema children on the #{adapter} lane" do
|
|
77
|
+
Dir.mktmpdir do |dir|
|
|
78
|
+
File.write(File.join(dir, "base.xsd"), base_xsd)
|
|
79
|
+
File.write(File.join(dir, "main.xsd"), main_xsd)
|
|
80
|
+
File.write(File.join(dir, "instance.xml"), instance_xml)
|
|
81
|
+
|
|
82
|
+
configure = if adapter == "default"
|
|
83
|
+
""
|
|
84
|
+
else
|
|
85
|
+
"Lutaml::Model::Config.configure do |c|\n " \
|
|
86
|
+
"c.xml_adapter_type = :#{adapter}\n" \
|
|
87
|
+
"end\n"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
probe = <<~RUBY
|
|
91
|
+
require "lutaml/model"
|
|
92
|
+
#{configure}
|
|
93
|
+
Lutaml::Model::Schema.from_xml(
|
|
94
|
+
File.read("#{dir}/main.xsd"),
|
|
95
|
+
output_dir: "#{dir}/p1212_models",
|
|
96
|
+
load_classes: true,
|
|
97
|
+
namespace: "http://example.com/p1212-main",
|
|
98
|
+
module_namespace: "P1212Models",
|
|
99
|
+
register_id: "p1212_reg",
|
|
100
|
+
location: "#{dir}/main.xsd",
|
|
101
|
+
)
|
|
102
|
+
parsed = Object.const_get("P1212Models::CTRoot").from_xml(
|
|
103
|
+
File.read("#{dir}/instance.xml"),
|
|
104
|
+
)
|
|
105
|
+
limit = parsed.holder.limit
|
|
106
|
+
puts "lower=\#{limit.lower.inspect}"
|
|
107
|
+
puts "upper=\#{limit.upper&.content.inspect}"
|
|
108
|
+
RUBY
|
|
109
|
+
|
|
110
|
+
_stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-I", "lib",
|
|
111
|
+
"-e", probe)
|
|
112
|
+
expect(status).to be_success, stderr
|
|
113
|
+
|
|
114
|
+
expect(_stdout).to include('lower="0"')
|
|
115
|
+
expect(_stdout).to include('upper="5"')
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.186
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -2009,6 +2009,7 @@ files:
|
|
|
2009
2009
|
- spec/lutaml/xml/adapter/xml_namespace_spec.rb
|
|
2010
2010
|
- spec/lutaml/xml/adapter_loader_spec.rb
|
|
2011
2011
|
- spec/lutaml/xml/adapter_metadata_default_spec.rb
|
|
2012
|
+
- spec/lutaml/xml/adapter_parity_cross_namespace_spec.rb
|
|
2012
2013
|
- spec/lutaml/xml/attribute_ambiguity_surface_spec.rb
|
|
2013
2014
|
- spec/lutaml/xml/attribute_element_namespace_disjoint_spec.rb
|
|
2014
2015
|
- spec/lutaml/xml/attribute_namespace_disjointness_spec.rb
|