lutaml-model 0.8.194 → 0.8.195

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: d098251c4a1cee01a85101b7d12be79aea4d0bc550384134f635a44775544a09
4
- data.tar.gz: 8a658f405ed484b917c058dd09ca80f4c3ea216dc93d9b30dd07b5b5fa7a58b2
3
+ metadata.gz: 3ad5a94aa9e61c22558746e7a29d19c9dc4ae4670359ea46c3a58e8cee1513dc
4
+ data.tar.gz: bb5db6b8392998ea97777d865e1e4b3a034db6faa2f7e62362e75f3d2994cedf
5
5
  SHA512:
6
- metadata.gz: '09978922557b9c1963aff3d1449dda08f9984ccba340b021242d1169b052948bb44ecf5a2db9205b878543da2fa1c1cce7e1496cc134576e10bd399782cb1e7a'
7
- data.tar.gz: b245236ae74bcbf24859dd44ee64d649086ad9d83cef356e2361b9761c3b3bcb9b5af0b1fa6b058005fcb33f3e2ef69159035984c168f6eab71ab101e1f961ff
6
+ metadata.gz: 5cb95be5f9492d733a6b5d40d1c6c7d38e9ad1e3f418d88916a8816f20d93597214caa5cf2ac017f3e47cbab9d6fd65bb486cf109bbdd782802555fc2fc5f7a2
7
+ data.tar.gz: 7414355c20764590c18b6e8c0289bc70d5d2e6144b6b6b3b9fb1f5dde405704123bd7247315a656f926c66e92ba45e814b606fb3b521f44ac6c092f43d9d6d7c
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.194"
5
+ VERSION = "0.8.195"
6
6
  end
7
7
  end
@@ -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
- seen_classes = nil
475
+ seen_signatures = nil
441
476
  instances.each do |item|
442
- item_class = item.class
443
- if seen_classes
444
- next if seen_classes[item_class]
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
- seen_classes = {}
486
+ seen_signatures = {}
447
487
  end
448
- seen_classes[item_class] = true
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,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.194
4
+ version: 0.8.195
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-29 00:00:00.000000000 Z
11
+ date: 2026-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -2365,6 +2365,7 @@ files:
2365
2365
  - spec/lutaml/xml/plain_model_accessors_spec.rb
2366
2366
  - spec/lutaml/xml/plain_model_mapping_resolution_spec.rb
2367
2367
  - spec/lutaml/xml/plan_fast_path_spec.rb
2368
+ - spec/lutaml/xml/plan_mixed_content_nested_namespace_spec.rb
2368
2369
  - spec/lutaml/xml/plan_namespaced_serialize_spec.rb
2369
2370
  - spec/lutaml/xml/plan_ns_less_document_spec.rb
2370
2371
  - spec/lutaml/xml/plan_partition_spec.rb