lutaml-model 0.8.193 → 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 +4 -4
- data/lib/lutaml/json/type/serializers.rb +6 -4
- data/lib/lutaml/model/type/date.rb +17 -13
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/toml/type/serializers.rb +3 -2
- data/lib/lutaml/xml/namespace_collector.rb +46 -6
- data/lib/lutaml/xml/type/serializers.rb +6 -4
- data/spec/lutaml/model/type/date_spec.rb +40 -12
- data/spec/lutaml/model/type/subclass_serialize_override_spec.rb +86 -0
- data/spec/lutaml/xml/plan_mixed_content_nested_namespace_spec.rb +105 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ad5a94aa9e61c22558746e7a29d19c9dc4ae4670359ea46c3a58e8cee1513dc
|
|
4
|
+
data.tar.gz: bb5db6b8392998ea97777d865e1e4b3a034db6faa2f7e62362e75f3d2994cedf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5cb95be5f9492d733a6b5d40d1c6c7d38e9ad1e3f418d88916a8816f20d93597214caa5cf2ac017f3e47cbab9d6fd65bb486cf109bbdd782802555fc2fc5f7a2
|
|
7
|
+
data.tar.gz: 7414355c20764590c18b6e8c0289bc70d5d2e6144b6b6b3b9fb1f5dde405704123bd7247315a656f926c66e92ba45e814b606fb3b521f44ac6c092f43d9d6d7c
|
|
@@ -41,16 +41,18 @@ module Lutaml
|
|
|
41
41
|
}
|
|
42
42
|
)
|
|
43
43
|
|
|
44
|
-
# Date — ISO8601 with optional timezone
|
|
44
|
+
# Date — ISO8601 with optional timezone; delegates to the
|
|
45
|
+
# resolved type class (subclass serialize overrides fire)
|
|
45
46
|
v.register_format_type_serializer(
|
|
46
47
|
:json, Lutaml::Model::Type::Date,
|
|
47
|
-
to: ->(inst) {
|
|
48
|
+
to: ->(inst) { inst.class.serialize(inst.value) }
|
|
48
49
|
)
|
|
49
50
|
|
|
50
|
-
# TimeWithoutDate — HH:MM:SS format
|
|
51
|
+
# TimeWithoutDate — HH:MM:SS format; delegates to the
|
|
52
|
+
# resolved type class
|
|
51
53
|
v.register_format_type_serializer(
|
|
52
54
|
:json, Lutaml::Model::Type::TimeWithoutDate,
|
|
53
|
-
to: ->(inst) {
|
|
55
|
+
to: ->(inst) { inst.class.serialize(inst.value) }
|
|
54
56
|
)
|
|
55
57
|
|
|
56
58
|
# Symbol — :symbol: format
|
|
@@ -15,9 +15,10 @@ module Lutaml
|
|
|
15
15
|
|
|
16
16
|
case value
|
|
17
17
|
when ::DateTime
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
# Precision is the value: keep the time-of-day verbatim.
|
|
19
|
+
# Truncating here (or in serialize below) silently drops
|
|
20
|
+
# time components the consumer round-trips (issue #1256).
|
|
21
|
+
value
|
|
21
22
|
when ::Time
|
|
22
23
|
value.to_date
|
|
23
24
|
when ::Date
|
|
@@ -26,9 +27,15 @@ module Lutaml
|
|
|
26
27
|
str = value.to_s
|
|
27
28
|
tz_match = str.match(TIMEZONE_RE)
|
|
28
29
|
if tz_match
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
if str.sub(TIMEZONE_RE, "").include?(":")
|
|
31
|
+
# Time-of-day present: DateTime.parse keeps both the
|
|
32
|
+
# time and the zone (a bare date+zone loses the zone).
|
|
33
|
+
::DateTime.parse(str)
|
|
34
|
+
else
|
|
35
|
+
date = ::Date.parse(str.sub(TIMEZONE_RE, ""))
|
|
36
|
+
offset = parse_timezone(tz_match[1])
|
|
37
|
+
::DateTime.new(date.year, date.month, date.mday, 0, 0, 0, offset)
|
|
38
|
+
end
|
|
32
39
|
else
|
|
33
40
|
::Date.parse(str)
|
|
34
41
|
end
|
|
@@ -37,16 +44,13 @@ module Lutaml
|
|
|
37
44
|
nil
|
|
38
45
|
end
|
|
39
46
|
|
|
40
|
-
# xs:date
|
|
47
|
+
# xs:date for date-only values; the full ISO 8601 dateTime form
|
|
48
|
+
# when the value is a ::DateTime — cast and serialize agree, so
|
|
49
|
+
# a time carried into the type survives the round-trip.
|
|
41
50
|
def self.serialize(value)
|
|
42
51
|
return nil if value.nil?
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
when ::DateTime
|
|
46
|
-
value.strftime("%Y-%m-%d%:z")
|
|
47
|
-
else
|
|
48
|
-
value.iso8601
|
|
49
|
-
end
|
|
53
|
+
value.is_a?(::DateTime) ? DateTime.format_datetime_iso8601(value) : value.iso8601
|
|
50
54
|
end
|
|
51
55
|
|
|
52
56
|
# Default XSD type for Date
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -40,10 +40,11 @@ module Lutaml
|
|
|
40
40
|
}
|
|
41
41
|
)
|
|
42
42
|
|
|
43
|
-
# Date — ISO8601 with optional timezone
|
|
43
|
+
# Date — ISO8601 with optional timezone; delegates to the
|
|
44
|
+
# resolved type class (subclass serialize overrides fire)
|
|
44
45
|
v.register_format_type_serializer(
|
|
45
46
|
:toml, Lutaml::Model::Type::Date,
|
|
46
|
-
to: ->(inst) {
|
|
47
|
+
to: ->(inst) { inst.class.serialize(inst.value) }
|
|
47
48
|
)
|
|
48
49
|
|
|
49
50
|
# TimeWithoutDate — HH:MM:SS.mmm with milliseconds
|
|
@@ -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
|
|
@@ -62,22 +62,24 @@ module Lutaml
|
|
|
62
62
|
}
|
|
63
63
|
)
|
|
64
64
|
|
|
65
|
-
# Date — ISO8601 with Z for UTC
|
|
65
|
+
# Date — ISO8601 with Z for UTC. Delegates to the resolved
|
|
66
|
+
# type class so a subclass's own self.serialize override
|
|
67
|
+
# reaches to_xml (issue #1263).
|
|
66
68
|
v.register_format_type_serializer(
|
|
67
69
|
:xml, Lutaml::Model::Type::Date,
|
|
68
70
|
to: lambda { |inst|
|
|
69
71
|
return nil unless inst.value
|
|
70
72
|
|
|
71
|
-
result =
|
|
73
|
+
result = inst.class.serialize(inst.value)
|
|
72
74
|
result = result.sub(/\+00:00$/, "Z") if result.include?("+00:00")
|
|
73
75
|
result
|
|
74
76
|
}
|
|
75
77
|
)
|
|
76
78
|
|
|
77
|
-
# TimeWithoutDate — delegates to
|
|
79
|
+
# TimeWithoutDate — delegates to the resolved type class
|
|
78
80
|
v.register_format_type_serializer(
|
|
79
81
|
:xml, Lutaml::Model::Type::TimeWithoutDate,
|
|
80
|
-
to: ->(inst) {
|
|
82
|
+
to: ->(inst) { inst.class.serialize(inst.value) }
|
|
81
83
|
)
|
|
82
84
|
|
|
83
85
|
# Symbol — :symbol: format
|
|
@@ -25,7 +25,10 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
25
25
|
context "with DateTime object" do
|
|
26
26
|
let(:value) { DateTime.new(2024, 1, 1, 12, 0, 0) }
|
|
27
27
|
|
|
28
|
-
it
|
|
28
|
+
it "keeps the DateTime verbatim (precision preserved)" do
|
|
29
|
+
expect(cast).to eq(value)
|
|
30
|
+
expect(cast.hour).to eq(12)
|
|
31
|
+
end
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
context "with Time object" do
|
|
@@ -58,9 +61,10 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
58
61
|
end
|
|
59
62
|
|
|
60
63
|
it "parses RFC 3339" do
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
result = described_class.cast("2024-01-01T12:00:00Z")
|
|
65
|
+
expect(result).to be_a(DateTime)
|
|
66
|
+
expect(result.hour).to eq(12)
|
|
67
|
+
expect(result.offset).to eq(Rational(0))
|
|
64
68
|
end
|
|
65
69
|
|
|
66
70
|
it "parses common formats" do
|
|
@@ -155,7 +159,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
155
159
|
let(:value) { DateTime.new(2019, 9, 28, 0, 0, 0, Rational(0)) }
|
|
156
160
|
|
|
157
161
|
it "serializes with +00:00 offset" do
|
|
158
|
-
expect(serialize).to eq("2019-09-
|
|
162
|
+
expect(serialize).to eq("2019-09-28T00:00:00+00:00")
|
|
159
163
|
end
|
|
160
164
|
end
|
|
161
165
|
|
|
@@ -163,7 +167,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
163
167
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(8, 24)) }
|
|
164
168
|
|
|
165
169
|
it "serializes with offset" do
|
|
166
|
-
expect(serialize).to eq("2019-12-
|
|
170
|
+
expect(serialize).to eq("2019-12-02T00:00:00+08:00")
|
|
167
171
|
end
|
|
168
172
|
end
|
|
169
173
|
|
|
@@ -171,7 +175,23 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
171
175
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(-5, 24)) }
|
|
172
176
|
|
|
173
177
|
it "serializes with offset" do
|
|
174
|
-
expect(serialize).to eq("2019-12-
|
|
178
|
+
expect(serialize).to eq("2019-12-02T00:00:00-05:00")
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
context "with time-of-day (issue #1256)" do
|
|
183
|
+
let(:value) { DateTime.parse("2018-04-15T10:30:00Z") }
|
|
184
|
+
|
|
185
|
+
it "serializes as ISO 8601 dateTime, keeping the time" do
|
|
186
|
+
expect(serialize).to eq("2018-04-15T10:30:00+00:00")
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
context "with fractional seconds" do
|
|
191
|
+
let(:value) { DateTime.parse("2018-04-15T10:30:00.123Z") }
|
|
192
|
+
|
|
193
|
+
it "keeps fractional precision" do
|
|
194
|
+
expect(serialize).to eq("2018-04-15T10:30:00.123+00:00")
|
|
175
195
|
end
|
|
176
196
|
end
|
|
177
197
|
|
|
@@ -191,7 +211,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
191
211
|
let(:value) { DateTime.new(2019, 9, 28, 0, 0, 0, Rational(0)) }
|
|
192
212
|
|
|
193
213
|
it "uses Z notation for UTC" do
|
|
194
|
-
expect(xml_value).to eq("2019-09-
|
|
214
|
+
expect(xml_value).to eq("2019-09-28T00:00:00Z")
|
|
195
215
|
end
|
|
196
216
|
end
|
|
197
217
|
|
|
@@ -199,7 +219,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
199
219
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(8, 24)) }
|
|
200
220
|
|
|
201
221
|
it "uses offset notation" do
|
|
202
|
-
expect(xml_value).to eq("2019-12-
|
|
222
|
+
expect(xml_value).to eq("2019-12-02T00:00:00+08:00")
|
|
203
223
|
end
|
|
204
224
|
end
|
|
205
225
|
|
|
@@ -207,7 +227,15 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
207
227
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(-5, 24)) }
|
|
208
228
|
|
|
209
229
|
it "uses offset notation" do
|
|
210
|
-
expect(xml_value).to eq("2019-12-
|
|
230
|
+
expect(xml_value).to eq("2019-12-02T00:00:00-05:00")
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
context "with time-of-day (issue #1256)" do
|
|
235
|
+
let(:value) { DateTime.parse("2010-10-10T12:21:00Z") }
|
|
236
|
+
|
|
237
|
+
it "round-trips the full instant" do
|
|
238
|
+
expect(xml_value).to eq("2010-10-10T12:21:00Z")
|
|
211
239
|
end
|
|
212
240
|
end
|
|
213
241
|
|
|
@@ -227,7 +255,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
227
255
|
let(:value) { DateTime.new(2019, 9, 28, 0, 0, 0, Rational(0)) }
|
|
228
256
|
|
|
229
257
|
it "uses +00:00 notation for UTC" do
|
|
230
|
-
expect(json_value).to eq("2019-09-
|
|
258
|
+
expect(json_value).to eq("2019-09-28T00:00:00+00:00")
|
|
231
259
|
end
|
|
232
260
|
end
|
|
233
261
|
|
|
@@ -235,7 +263,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
235
263
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(8, 24)) }
|
|
236
264
|
|
|
237
265
|
it "uses offset notation" do
|
|
238
|
-
expect(json_value).to eq("2019-12-
|
|
266
|
+
expect(json_value).to eq("2019-12-02T00:00:00+08:00")
|
|
239
267
|
end
|
|
240
268
|
end
|
|
241
269
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe "Type subclass serialize override" do
|
|
4
|
+
# The documented override pattern: subclass a builtin type and
|
|
5
|
+
# redefine self.serialize. The format-serializer table must resolve
|
|
6
|
+
# to the SUBCLASS's own serialize, not the base class's registered
|
|
7
|
+
# static (issue #1263).
|
|
8
|
+
let(:plain_date) do
|
|
9
|
+
Class.new(Lutaml::Model::Type::Date) do
|
|
10
|
+
def self.cast(value, *)
|
|
11
|
+
value.is_a?(String) ? DateTime.parse(value) : value
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.serialize(value, *)
|
|
15
|
+
return value.strftime("%FT%TZ") if value.is_a?(DateTime)
|
|
16
|
+
|
|
17
|
+
value.iso8601
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
let(:model_class) do
|
|
23
|
+
type = plain_date
|
|
24
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
25
|
+
attribute :begins, type
|
|
26
|
+
|
|
27
|
+
xml do
|
|
28
|
+
root "validity"
|
|
29
|
+
map_element "begins", to: :begins
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
json do
|
|
33
|
+
map "begins", to: :begins
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "xml serialization" do
|
|
39
|
+
it "uses the subclass's serialize override" do
|
|
40
|
+
instance = model_class.new(begins: "2010-10-10T12:21:00Z")
|
|
41
|
+
|
|
42
|
+
expect(instance.to_xml).to eq(<<~XML.strip)
|
|
43
|
+
<validity>
|
|
44
|
+
<begins>2010-10-10T12:21:00Z</begins>
|
|
45
|
+
</validity>
|
|
46
|
+
XML
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "does not fall back to the base Date truncation" do
|
|
50
|
+
instance = model_class.new(begins: "2010-10-10T12:21:00Z")
|
|
51
|
+
|
|
52
|
+
expect(instance.to_xml).not_to include("2010-10-10Z")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "json serialization" do
|
|
57
|
+
it "uses the subclass's serialize override" do
|
|
58
|
+
instance = model_class.new(begins: "2010-10-10T12:21:00Z")
|
|
59
|
+
|
|
60
|
+
expect(instance.to_json).to include('"begins":"2010-10-10T12:21:00Z"')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe "base-class behavior is unchanged" do
|
|
65
|
+
let(:base_model_class) do
|
|
66
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
67
|
+
attribute :begins, Lutaml::Model::Type::Date
|
|
68
|
+
|
|
69
|
+
xml do
|
|
70
|
+
root "validity"
|
|
71
|
+
map_element "begins", to: :begins
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "serializes a plain Date as xs:date" do
|
|
77
|
+
instance = base_model_class.new(begins: "2010-10-10")
|
|
78
|
+
|
|
79
|
+
expect(instance.to_xml).to eq(<<~XML.strip)
|
|
80
|
+
<validity>
|
|
81
|
+
<begins>2010-10-10</begins>
|
|
82
|
+
</validity>
|
|
83
|
+
XML
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
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.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-
|
|
11
|
+
date: 2026-11-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -2194,6 +2194,7 @@ files:
|
|
|
2194
2194
|
- spec/lutaml/model/type/reference_integration_spec.rb
|
|
2195
2195
|
- spec/lutaml/model/type/reference_spec.rb
|
|
2196
2196
|
- spec/lutaml/model/type/string_spec.rb
|
|
2197
|
+
- spec/lutaml/model/type/subclass_serialize_override_spec.rb
|
|
2197
2198
|
- spec/lutaml/model/type/symbol_spec.rb
|
|
2198
2199
|
- spec/lutaml/model/type/time_spec.rb
|
|
2199
2200
|
- spec/lutaml/model/type/time_without_date_spec.rb
|
|
@@ -2364,6 +2365,7 @@ files:
|
|
|
2364
2365
|
- spec/lutaml/xml/plain_model_accessors_spec.rb
|
|
2365
2366
|
- spec/lutaml/xml/plain_model_mapping_resolution_spec.rb
|
|
2366
2367
|
- spec/lutaml/xml/plan_fast_path_spec.rb
|
|
2368
|
+
- spec/lutaml/xml/plan_mixed_content_nested_namespace_spec.rb
|
|
2367
2369
|
- spec/lutaml/xml/plan_namespaced_serialize_spec.rb
|
|
2368
2370
|
- spec/lutaml/xml/plan_ns_less_document_spec.rb
|
|
2369
2371
|
- spec/lutaml/xml/plan_partition_spec.rb
|