lutaml-model 0.8.146 → 0.8.148
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/serialize/initialization.rb +6 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +53 -21
- data/lib/lutaml/xml/schema/xsd/schema.rb +3 -1
- data/spec/lutaml/model/xml_constructor_defaults_spec.rb +63 -0
- data/spec/lutaml/xml/leptris/plan_hydrator_ns_snapshot_spec.rb +61 -0
- data/spec/lutaml/xml/schema/xsd/import_without_namespace_spec.rb +61 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a830ec6a143525a0d59b70b642ffa232553eb7aadb9d1b6a7cd740a1cfcad6cb
|
|
4
|
+
data.tar.gz: 565167c64a78c785ff6f6742bce3ee5c56083022bd9c37746af983cace306262
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e26f1bec70e96e4311140e345cd7cb15e048b71fe37df05d96bbe8cf319b959bba4e6a6073ac61767e4a6c8a94c7a3e14c5decab75412718bb73cf7d7fee6e1a
|
|
7
|
+
data.tar.gz: a2c55f36c898966db5499b0485702a50749bef098ff3f07e8e4ee90caab1d2c112294adc59da7a6dac486d256679f4f27a426b8384e35932a3228998b27e21f5
|
|
@@ -560,8 +560,14 @@ module Lutaml
|
|
|
560
560
|
# constructor contract — internal state the compiled seeding
|
|
561
561
|
# cannot know about — so they construct through the real
|
|
562
562
|
# constructor, then carry the parse's register context.
|
|
563
|
+
# Attribute state then goes back to the deserialization
|
|
564
|
+
# markers: the parse reads them to tell an absent element from
|
|
565
|
+
# a value a writer assigned (#922), so constructor-seeded
|
|
566
|
+
# defaults would otherwise count as set and a render_default:
|
|
567
|
+
# false element would be written back out.
|
|
563
568
|
if constructs_through_initialize?
|
|
564
569
|
instance = new(lutaml_register: register_id)
|
|
570
|
+
instance.init_deserialization_state(register_id)
|
|
565
571
|
return instance
|
|
566
572
|
end
|
|
567
573
|
instance = allocate
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -94,6 +94,50 @@ module Lutaml
|
|
|
94
94
|
instance
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
+
# leptris#1874: snapshot rows -> the ns_data hash
|
|
98
|
+
# ({path => {prefix_key => {uri:, prefix:, format:}}}), the
|
|
99
|
+
# exact shape the recursion builds. Public: it is the
|
|
100
|
+
# contract the binding's snapshot rows must satisfy.
|
|
101
|
+
def ns_data_from_snapshot_rows(rows)
|
|
102
|
+
rows.each_with_object({}) do |row, result|
|
|
103
|
+
prefix = row[:prefix]
|
|
104
|
+
# One element carrying several declarations emits one
|
|
105
|
+
# row PER declaration with the same path — merge them,
|
|
106
|
+
# exactly as the recursion accumulates per path.
|
|
107
|
+
(result[row[:path]] ||= {})[row[:prefix] || :default] = {
|
|
108
|
+
uri: row[:href], prefix: prefix,
|
|
109
|
+
format: prefix ? :prefix : :default
|
|
110
|
+
}
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def collect_native_namespaces(element, path = [], result = {})
|
|
115
|
+
if element.respond_to?(:namespace_declarations_snapshot)
|
|
116
|
+
return ns_data_from_snapshot_rows(
|
|
117
|
+
element.namespace_declarations_snapshot,
|
|
118
|
+
)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
own = element.namespace_definitions
|
|
122
|
+
unless own.empty?
|
|
123
|
+
namespaces = {}
|
|
124
|
+
own.each do |ns|
|
|
125
|
+
key = ns.prefix || :default
|
|
126
|
+
namespaces[key] = { uri: ns.href, prefix: ns.prefix,
|
|
127
|
+
format: ns.prefix ? :prefix : :default }
|
|
128
|
+
end
|
|
129
|
+
result[path.dup] = namespaces
|
|
130
|
+
end
|
|
131
|
+
element.children.each do |child|
|
|
132
|
+
next unless child.is_a?(::Leptris::XML::Element)
|
|
133
|
+
|
|
134
|
+
path.push(child.name)
|
|
135
|
+
collect_native_namespaces(child, path, result)
|
|
136
|
+
path.pop
|
|
137
|
+
end
|
|
138
|
+
result
|
|
139
|
+
end
|
|
140
|
+
|
|
97
141
|
private
|
|
98
142
|
|
|
99
143
|
def record_declaration_plan(instance, node, model_class)
|
|
@@ -123,27 +167,15 @@ module Lutaml
|
|
|
123
167
|
# Iterates children with an inline element filter:
|
|
124
168
|
# element_children materializes a filtered array per node,
|
|
125
169
|
# which the niso allocation gate caught at scale.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
result[path.dup] = namespaces
|
|
136
|
-
end
|
|
137
|
-
element.children.each do |child|
|
|
138
|
-
next unless child.is_a?(::Leptris::XML::Element)
|
|
139
|
-
|
|
140
|
-
path.push(child.name)
|
|
141
|
-
collect_native_namespaces(child, path, result)
|
|
142
|
-
path.pop
|
|
143
|
-
end
|
|
144
|
-
result
|
|
145
|
-
end
|
|
146
|
-
|
|
170
|
+
#
|
|
171
|
+
# leptris#1874: when the binding exposes the bulk snapshot
|
|
172
|
+
# face (namespace_declarations_snapshot — one FFI crossing
|
|
173
|
+
# for the whole subtree; shipped engine-side in 1.9.387),
|
|
174
|
+
# the whole-subtree Ruby recursion collapses into a single
|
|
175
|
+
# call. Rows: {path: [names...], prefix: String|nil,
|
|
176
|
+
# href: String} in pre-order, paths relative to the
|
|
177
|
+
# receiver. The face probe keeps older bindings on the
|
|
178
|
+
# recursion unchanged.
|
|
147
179
|
def register
|
|
148
180
|
Lutaml::Model::Config.default_register
|
|
149
181
|
end
|
|
@@ -86,7 +86,9 @@ module Lutaml
|
|
|
86
86
|
"import",
|
|
87
87
|
model,
|
|
88
88
|
schema,
|
|
89
|
-
|
|
89
|
+
# An xs:import without a namespace attribute is legal
|
|
90
|
+
# (XSD 1.0 §3.13.2); the raw read stays nil-safe (#1051).
|
|
91
|
+
namespace: schema.attributes["namespace"]&.value,
|
|
90
92
|
)
|
|
91
93
|
end
|
|
92
94
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# from_xml builds a custom-initialize class through its constructor so the
|
|
6
|
+
# class's own internal state exists. Its attributes must still come out of
|
|
7
|
+
# the parse exactly as they do for the same class on the standard
|
|
8
|
+
# initializer: constructor-seeded defaults are not values the document
|
|
9
|
+
# set, so an absent render_default: false element stays absent.
|
|
10
|
+
RSpec.describe "XML deserialization of a custom-initialize class" do
|
|
11
|
+
let(:standard) do
|
|
12
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
13
|
+
attribute :name, :string
|
|
14
|
+
attribute :bidi, :boolean, default: -> { false }
|
|
15
|
+
|
|
16
|
+
xml do
|
|
17
|
+
element "para"
|
|
18
|
+
map_element "name", to: :name
|
|
19
|
+
map_element "bidi", to: :bidi
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
let(:custom) do
|
|
25
|
+
Class.new(standard) do
|
|
26
|
+
def initialize(*args, **kwargs)
|
|
27
|
+
@internal = :ready
|
|
28
|
+
super
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
attr_reader :internal
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
before do
|
|
36
|
+
stub_const("XmlConstructorDefaultsStandard", standard)
|
|
37
|
+
stub_const("XmlConstructorDefaultsCustom", custom)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "runs the class's own initialize" do
|
|
41
|
+
expect(custom.from_xml("<para><name>a</name></para>").internal).to eq(:ready)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "keeps an absent defaulted element absent on round trip" do
|
|
45
|
+
xml = custom.from_xml("<para><name>a</name></para>").to_xml
|
|
46
|
+
|
|
47
|
+
expect(xml).not_to include("bidi")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
[
|
|
51
|
+
"<para><name>a</name></para>",
|
|
52
|
+
"<para><name>a</name><bidi>true</bidi></para>",
|
|
53
|
+
"<para><name>a</name><bidi>false</bidi></para>",
|
|
54
|
+
].each do |input|
|
|
55
|
+
it "parses #{input} the same as the standard initializer" do
|
|
56
|
+
expected = standard.from_xml(input)
|
|
57
|
+
actual = custom.from_xml(input)
|
|
58
|
+
|
|
59
|
+
expect([actual.bidi, actual.to_xml])
|
|
60
|
+
.to eq([expected.bidi, expected.to_xml])
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require_relative "../../../../lib/lutaml/model"
|
|
3
|
+
|
|
4
|
+
# leptris#1874: the plan hydrator's namespace collection collapses the
|
|
5
|
+
# whole-subtree Ruby recursion (one namespace_definitions FFI crossing
|
|
6
|
+
# per node) into the engine's bulk snapshot face when the binding
|
|
7
|
+
# exposes it. These specs pin the ROW CONTRACT the binding must
|
|
8
|
+
# satisfy and the dispatch, so the binding PR can be verified without
|
|
9
|
+
# waiting for the native pin bump.
|
|
10
|
+
# A real lightweight struct standing in for the future binding
|
|
11
|
+
# element: responds to the bulk face with fixed rows, carries no
|
|
12
|
+
# behavior of its own.
|
|
13
|
+
SnapshotFaceElement = Struct.new(:rows) do
|
|
14
|
+
def namespace_declarations_snapshot
|
|
15
|
+
rows
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
RSpec.describe Lutaml::Xml::Leptris::PlanHydrator do
|
|
20
|
+
describe ".ns_data_from_snapshot_rows" do
|
|
21
|
+
it "builds the ns_data hash from pre-order snapshot rows" do
|
|
22
|
+
rows = [
|
|
23
|
+
{ path: [], prefix: nil, href: "urn:d" },
|
|
24
|
+
{ path: [], prefix: "a", href: "urn:a" },
|
|
25
|
+
{ path: ["c1"], prefix: "b", href: "urn:b" },
|
|
26
|
+
{ path: ["c2"], prefix: nil, href: "urn:d2" },
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
result = described_class.ns_data_from_snapshot_rows(rows)
|
|
30
|
+
|
|
31
|
+
expect(result).to eq(
|
|
32
|
+
[] => { default: { uri: "urn:d", prefix: nil,
|
|
33
|
+
format: :default },
|
|
34
|
+
"a" => { uri: "urn:a", prefix: "a", format: :prefix } },
|
|
35
|
+
["c1"] => { "b" => { uri: "urn:b", prefix: "b",
|
|
36
|
+
format: :prefix } },
|
|
37
|
+
["c2"] => { default: { uri: "urn:d2", prefix: nil,
|
|
38
|
+
format: :default } },
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "returns an empty hash for a declaration-free subtree" do
|
|
43
|
+
expect(described_class.ns_data_from_snapshot_rows([])).to eq({})
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "the snapshot face probe in collect_native_namespaces" do
|
|
48
|
+
it "prefers the bulk face when the binding exposes it" do
|
|
49
|
+
element = SnapshotFaceElement.new(
|
|
50
|
+
[{ path: ["x"], prefix: "p", href: "urn:p" }],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
result = described_class.collect_native_namespaces(element)
|
|
54
|
+
|
|
55
|
+
expect(result).to eq(
|
|
56
|
+
["x"] => { "p" => { uri: "urn:p", prefix: "p",
|
|
57
|
+
format: :prefix } },
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "tmpdir"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require_relative "../../../../spec_helper"
|
|
6
|
+
require "lutaml/xml/schema/xsd"
|
|
7
|
+
|
|
8
|
+
# #1051: an xs:import without a namespace attribute is legal
|
|
9
|
+
# (XSD 1.0 §3.13.2 — it imports a schema document with no target
|
|
10
|
+
# namespace). The schema walk read the attribute store unguarded, so
|
|
11
|
+
# a follow-up schema document carrying such an import crashed the
|
|
12
|
+
# parse with "undefined method 'value' for nil".
|
|
13
|
+
RSpec.describe "Xsd import without a namespace attribute" do
|
|
14
|
+
let(:dir) { Dir.mktmpdir }
|
|
15
|
+
|
|
16
|
+
before do
|
|
17
|
+
File.write(File.join(dir, "a.xsd"), <<~XSD)
|
|
18
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
19
|
+
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="b.xsd"/>
|
|
20
|
+
<xs:element name="root"/>
|
|
21
|
+
</xs:schema>
|
|
22
|
+
XSD
|
|
23
|
+
File.write(File.join(dir, "b.xsd"), <<~XSD)
|
|
24
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
25
|
+
<xs:import schemaLocation="c.xsd"/>
|
|
26
|
+
<xs:attribute name="lang" type="xs:language"/>
|
|
27
|
+
</xs:schema>
|
|
28
|
+
XSD
|
|
29
|
+
File.write(File.join(dir, "c.xsd"), <<~XSD)
|
|
30
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
31
|
+
<xs:element name="helper"/>
|
|
32
|
+
</xs:schema>
|
|
33
|
+
XSD
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
after { FileUtils.remove_entry(dir) }
|
|
37
|
+
|
|
38
|
+
it "parses the whole chain" do
|
|
39
|
+
parsed = Lutaml::Xml::Schema::Xsd.parse(
|
|
40
|
+
File.read(File.join(dir, "a.xsd")),
|
|
41
|
+
location: dir,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
expect(parsed).to be_a(Lutaml::Xml::Schema::Xsd::Schema)
|
|
45
|
+
expect(parsed.imports.first.schema_path).to eq("b.xsd")
|
|
46
|
+
expect(parsed.import.first).to be_a(Lutaml::Xml::Schema::Xsd::Schema)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "keeps the namespace-less import unnamed" do
|
|
50
|
+
parsed = Lutaml::Xml::Schema::Xsd.parse(
|
|
51
|
+
<<~XSD,
|
|
52
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
53
|
+
<xs:import schemaLocation="c.xsd"/>
|
|
54
|
+
</xs:schema>
|
|
55
|
+
XSD
|
|
56
|
+
location: dir,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
expect(parsed.imports.first.namespace).to be_nil
|
|
60
|
+
end
|
|
61
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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.148
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -1918,6 +1918,7 @@ files:
|
|
|
1918
1918
|
- spec/lutaml/model/walk_constructor_spec.rb
|
|
1919
1919
|
- spec/lutaml/model/with_child_mapping_spec.rb
|
|
1920
1920
|
- spec/lutaml/model/writer_assigned_attribute_spec.rb
|
|
1921
|
+
- spec/lutaml/model/xml_constructor_defaults_spec.rb
|
|
1921
1922
|
- spec/lutaml/model/xml_decoupling_spec.rb
|
|
1922
1923
|
- spec/lutaml/model/xsd_form_default_patterns_spec.rb
|
|
1923
1924
|
- spec/lutaml/model/xsd_patterns_spec.rb
|
|
@@ -1990,6 +1991,7 @@ files:
|
|
|
1990
1991
|
- spec/lutaml/xml/general_namespace_spec.rb
|
|
1991
1992
|
- spec/lutaml/xml/html_entities_spec.rb
|
|
1992
1993
|
- spec/lutaml/xml/indent_spec.rb
|
|
1994
|
+
- spec/lutaml/xml/leptris/plan_hydrator_ns_snapshot_spec.rb
|
|
1993
1995
|
- spec/lutaml/xml/leptris_string_encoding_spec.rb
|
|
1994
1996
|
- spec/lutaml/xml/line_ending_spec.rb
|
|
1995
1997
|
- spec/lutaml/xml/mapping_finalization_guard_spec.rb
|
|
@@ -2054,6 +2056,7 @@ files:
|
|
|
2054
2056
|
- spec/lutaml/xml/schema/xsd/errors/suggestion_spec.rb
|
|
2055
2057
|
- spec/lutaml/xml/schema/xsd/file_validation_result_spec.rb
|
|
2056
2058
|
- spec/lutaml/xml/schema/xsd/glob_spec.rb
|
|
2059
|
+
- spec/lutaml/xml/schema/xsd/import_without_namespace_spec.rb
|
|
2057
2060
|
- spec/lutaml/xml/schema/xsd/keyref_refer_spec.rb
|
|
2058
2061
|
- spec/lutaml/xml/schema/xsd/liquid_methods/attribute_and_group_spec.rb
|
|
2059
2062
|
- spec/lutaml/xml/schema/xsd/liquid_methods/complex_type_spec.rb
|