lutaml-model 0.8.204 → 0.8.206
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/docs/_guides/native-engines.adoc +16 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +22 -8
- data/lib/lutaml/model/serialize/initialization.rb +2 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/leptris/native_emission.rb +106 -10
- data/lib/lutaml/xml/leptris/plan_compiler.rb +249 -60
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +256 -68
- data/lib/lutaml/xml/leptris/plan_serializer.rb +592 -112
- data/lib/lutaml/xml/leptris/plan_walk.rb +1 -0
- data/lib/lutaml/xml/schema/builder/moxml.rb +7 -3
- data/lib/lutaml/xml/transformation/order_reconciler.rb +4 -0
- data/lib/lutaml/xml/transformation/ordered_applier.rb +8 -7
- data/spec/lutaml/model/cli_spec.rb +16 -7
- data/spec/lutaml/model/group_spec.rb +7 -2
- data/spec/lutaml/model/value_map_spec.rb +16 -15
- data/spec/lutaml/xml/production_lane_parity_spec.rb +901 -0
- metadata +3 -2
|
@@ -20,6 +20,7 @@ module Lutaml
|
|
|
20
20
|
document = ::Leptris::XML.parse(xml)
|
|
21
21
|
root = document.root
|
|
22
22
|
return nil unless root && root.name == plan[:tree][:name]
|
|
23
|
+
return nil if PlanHydrator.xsi_nil_below_root?(root)
|
|
23
24
|
|
|
24
25
|
PlanHydrator.call(model_class, plan,
|
|
25
26
|
plan[:descriptor].walk(root),
|
|
@@ -30,7 +30,11 @@ module Lutaml
|
|
|
30
30
|
yield(@builder) if block
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
# Generate the schema XML string
|
|
33
|
+
# Generate the schema XML string in the Nokogiri wrapper's byte
|
|
34
|
+
# shape: leptris indents only when indent_text rides along with
|
|
35
|
+
# indent, and the moxml backends expand empty elements (<x></x>)
|
|
36
|
+
# unless told otherwise. Generated schemas are artifacts consumers
|
|
37
|
+
# diff and commit, so the spelling must not follow the engine.
|
|
34
38
|
# @param options [Hash] formatting options
|
|
35
39
|
# @option options [Boolean] :pretty Pretty print with indentation
|
|
36
40
|
# @option options [Integer] :indent Number of spaces (default: 2)
|
|
@@ -39,9 +43,9 @@ module Lutaml
|
|
|
39
43
|
doc = @builder.document
|
|
40
44
|
if options[:pretty]
|
|
41
45
|
indent = options[:indent] || 2
|
|
42
|
-
doc.to_xml(indent: indent)
|
|
46
|
+
doc.to_xml(indent: indent, indent_text: " ", expand_empty: false)
|
|
43
47
|
else
|
|
44
|
-
doc.to_xml
|
|
48
|
+
doc.to_xml(expand_empty: false)
|
|
45
49
|
end
|
|
46
50
|
end
|
|
47
51
|
end
|
|
@@ -173,6 +173,10 @@ module Lutaml
|
|
|
173
173
|
collection_element_count(value, rule)
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
+
# Public: the plan lanes' coverage pre-check measures a parsed
|
|
177
|
+
# order against the same count before deciding to reconcile.
|
|
178
|
+
public :expected_element_count
|
|
179
|
+
|
|
176
180
|
def collection_element_count(value, rule)
|
|
177
181
|
# Mirror the applier's own dispatch. A value it will not iterate
|
|
178
182
|
# — nil, or a String — never reaches process_collection_item; it
|
|
@@ -188,13 +188,12 @@ model_class, register_id)
|
|
|
188
188
|
end
|
|
189
189
|
end
|
|
190
190
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
#
|
|
194
|
-
#
|
|
195
|
-
#
|
|
196
|
-
#
|
|
197
|
-
# emitted, and must be skipped rather than crash serialization.
|
|
191
|
+
# Whether an element_order entry is something the ordered path
|
|
192
|
+
# can interpret. element_order is a plain public accessor, so
|
|
193
|
+
# arrays holding foreign objects (Integers, strings, ...) exist
|
|
194
|
+
# in the wild. Anything without #type cannot be matched to a
|
|
195
|
+
# rule or emitted, and must be skipped rather than crash
|
|
196
|
+
# serialization. Shared with the plan lanes' order walks.
|
|
198
197
|
#
|
|
199
198
|
# @param object [Object] An entry from element_order
|
|
200
199
|
# @return [Boolean] true when the entry is a usable order entry
|
|
@@ -202,6 +201,8 @@ model_class, register_id)
|
|
|
202
201
|
object.respond_to?(:type)
|
|
203
202
|
end
|
|
204
203
|
|
|
204
|
+
private
|
|
205
|
+
|
|
205
206
|
# Match by name AND namespace when object has a namespace URI.
|
|
206
207
|
# Falls back to name-only match for backward compatibility.
|
|
207
208
|
# Also checks uri_aliases for namespace alias support (e.g., ReqIF versions).
|
|
@@ -334,15 +334,24 @@ RSpec.describe Lutaml::Model::Cli do
|
|
|
334
334
|
|
|
335
335
|
after { FileUtils.rm_rf(temp_dir) }
|
|
336
336
|
|
|
337
|
-
it "handles malformed XML
|
|
337
|
+
it "handles malformed XML according to the engine's parse contract" do
|
|
338
338
|
cli.options = options
|
|
339
339
|
|
|
340
|
-
# The
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
340
|
+
# The leptris plan lane parses strictly (malformed XML raises on
|
|
341
|
+
# every lane, 17a4658d): the CLI reports the parse failure. A
|
|
342
|
+
# recovering engine (Nokogiri) hands it a best-effort tree and
|
|
343
|
+
# the comparison runs on that.
|
|
344
|
+
if Lutaml::Xml.moxml_engine == :leptris
|
|
345
|
+
expect do
|
|
346
|
+
cli.compare(malformed_xml, files[:target_xml_path])
|
|
347
|
+
end.to raise_error(StandardError, /Error parsing file .*malformed\.xml/)
|
|
348
|
+
else
|
|
349
|
+
expect do
|
|
350
|
+
cli.compare(malformed_xml, files[:target_xml_path])
|
|
351
|
+
end.to output(
|
|
352
|
+
a_string_including("Differences between", "Similarity score:"),
|
|
353
|
+
).to_stdout
|
|
354
|
+
end
|
|
346
355
|
end
|
|
347
356
|
|
|
348
357
|
it "raises error when parsing malformed YAML" do
|
|
@@ -266,9 +266,14 @@ RSpec.describe "Group" do
|
|
|
266
266
|
let(:mapper) { GroupSpec::CeramicCollection }
|
|
267
267
|
|
|
268
268
|
it "raises error if type-only class used directly for parsing" do
|
|
269
|
+
# A well-formed document: the model's own error must be the one
|
|
270
|
+
# raised, not an engine's verdict on the input (a strict lane
|
|
271
|
+
# rejects a two-root fragment before the model is consulted).
|
|
269
272
|
xml = <<~XML
|
|
270
|
-
<
|
|
271
|
-
|
|
273
|
+
<ceramic>
|
|
274
|
+
<type>Data</type>
|
|
275
|
+
<name>Smith</name>
|
|
276
|
+
</ceramic>
|
|
272
277
|
XML
|
|
273
278
|
|
|
274
279
|
expect { GroupSpec::Ceramic.from_xml(xml) }.to raise_error(
|
|
@@ -218,22 +218,23 @@ RSpec.describe "ValueMap" do
|
|
|
218
218
|
|
|
219
219
|
let(:parsed) { ValueMapSpec::WithValueMaps.from_xml(xml) }
|
|
220
220
|
|
|
221
|
-
let(:expected) do
|
|
222
|
-
ValueMapSpec::WithValueMaps.new(
|
|
223
|
-
{
|
|
224
|
-
nil_as_nil: nil,
|
|
225
|
-
nil_as_empty: "",
|
|
226
|
-
empty_as_empty: "",
|
|
227
|
-
empty_as_nil: nil,
|
|
228
|
-
omitted_as_nil: nil,
|
|
229
|
-
omitted_as_empty: "",
|
|
230
|
-
},
|
|
231
|
-
{ omitted: :omitted },
|
|
232
|
-
)
|
|
233
|
-
end
|
|
234
|
-
|
|
235
221
|
it "sets correct values when deserializing" do
|
|
236
|
-
|
|
222
|
+
# The bound attributes carry their value_map's binding.
|
|
223
|
+
expect(parsed.nil_as_nil).to be_nil
|
|
224
|
+
expect(parsed.nil_as_empty).to eq("")
|
|
225
|
+
expect(parsed.empty_as_empty).to eq("")
|
|
226
|
+
expect(parsed.empty_as_nil).to be_nil
|
|
227
|
+
expect(parsed.omitted_as_nil).to be_nil
|
|
228
|
+
expect(parsed.omitted_as_empty).to eq("")
|
|
229
|
+
|
|
230
|
+
# :omitted binds no value — whether the element was absent,
|
|
231
|
+
# nil-marked, or empty. (How an unbound attribute is held is the
|
|
232
|
+
# constructor's business: the deserialization seed keeps the
|
|
233
|
+
# uninitialized sentinel, the plan lane's seed a nil.)
|
|
234
|
+
unbound = ->(value) { value.nil? || Lutaml::Model::Utils.uninitialized?(value) }
|
|
235
|
+
%i[omitted_as_omitted nil_as_omitted empty_as_omitted].each do |name|
|
|
236
|
+
expect(unbound.call(parsed.public_send(name))).to be(true), "#{name} should bind no value"
|
|
237
|
+
end
|
|
237
238
|
end
|
|
238
239
|
end
|
|
239
240
|
end
|