lutaml-model 0.8.194 → 0.8.196
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/compat/opal/lutaml_model_boot.rb +1 -0
- data/lib/lutaml/model/serialize/builder.rb +2 -0
- data/lib/lutaml/model/serialize/initialization.rb +20 -1
- data/lib/lutaml/model/serialize/tracking_default_hash.rb +64 -0
- data/lib/lutaml/model/serialize.rb +55 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/adapter_element.rb +5 -1
- data/lib/lutaml/xml/namespace_collector.rb +46 -6
- data/spec/lutaml/model/mutable_default_spec.rb +110 -0
- data/spec/lutaml/xml/adapter_element_verbatim_spec.rb +44 -0
- data/spec/lutaml/xml/plan_mixed_content_nested_namespace_spec.rb +105 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85e0b7e03682f50ff60810fd5635731bdb25ecfaf8459d4aacefe83868add8e8
|
|
4
|
+
data.tar.gz: 618235ad9e8b5fc2ae70e6c3056d04558927de3a86aaa8bb4b129e19e02bc018
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa2a5aac349920a13a01ec25575d98af17cda245c2a9c8ad95c30b4ca6dd6dc5ee19b62c4f6514ec2182a9f6d4c1c4ff97b6bd3f2978b0d5a87277cc7be91811
|
|
7
|
+
data.tar.gz: b172fe00497c499c054b2705a3624b9d2f7d43997e1ee29ff8a87f50615366073ad9878ab289f02eef03bf71cea3bb8850fe11a3938874f1a6609ddeac0e048a
|
|
@@ -413,6 +413,7 @@ require "lutaml/model/serialize/enum_handling"
|
|
|
413
413
|
require "lutaml/model/serialize/format_conversion"
|
|
414
414
|
require "lutaml/model/serialize/initialization"
|
|
415
415
|
require "lutaml/model/serialize/model_import"
|
|
416
|
+
require "lutaml/model/serialize/tracking_default_hash"
|
|
416
417
|
require "lutaml/model/serialize/transformation_builder"
|
|
417
418
|
require "lutaml/model/serialize/value_mapping"
|
|
418
419
|
require "lutaml/model/services/base"
|
|
@@ -123,6 +123,7 @@ module Lutaml
|
|
|
123
123
|
# @return [Object] the passed value
|
|
124
124
|
def record_mutation(attribute_name, value = nil)
|
|
125
125
|
@__mutated_after_parse__ = true
|
|
126
|
+
propagate_default_mutation!
|
|
126
127
|
return value unless @__order_tracking__
|
|
127
128
|
|
|
128
129
|
track_order(attribute_name, value, nil)
|
|
@@ -144,6 +145,7 @@ module Lutaml
|
|
|
144
145
|
# @return [Object] the passed value
|
|
145
146
|
def record_mutation_collection(attribute_name, value)
|
|
146
147
|
@__mutated_after_parse__ = true
|
|
148
|
+
propagate_default_mutation!
|
|
147
149
|
return value unless @__order_tracking__
|
|
148
150
|
return value if value.nil? || Lutaml::Model::Utils.uninitialized?(value)
|
|
149
151
|
|
|
@@ -667,10 +667,29 @@ module Lutaml
|
|
|
667
667
|
value = if Lutaml::Model::Utils.uninitialized?(default)
|
|
668
668
|
nil
|
|
669
669
|
else
|
|
670
|
-
attr.cast_value(default, register_id)
|
|
670
|
+
casted = attr.cast_value(default, register_id)
|
|
671
|
+
case casted
|
|
672
|
+
when Serialize::TrackingDefaultHash
|
|
673
|
+
casted
|
|
674
|
+
when ::Hash
|
|
675
|
+
Serialize::TrackingDefaultHash.for(
|
|
676
|
+
casted, instance, name
|
|
677
|
+
)
|
|
678
|
+
else
|
|
679
|
+
casted
|
|
680
|
+
end
|
|
671
681
|
end
|
|
672
682
|
instance.public_send(writers[name], value)
|
|
673
683
|
instance.using_default_for(name)
|
|
684
|
+
# A mutable default handed to the consumer is mutated
|
|
685
|
+
# through its own object (#1272) - the owner's mark never
|
|
686
|
+
# sees it. Register the wiring so the mutation entry
|
|
687
|
+
# point (record_mutation) can clear the owner's mark;
|
|
688
|
+
# Hash defaults carry the tracking wrapper above.
|
|
689
|
+
if value.is_a?(Serialize)
|
|
690
|
+
value.__lutaml_default_owner__ = instance
|
|
691
|
+
value.__lutaml_default_attribute_name__ = name
|
|
692
|
+
end
|
|
674
693
|
end
|
|
675
694
|
end
|
|
676
695
|
reserved = (attrs.key?(:lutaml_register) ? 1 : 0) +
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Serialize
|
|
6
|
+
# A Hash that surfaces its own in-place mutation to the model
|
|
7
|
+
# whose constructor default it seeds (#1272).
|
|
8
|
+
#
|
|
9
|
+
# A constructor-defaulted Hash attribute is handed out by the
|
|
10
|
+
# reader and mutated through plain Hash faces (`h[k] = v`) -
|
|
11
|
+
# events the owning model can never see, so the attribute stays
|
|
12
|
+
# using-default and is silently dropped at serialization. The
|
|
13
|
+
# constructor seeds this subclass instead; every mutating face
|
|
14
|
+
# clears the owner's mark (the seed itself runs with the owner
|
|
15
|
+
# unwired, so seeding does not flip the mark).
|
|
16
|
+
#
|
|
17
|
+
# merge!/update bypass the overridden []= (C-level Hash loop),
|
|
18
|
+
# so they are overridden explicitly, as is replace.
|
|
19
|
+
class TrackingDefaultHash < ::Hash
|
|
20
|
+
attr_accessor :__lutaml_default_owner__,
|
|
21
|
+
:__lutaml_default_attribute_name__
|
|
22
|
+
|
|
23
|
+
def self.for(seed, owner, attribute_name)
|
|
24
|
+
hash = new
|
|
25
|
+
hash.replace(seed)
|
|
26
|
+
hash.__lutaml_default_owner__ = owner
|
|
27
|
+
hash.__lutaml_default_attribute_name__ = attribute_name
|
|
28
|
+
hash
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def []=(key, value)
|
|
32
|
+
super
|
|
33
|
+
__lutaml_default_owner__&.value_set_for(
|
|
34
|
+
__lutaml_default_attribute_name__,
|
|
35
|
+
)
|
|
36
|
+
__lutaml_default_owner__&.propagate_default_mutation!
|
|
37
|
+
value
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
alias store []=
|
|
41
|
+
|
|
42
|
+
def merge!(other)
|
|
43
|
+
super
|
|
44
|
+
__lutaml_default_owner__&.value_set_for(
|
|
45
|
+
__lutaml_default_attribute_name__,
|
|
46
|
+
)
|
|
47
|
+
__lutaml_default_owner__&.propagate_default_mutation!
|
|
48
|
+
self
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
alias update merge!
|
|
52
|
+
|
|
53
|
+
def replace(other)
|
|
54
|
+
super
|
|
55
|
+
__lutaml_default_owner__&.value_set_for(
|
|
56
|
+
__lutaml_default_attribute_name__,
|
|
57
|
+
)
|
|
58
|
+
__lutaml_default_owner__&.propagate_default_mutation!
|
|
59
|
+
self
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -16,6 +16,7 @@ module Lutaml
|
|
|
16
16
|
autoload :TransformationBuilder,
|
|
17
17
|
"#{__dir__}/serialize/transformation_builder"
|
|
18
18
|
autoload :Builder, "#{__dir__}/serialize/builder"
|
|
19
|
+
autoload :TrackingDefaultHash, "#{__dir__}/serialize/tracking_default_hash"
|
|
19
20
|
|
|
20
21
|
include ComparableModel
|
|
21
22
|
include Validation
|
|
@@ -258,6 +259,35 @@ module Lutaml
|
|
|
258
259
|
@using_default[attribute_name] = true
|
|
259
260
|
end
|
|
260
261
|
|
|
262
|
+
# The constructor-defaulted mutable-object backlink (#1272).
|
|
263
|
+
#
|
|
264
|
+
# When `.new` seeds an attribute with a MUTABLE default (a nested
|
|
265
|
+
# Serialize model or a TrackingDefaultHash), in-place mutation
|
|
266
|
+
# through the reader-returned object fires on THAT object -
|
|
267
|
+
# never on the owner - so the owner's using_default? mark
|
|
268
|
+
# survives and the entire attribute is silently dropped at
|
|
269
|
+
# serialization. The seed stamps the backlink on the default
|
|
270
|
+
# object itself (nil on every untouched instance); the single
|
|
271
|
+
# mutation entry point (record_mutation) walks it up the chain.
|
|
272
|
+
attr_accessor :__lutaml_default_owner__,
|
|
273
|
+
:__lutaml_default_attribute_name__
|
|
274
|
+
|
|
275
|
+
# Walk the backlink chain clear of using-default marks: each hop
|
|
276
|
+
# clears its owner's mark for the attribute the object was
|
|
277
|
+
# seeded under. A seen set guards cycles (default lambdas can
|
|
278
|
+
# reference models that carry the same default).
|
|
279
|
+
def propagate_default_mutation!
|
|
280
|
+
seen = nil
|
|
281
|
+
current = self
|
|
282
|
+
while (owner = current.__lutaml_default_owner__)
|
|
283
|
+
owner.value_set_for(current.__lutaml_default_attribute_name__)
|
|
284
|
+
(seen ||= []) << current
|
|
285
|
+
current = owner
|
|
286
|
+
break if seen.include?(current)
|
|
287
|
+
end
|
|
288
|
+
nil
|
|
289
|
+
end
|
|
290
|
+
|
|
261
291
|
def value_set_for(attribute_name)
|
|
262
292
|
# Only allocate hash when transitioning from "all defaults" (nil)
|
|
263
293
|
# Hash.new(true) ensures unset keys still return true
|
|
@@ -428,11 +458,36 @@ module Lutaml
|
|
|
428
458
|
value = self.class.apply_value_map(value, vmap, attr)
|
|
429
459
|
# Performance: Only call ensure_utf8 for string values
|
|
430
460
|
value = self.class.ensure_utf8(value) if transcode_to_utf8?(value, attr)
|
|
461
|
+
if default
|
|
462
|
+
# A constructor-defaulted mutable object is mutated through
|
|
463
|
+
# its own object (#1272) - the owner's mark never sees it.
|
|
464
|
+
# Hash defaults are seeded as a tracking wrapper whose
|
|
465
|
+
# mutating faces clear the owner's mark; nested Serialize
|
|
466
|
+
# models register at the seed below (their own writers are
|
|
467
|
+
# the mutation entry point). The wrapper is re-pointed after
|
|
468
|
+
# the writer: the compiled writer's cast_value duplicates
|
|
469
|
+
# Hash subclasses back into plain Hashes.
|
|
470
|
+
wrapped = case value
|
|
471
|
+
when Serialize::TrackingDefaultHash then value
|
|
472
|
+
when ::Hash
|
|
473
|
+
Serialize::TrackingDefaultHash.for(value, self, name)
|
|
474
|
+
end
|
|
475
|
+
if wrapped && !wrapped.equal?(value)
|
|
476
|
+
public_send(self.class.instantiate_writers(lutaml_register)[name], value)
|
|
477
|
+
using_default_for(name) if default
|
|
478
|
+
instance_variable_set(:"@#{name}", wrapped)
|
|
479
|
+
return value
|
|
480
|
+
end
|
|
481
|
+
end
|
|
431
482
|
# Interpolating the writer symbol allocated a String per
|
|
432
483
|
# attribute per instance; the per-register writer table is
|
|
433
484
|
# interned once per class.
|
|
434
485
|
public_send(self.class.instantiate_writers(lutaml_register)[name], value)
|
|
435
486
|
using_default_for(name) if default
|
|
487
|
+
if default && value.is_a?(Serialize)
|
|
488
|
+
value.__lutaml_default_owner__ = self
|
|
489
|
+
value.__lutaml_default_attribute_name__ = name
|
|
490
|
+
end
|
|
436
491
|
end
|
|
437
492
|
|
|
438
493
|
# A binary String from a non-text type holds bytes, not text:
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -88,7 +88,11 @@ module Lutaml
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
def to_xml(_builder = nil)
|
|
91
|
-
|
|
91
|
+
# Verbatim raw capture (#223): the markup must come back byte-for-byte,
|
|
92
|
+
# so serialization opts out of the context's default indent — a
|
|
93
|
+
# formatted emission would compound onto the source's own
|
|
94
|
+
# whitespace-only text nodes and corrupt the captured subtree.
|
|
95
|
+
@moxml_node.to_xml(declaration: false, expand_empty: false, indent: 0)
|
|
92
96
|
end
|
|
93
97
|
|
|
94
98
|
def build_xml(builder = nil)
|
|
@@ -252,6 +252,41 @@ module Lutaml
|
|
|
252
252
|
Lutaml::Model::Register.resolve_for_child(mapper_class, @register)
|
|
253
253
|
end
|
|
254
254
|
|
|
255
|
+
# Child-presence signature of an instance: which mapped elements
|
|
256
|
+
# carry values, recursively (depth-capped). Members with equal
|
|
257
|
+
# signatures serialize through identical subtree shapes, so their
|
|
258
|
+
# namespace needs may be merged once (#1268: namespace needs are
|
|
259
|
+
# value-dependent, not class-dependent).
|
|
260
|
+
def presence_signature(item, mapping, depth = 6)
|
|
261
|
+
return :unshaped unless item.is_a?(::Lutaml::Model::Serialize) &&
|
|
262
|
+
mapping.is_a?(Lutaml::Xml::Mapping) && depth.positive?
|
|
263
|
+
|
|
264
|
+
sig = {}
|
|
265
|
+
attributes = item.class.attributes
|
|
266
|
+
mapping.elements.each do |rule|
|
|
267
|
+
next unless attributes.key?(rule.to)
|
|
268
|
+
|
|
269
|
+
value = item.public_send(rule.to)
|
|
270
|
+
value = value.collection if value.is_a?(Lutaml::Model::Collection)
|
|
271
|
+
if value.nil? || (value.is_a?(Array) && value.empty?) ||
|
|
272
|
+
::Lutaml::Model::Utils.uninitialized?(value)
|
|
273
|
+
sig[rule.to] = :absent
|
|
274
|
+
next
|
|
275
|
+
end
|
|
276
|
+
child_type = attributes[rule.to]&.type(effective_register_for(item.class))
|
|
277
|
+
if child_type.is_a?(Class) && child_type < Lutaml::Model::Serialize
|
|
278
|
+
child_mapping = child_type.mappings_for(:xml)
|
|
279
|
+
members = value.is_a?(Array) ? value : [value]
|
|
280
|
+
sig[rule.to] = members.map do |member|
|
|
281
|
+
presence_signature(member, child_mapping, depth - 1)
|
|
282
|
+
end
|
|
283
|
+
else
|
|
284
|
+
sig[rule.to] = :value
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
sig
|
|
288
|
+
end
|
|
289
|
+
|
|
255
290
|
# Internal collection method
|
|
256
291
|
#
|
|
257
292
|
# @param element [Object] the model instance (can be nil for type analysis)
|
|
@@ -437,15 +472,20 @@ module Lutaml
|
|
|
437
472
|
# output. Merge-once is equivalent to merge-N: every read
|
|
438
473
|
# path of the merged needs is any?/set-based.
|
|
439
474
|
merged_needs = NamespaceNeeds.new
|
|
440
|
-
|
|
475
|
+
seen_signatures = nil
|
|
441
476
|
instances.each do |item|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
477
|
+
# Merge-once across structurally identical members only:
|
|
478
|
+
# namespace needs are value-dependent (an optional child
|
|
479
|
+
# model may carry its own namespace in one member and be
|
|
480
|
+
# absent in the next), so the memo key is the member's
|
|
481
|
+
# child-presence signature, not its class (#1268).
|
|
482
|
+
signature = presence_signature(item, child_mapping)
|
|
483
|
+
if seen_signatures
|
|
484
|
+
next if seen_signatures[signature]
|
|
445
485
|
else
|
|
446
|
-
|
|
486
|
+
seen_signatures = {}
|
|
447
487
|
end
|
|
448
|
-
|
|
488
|
+
seen_signatures[signature] = true
|
|
449
489
|
item_ns_prefix = if item.is_a?(::Lutaml::Model::Serialize)
|
|
450
490
|
item.xml_namespace_prefix
|
|
451
491
|
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require_relative "../../../lib/lutaml/model"
|
|
5
|
+
|
|
6
|
+
module MutableDefaultSpec
|
|
7
|
+
class Definition < Lutaml::Model::Serializable
|
|
8
|
+
attribute :terms, :string, collection: true
|
|
9
|
+
|
|
10
|
+
yaml do
|
|
11
|
+
map "terms", to: :terms
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Concept < Lutaml::Model::Serializable
|
|
16
|
+
attribute :id, :string
|
|
17
|
+
attribute :data, Definition, default: -> { Definition.new }
|
|
18
|
+
attribute :meta, :hash, default: -> { {} }
|
|
19
|
+
|
|
20
|
+
yaml do
|
|
21
|
+
map "id", to: :id
|
|
22
|
+
map "data", to: :data
|
|
23
|
+
map "meta", to: :meta
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class LocalizedConcept < Lutaml::Model::Serializable
|
|
28
|
+
attribute :id, :string
|
|
29
|
+
attribute :data, Definition, default: -> { Definition.new }
|
|
30
|
+
|
|
31
|
+
yaml do
|
|
32
|
+
map "id", to: :id
|
|
33
|
+
map "data", to: :data
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The delegating-setter shape from the issue: a custom writer that
|
|
37
|
+
# writes through the default nested object.
|
|
38
|
+
def language_code=(value)
|
|
39
|
+
data.terms = [value]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def language_code
|
|
43
|
+
data.terms&.first
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
RSpec.describe "mutable constructor defaults" do
|
|
49
|
+
describe "nested model default mutated in place" do
|
|
50
|
+
it "serializes the mutation (issue #1272)" do
|
|
51
|
+
concept = MutableDefaultSpec::Concept.new
|
|
52
|
+
concept.data.terms = ["thermal-neutron"]
|
|
53
|
+
|
|
54
|
+
yaml = concept.to_yaml
|
|
55
|
+
|
|
56
|
+
expect(yaml).to include("thermal-neutron")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "still omits an untouched default" do
|
|
60
|
+
concept = MutableDefaultSpec::Concept.new
|
|
61
|
+
|
|
62
|
+
expect(concept.to_yaml).not_to include("data")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "reads the mutation back through the nested reader" do
|
|
66
|
+
concept = MutableDefaultSpec::Concept.new
|
|
67
|
+
concept.data.terms = ["thermal-neutron"]
|
|
68
|
+
|
|
69
|
+
round_tripped = MutableDefaultSpec::Concept.from_yaml(concept.to_yaml)
|
|
70
|
+
|
|
71
|
+
expect(round_tripped.data.terms).to eq(["thermal-neutron"])
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "delegating writer through the default" do
|
|
76
|
+
it "serializes the delegated mutation" do
|
|
77
|
+
concept = MutableDefaultSpec::LocalizedConcept.new
|
|
78
|
+
concept.language_code = "eng"
|
|
79
|
+
|
|
80
|
+
yaml = concept.to_yaml
|
|
81
|
+
|
|
82
|
+
expect(yaml).to include("eng")
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe "hash default mutated in place" do
|
|
87
|
+
it "serializes the mutation" do
|
|
88
|
+
concept = MutableDefaultSpec::Concept.new
|
|
89
|
+
concept.meta[:register] = "main"
|
|
90
|
+
|
|
91
|
+
yaml = concept.to_yaml
|
|
92
|
+
|
|
93
|
+
expect(yaml).to include("register")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe "parsed instances keep the absent-omission semantics (#922)" do
|
|
98
|
+
it "keeps a read-but-unmutated absent attribute omitted" do
|
|
99
|
+
concept = MutableDefaultSpec::Concept.from_yaml("id: c1\n")
|
|
100
|
+
|
|
101
|
+
_ = concept.data # the read materializes the default object
|
|
102
|
+
_ = concept.meta
|
|
103
|
+
|
|
104
|
+
yaml = concept.to_yaml
|
|
105
|
+
|
|
106
|
+
expect(yaml).not_to include("data")
|
|
107
|
+
expect(yaml).not_to include("meta")
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# Raw markup capture through a custom `with:` handler (the lane isodoc's
|
|
6
|
+
# BibdataConfig#bibdata_from_xml rides) must return the source subtree
|
|
7
|
+
# byte-for-byte. moxml's document serializer pretty-prints when the
|
|
8
|
+
# context's default indent applies, which compounds onto the source's own
|
|
9
|
+
# whitespace-only text nodes ("<v>\n <x/>" round-tripping as
|
|
10
|
+
# "<v>\n <x/>"); AdapterElement#to_xml opts out of formatting so the
|
|
11
|
+
# verbatim contract holds.
|
|
12
|
+
RSpec.describe "AdapterElement#to_xml verbatim raw markup" do
|
|
13
|
+
let(:handler_class) do
|
|
14
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
15
|
+
attribute :frag, :string
|
|
16
|
+
|
|
17
|
+
xml do
|
|
18
|
+
element "d"
|
|
19
|
+
map_element "frag", to: :frag,
|
|
20
|
+
with: {
|
|
21
|
+
from: :frag_from_xml, to: :frag_to_xml
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def frag_from_xml(model, node)
|
|
26
|
+
model.frag = node.to_xml
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def frag_to_xml(_model, _parent, _doc); end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "returns the subtree byte-for-byte when the source is single-spaced" do
|
|
34
|
+
source = "<d><frag>\n <x a=\"1\">inner</x>\n</frag></d>"
|
|
35
|
+
expect(handler_class.from_xml(source).frag)
|
|
36
|
+
.to eq("<frag>\n <x a=\"1\">inner</x>\n</frag>")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "does not compound onto pre-existing indentation on nested sources" do
|
|
40
|
+
source = "<d><frag><v>\n <x>inner</x>\n</v></frag></d>"
|
|
41
|
+
expect(handler_class.from_xml(source).frag)
|
|
42
|
+
.to eq("<frag><v>\n <x>inner</x>\n</v></frag>")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "nested model namespace declarations on the plan serialization path" do
|
|
6
|
+
# The metanorma-standoc unitsml shape (lutaml-model#1268): a parent
|
|
7
|
+
# model with mixed content holds two same-class elements - one with
|
|
8
|
+
# text content, one carrying a child model that declares its own
|
|
9
|
+
# namespace. On the leptris plan path the child's namespace
|
|
10
|
+
# declaration was dropped when the text sibling was present.
|
|
11
|
+
let(:inner_namespace) do
|
|
12
|
+
Class.new(Lutaml::Xml::W3c::XmlNamespace) do
|
|
13
|
+
uri "http://example.com/inner"
|
|
14
|
+
prefix_default "inner"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
let(:outer_namespace) do
|
|
19
|
+
Class.new(Lutaml::Xml::W3c::XmlNamespace) do
|
|
20
|
+
uri "http://example.com/outer"
|
|
21
|
+
prefix_default "outer"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
let(:classes) do
|
|
26
|
+
inner = inner_namespace
|
|
27
|
+
outer = outer_namespace
|
|
28
|
+
math_class = Class.new(Lutaml::Model::Serializable) do
|
|
29
|
+
attribute :mi, :string
|
|
30
|
+
|
|
31
|
+
xml do
|
|
32
|
+
namespace inner
|
|
33
|
+
element "math"
|
|
34
|
+
map_element "mi", to: :mi
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
symbol_class = Class.new(Lutaml::Model::Serializable) do
|
|
38
|
+
attribute :text, :string, collection: true
|
|
39
|
+
attribute :math, math_class, collection: true
|
|
40
|
+
|
|
41
|
+
xml do
|
|
42
|
+
namespace outer
|
|
43
|
+
element "symbol"
|
|
44
|
+
mixed_content
|
|
45
|
+
map_content to: :text
|
|
46
|
+
map_element "math", to: :math
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
root_class = Class.new(Lutaml::Model::Serializable) do
|
|
50
|
+
attribute :symbol, symbol_class, collection: true
|
|
51
|
+
|
|
52
|
+
xml do
|
|
53
|
+
namespace outer
|
|
54
|
+
element "root"
|
|
55
|
+
map_element "symbol", to: :symbol
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
[math_class, symbol_class, root_class]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
let(:math_class) { classes[0] }
|
|
62
|
+
let(:symbol_class) { classes[1] }
|
|
63
|
+
let(:root_class) { classes[2] }
|
|
64
|
+
|
|
65
|
+
let(:xml) do
|
|
66
|
+
'<root xmlns="http://example.com/outer">' \
|
|
67
|
+
"<symbol>mm</symbol>" \
|
|
68
|
+
'<symbol><math xmlns="http://example.com/inner">' \
|
|
69
|
+
"<mi>mm</mi></math></symbol>" \
|
|
70
|
+
"</root>"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
around do |example|
|
|
74
|
+
old_fast = Lutaml::Model::Config.instance.xml_plan_fast_path
|
|
75
|
+
old_ordered = Lutaml::Model::Config.instance.xml_plan_ordered_path
|
|
76
|
+
Lutaml::Model::Config.instance.xml_plan_fast_path = true
|
|
77
|
+
Lutaml::Model::Config.instance.xml_plan_ordered_path = true
|
|
78
|
+
example.run
|
|
79
|
+
ensure
|
|
80
|
+
Lutaml::Model::Config.instance.xml_plan_fast_path = old_fast
|
|
81
|
+
Lutaml::Model::Config.instance.xml_plan_ordered_path = old_ordered
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "keeps the nested namespace declaration across the round-trip" do
|
|
85
|
+
Lutaml::Model::Config.with_adapter(xml: :leptris) do
|
|
86
|
+
root = root_class.from_xml(xml)
|
|
87
|
+
out = root.to_xml
|
|
88
|
+
expect(out).to include("http://example.com/inner")
|
|
89
|
+
reparsed = root_class.from_xml(out)
|
|
90
|
+
expect(reparsed.symbol[1].math.first.mi).to eq("mm")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "matches the interpretive serialization on the child namespace" do
|
|
95
|
+
expected = nil
|
|
96
|
+
Lutaml::Model::Config.with_adapter(xml: :nokogiri) do
|
|
97
|
+
expected = root_class.from_xml(xml).to_xml
|
|
98
|
+
end
|
|
99
|
+
Lutaml::Model::Config.with_adapter(xml: :leptris) do
|
|
100
|
+
actual = root_class.from_xml(xml).to_xml
|
|
101
|
+
expect(actual).to include('xmlns="http://example.com/inner"')
|
|
102
|
+
expect(expected).to include('xmlns="http://example.com/inner"')
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
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.196
|
|
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-
|
|
11
|
+
date: 2026-12-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -760,6 +760,7 @@ files:
|
|
|
760
760
|
- lib/lutaml/model/serialize/format_conversion.rb
|
|
761
761
|
- lib/lutaml/model/serialize/initialization.rb
|
|
762
762
|
- lib/lutaml/model/serialize/model_import.rb
|
|
763
|
+
- lib/lutaml/model/serialize/tracking_default_hash.rb
|
|
763
764
|
- lib/lutaml/model/serialize/transformation_builder.rb
|
|
764
765
|
- lib/lutaml/model/serialize/value_mapping.rb
|
|
765
766
|
- lib/lutaml/model/services.rb
|
|
@@ -2124,6 +2125,7 @@ files:
|
|
|
2124
2125
|
- spec/lutaml/model/model_import_reentry_spec.rb
|
|
2125
2126
|
- spec/lutaml/model/model_transformer_spec.rb
|
|
2126
2127
|
- spec/lutaml/model/multiple_mapping_spec.rb
|
|
2128
|
+
- spec/lutaml/model/mutable_default_spec.rb
|
|
2127
2129
|
- spec/lutaml/model/namespace_autoload_spec.rb
|
|
2128
2130
|
- spec/lutaml/model/namespace_versioning_spec.rb
|
|
2129
2131
|
- spec/lutaml/model/one_entry_cache_spec.rb
|
|
@@ -2278,6 +2280,7 @@ files:
|
|
|
2278
2280
|
- spec/lutaml/xml/adapter/ox_adapter_spec.rb
|
|
2279
2281
|
- spec/lutaml/xml/adapter/rexml_adapter_spec.rb
|
|
2280
2282
|
- spec/lutaml/xml/adapter/xml_namespace_spec.rb
|
|
2283
|
+
- spec/lutaml/xml/adapter_element_verbatim_spec.rb
|
|
2281
2284
|
- spec/lutaml/xml/adapter_loader_spec.rb
|
|
2282
2285
|
- spec/lutaml/xml/adapter_metadata_default_spec.rb
|
|
2283
2286
|
- spec/lutaml/xml/adapter_moxml_engine_spec.rb
|
|
@@ -2365,6 +2368,7 @@ files:
|
|
|
2365
2368
|
- spec/lutaml/xml/plain_model_accessors_spec.rb
|
|
2366
2369
|
- spec/lutaml/xml/plain_model_mapping_resolution_spec.rb
|
|
2367
2370
|
- spec/lutaml/xml/plan_fast_path_spec.rb
|
|
2371
|
+
- spec/lutaml/xml/plan_mixed_content_nested_namespace_spec.rb
|
|
2368
2372
|
- spec/lutaml/xml/plan_namespaced_serialize_spec.rb
|
|
2369
2373
|
- spec/lutaml/xml/plan_ns_less_document_spec.rb
|
|
2370
2374
|
- spec/lutaml/xml/plan_partition_spec.rb
|