lutaml-model 0.8.203 → 0.8.205
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/.gitattributes +5 -0
- data/.github/workflows/lml-conformance.yml +71 -0
- data/.gitignore +7 -0
- data/README.adoc +1 -0
- data/docs/_guides/lml-cross-language.adoc +128 -0
- data/docs/_guides/native-engines.adoc +10 -0
- data/docs/_references/lml-conformance.adoc +78 -0
- data/docs/_references/lml-contract.adoc +290 -0
- data/lib/lutaml/model/lml/artifact_verifier.rb +205 -0
- data/lib/lutaml/model/lml/bundle.rb +171 -0
- data/lib/lutaml/model/lml/document.rb +46 -10
- data/lib/lutaml/model/lml/document_validator.rb +840 -0
- data/lib/lutaml/model/lml/exporter/v1_projector.rb +102 -0
- data/lib/lutaml/model/lml/exporter/v2_projector.rb +401 -0
- data/lib/lutaml/model/lml/exporter.rb +223 -87
- data/lib/lutaml/model/lml/graph_exporter.rb +248 -0
- data/lib/lutaml/model/lml/importer.rb +180 -0
- data/lib/lutaml/model/lml/mapping_compiler.rb +401 -0
- data/lib/lutaml/model/lml/materialization.rb +257 -0
- data/lib/lutaml/model/lml/ordered_content.rb +577 -0
- data/lib/lutaml/model/lml/portable_json.rb +385 -0
- data/lib/lutaml/model/lml/rejected_error.rb +64 -15
- data/lib/lutaml/model/lml/round_trip.rb +86 -0
- data/lib/lutaml/model/lml/value_declarations.rb +84 -0
- data/lib/lutaml/model/lml.rb +61 -0
- data/lib/lutaml/model/schema/definitions/attribute.rb +4 -2
- data/lib/lutaml/model/schema/registry_generator.rb +1 -1
- data/lib/lutaml/model/schema/renderers/member_decls.rb +1 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +10 -0
- data/lib/lutaml/model/sequence.rb +7 -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 +85 -3
- data/lib/lutaml/xml/leptris/plan_compiler.rb +190 -45
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +209 -56
- data/lib/lutaml/xml/leptris/plan_serializer.rb +533 -102
- 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/schema/lml/document.schema.json +179 -0
- data/scripts/lml/export_choices.rb +57 -0
- data/scripts/lml/export_conformance.rb +23 -0
- data/scripts/lml/export_mml.rb +253 -0
- data/scripts/lml/export_preservation.rb +421 -0
- data/scripts/lml/verify_artifacts.rb +31 -0
- data/spec/fixtures/lml_artifacts/model.json +1 -0
- data/spec/fixtures/lml_artifacts/valid.json +1 -0
- data/spec/fixtures/lml_artifacts/valid.sha256 +1 -0
- data/spec/fixtures/lml_conformance/core/index.json +1 -0
- data/spec/fixtures/lml_conformance/core/manifest.json +1 -0
- data/spec/fixtures/lml_conformance/core/schema.json +1 -0
- data/spec/fixtures/lml_conformance/core/schema.yaml +79 -0
- data/spec/fixtures/lml_conformance/float_vectors.generator.rb +60 -0
- data/spec/fixtures/lml_conformance/float_vectors.json +21550 -0
- data/spec/fixtures/lml_conformance/preservation/index.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/manifest.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/schema.json +1 -0
- data/spec/fixtures/lml_conformance/preservation/schema.yaml +319 -0
- data/spec/fixtures/lml_conformance/r2_refusals.generator.rb +153 -0
- data/spec/fixtures/lml_conformance/r2_refusals.json +1662 -0
- data/spec/fixtures/lml_conformance/ruby_portable_interop.generator.rb +40 -0
- data/spec/fixtures/lml_conformance/ruby_portable_interop.json +1 -0
- data/spec/fixtures/lml_contract/bundle.json +81 -0
- data/spec/fixtures/lml_contract/manifest.json +30 -0
- data/spec/fixtures/lml_contract/v1_unit.canonical.json +1 -0
- data/spec/fixtures/lml_contract/v1_unit.json +1 -0
- data/spec/fixtures/lml_contract/v2_node.canonical.json +1 -0
- data/spec/fixtures/lml_contract/v2_node.json +32 -0
- data/spec/fixtures/lml_mml/inventory.json +1 -0
- data/spec/fixtures/lml_mml/manifest.json +1 -0
- data/spec/fixtures/lml_mml/oracle.json +1 -0
- data/spec/fixtures/lml_mml/v3-mi-mixed.json +1 -0
- data/spec/fixtures/lml_mml/v3-mi-mixed.yaml +970 -0
- data/spec/fixtures/lml_mml/v4-mi-mixed.json +1 -0
- data/spec/fixtures/lml_mml/v4-mi-mixed.yaml +1516 -0
- data/spec/fixtures/lml_mml_materialization/replay.rb +37 -0
- data/spec/lutaml/model/lml_any_attribute_spec.rb +91 -0
- data/spec/lutaml/model/lml_artifact_verifier_spec.rb +86 -0
- data/spec/lutaml/model/lml_builtin_types_spec.rb +49 -0
- data/spec/lutaml/model/lml_conformance_spec.rb +178 -0
- data/spec/lutaml/model/lml_document_spec.rb +279 -0
- data/spec/lutaml/model/lml_export_validation_spec.rb +96 -0
- data/spec/lutaml/model/lml_exporter_spec.rb +127 -5
- data/spec/lutaml/model/lml_graph_exporter_spec.rb +205 -0
- data/spec/lutaml/model/lml_importer_spec.rb +290 -0
- data/spec/lutaml/model/lml_input_hardening_spec.rb +156 -0
- data/spec/lutaml/model/lml_mapping_compiler_spec.rb +256 -0
- data/spec/lutaml/model/lml_materialization_spec.rb +138 -0
- data/spec/lutaml/model/lml_mml_materialization_spec.rb +54 -0
- data/spec/lutaml/model/lml_mml_pilot_spec.rb +150 -0
- data/spec/lutaml/model/lml_model_choices_spec.rb +88 -0
- data/spec/lutaml/model/lml_ordered_content_spec.rb +243 -0
- data/spec/lutaml/model/lml_portable_json_spec.rb +310 -0
- data/spec/lutaml/model/lml_preservation_spec.rb +211 -0
- data/spec/lutaml/model/lml_review_export_spec.rb +247 -0
- data/spec/lutaml/model/lml_review_import_spec.rb +390 -0
- data/spec/lutaml/model/lml_review_misc_spec.rb +152 -0
- data/spec/lutaml/model/lml_review_round4_spec.rb +200 -0
- data/spec/lutaml/model/lml_review_round5_spec.rb +194 -0
- data/spec/lutaml/model/lml_ruby_interop_fixture_spec.rb +37 -0
- data/spec/lutaml/model/lml_shared_corpus_spec.rb +132 -0
- data/spec/lutaml/model/lml_value_declarations_spec.rb +128 -0
- data/spec/lutaml/model/schema/class_loader_spec.rb +51 -0
- data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +20 -0
- data/spec/lutaml/model/sequence_spec.rb +48 -0
- data/spec/lutaml/xml/cdata_emission_spec.rb +68 -0
- data/spec/lutaml/xml/production_lane_parity_spec.rb +632 -0
- data/spec/support/lml_any_attribute_fixtures.rb +26 -0
- data/spec/support/lml_conformance.rb +292 -0
- data/spec/support/lml_corpus.rb +75 -0
- data/spec/support/lml_export_fixtures.rb +190 -0
- data/spec/support/lml_graph_fixtures.rb +108 -0
- data/spec/support/lml_import_fixtures.rb +52 -0
- data/spec/support/lml_mapping_fixtures.rb +170 -0
- data/spec/support/lml_materialization_fixtures.rb +53 -0
- data/spec/support/lml_model_choices_fixtures.rb +150 -0
- data/spec/support/lml_order_fixtures.rb +151 -0
- metadata +94 -3
- data/lib/lutaml/model/schema/schema_builder/nokogiri.rb +0 -41
|
@@ -58,7 +58,29 @@ module Lutaml
|
|
|
58
58
|
PER_NODE_ROW_KINDS = %i[nested ordered_deferred
|
|
59
59
|
child_deferred].freeze
|
|
60
60
|
|
|
61
|
+
# Signature holder: the (attribute count, rule count) a plan was
|
|
62
|
+
# compiled against, keyed like PLAN_CACHE.
|
|
63
|
+
PLAN_SIGNATURES = ::Class.new do
|
|
64
|
+
class << self
|
|
65
|
+
def cache
|
|
66
|
+
@cache ||= {}
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end.cache
|
|
70
|
+
|
|
61
71
|
class << self
|
|
72
|
+
# Drop every compiled plan of a model class: its caches were
|
|
73
|
+
# cleared (Serialization#clear_cache).
|
|
74
|
+
def invalidate!(model_class)
|
|
75
|
+
PLAN_CACHE.each_key.to_a.each do |key|
|
|
76
|
+
next unless key.first.equal?(model_class)
|
|
77
|
+
|
|
78
|
+
PLAN_CACHE.delete(key)
|
|
79
|
+
PLAN_SIGNATURES.delete(key)
|
|
80
|
+
end
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
83
|
+
|
|
62
84
|
def compile(model_class, register)
|
|
63
85
|
# Version gate: below MIN_LEPTRIS_VERSION (the single
|
|
64
86
|
# capability floor) gems take the interpretive path via
|
|
@@ -77,7 +99,19 @@ module Lutaml
|
|
|
77
99
|
)
|
|
78
100
|
|
|
79
101
|
key = [model_class, register]
|
|
80
|
-
|
|
102
|
+
# A late-added attribute or rule (the XMI extension loader
|
|
103
|
+
# re-runs the xml DSL on a defined class) must reach the plan:
|
|
104
|
+
# the compiled shape is checked against the class's current
|
|
105
|
+
# attribute and rule counts.
|
|
106
|
+
signature = plan_signature(model_class, register)
|
|
107
|
+
if PLAN_CACHE.key?(key)
|
|
108
|
+
return PLAN_CACHE[key] if PLAN_SIGNATURES[key] == signature
|
|
109
|
+
|
|
110
|
+
# The class changed under its compiled plan (the XMI
|
|
111
|
+
# extension loader re-runs the xml DSL on a defined class):
|
|
112
|
+
# a late-bound class belongs to the interpretive pipeline.
|
|
113
|
+
return opt_out!(:class_changed)
|
|
114
|
+
end
|
|
81
115
|
|
|
82
116
|
# Cycle guard: a self-referential model (JATS sec-in-sec) must
|
|
83
117
|
# resolve to nil — the interpretive pipeline owns it. The guard
|
|
@@ -94,10 +128,21 @@ module Lutaml
|
|
|
94
128
|
|
|
95
129
|
stack.push(key)
|
|
96
130
|
begin
|
|
97
|
-
PLAN_CACHE[key] = build(model_class, register)
|
|
131
|
+
PLAN_CACHE[key] = plan = build(model_class, register)
|
|
132
|
+
PLAN_SIGNATURES[key] = signature
|
|
98
133
|
ensure
|
|
99
134
|
stack.pop
|
|
100
135
|
end
|
|
136
|
+
plan
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def plan_signature(model_class, register)
|
|
140
|
+
return nil unless model_class.is_a?(Class) &&
|
|
141
|
+
model_class.include?(::Lutaml::Model::Serialize)
|
|
142
|
+
|
|
143
|
+
mapping = model_class.mappings_for(:xml, register)
|
|
144
|
+
[model_class.attributes(register).size,
|
|
145
|
+
mapping&.mappings(register)&.size]
|
|
101
146
|
end
|
|
102
147
|
|
|
103
148
|
private
|
|
@@ -138,7 +183,7 @@ module Lutaml
|
|
|
138
183
|
rows = []
|
|
139
184
|
attr_rows = [] # [[rule, attr, row_name]] hydration metadata
|
|
140
185
|
plan_attrs = [] # [{name:, kind:}] rows for the engine plan
|
|
141
|
-
compiled = [] # [rule, attr, kind, spelling,
|
|
186
|
+
compiled = [] # [rule, attr, kind, spelling, delegate_name(, type)]
|
|
142
187
|
ns_attr_names = [] # exact-URI attribute rows (ambiguity guard)
|
|
143
188
|
# Local-name claim tallies for attribute rows: a name claimed
|
|
144
189
|
# by both an exact-URI row and a plain (any-namespace) row
|
|
@@ -150,9 +195,26 @@ module Lutaml
|
|
|
150
195
|
cdata = false
|
|
151
196
|
mixed_content = false
|
|
152
197
|
needs_nodes = false
|
|
153
|
-
collection_defaults = [] # collection attrs with element rows
|
|
154
198
|
tag = 100 # type_tag echo space for callback-routed rows
|
|
155
199
|
model_ns = plan_namespace(model_class, mapping, register)
|
|
200
|
+
# The interpretive writer's elementFormDefault contract
|
|
201
|
+
# (ElementBuilder.determine_element_namespace +
|
|
202
|
+
# DeclarationPlanner's blank-namespace rule) for a locally
|
|
203
|
+
# declared element with no namespace of its own:
|
|
204
|
+
# - form explicitly :qualified — it inherits the namespace
|
|
205
|
+
# - form explicitly :unqualified — :unqualified: spelled bare
|
|
206
|
+
# whatever the root carries
|
|
207
|
+
# - form not set — :blank: it is in NO namespace of its own;
|
|
208
|
+
# the serializer spells it through the enclosing
|
|
209
|
+
# namespace's format and, under the default-namespace
|
|
210
|
+
# one, opts it out with xmlns="" (BlankScope)
|
|
211
|
+
# Rows whose type or child model declares a namespace keep it.
|
|
212
|
+
ns_class = mapping.namespace_class
|
|
213
|
+
declared_form = if ns_class&.element_form_default_set?
|
|
214
|
+
ns_class.element_form_default
|
|
215
|
+
end
|
|
216
|
+
unqualified_form = declared_form == :unqualified
|
|
217
|
+
blank_form = !ns_class.nil? && declared_form.nil?
|
|
156
218
|
|
|
157
219
|
# Collection rows are NATIVE since leptris 1.9.178 —
|
|
158
220
|
# collection values echo name and type_tag (the #220 gap is
|
|
@@ -170,9 +232,22 @@ module Lutaml
|
|
|
170
232
|
else
|
|
171
233
|
model_class.attributes(register)[rule.to]
|
|
172
234
|
end
|
|
235
|
+
# Rows carry the delegate NAME: every lane sends it to the
|
|
236
|
+
# instance (value_of). The target attribute above only
|
|
237
|
+
# resolves the child attribute type here; storing it in the
|
|
238
|
+
# row made every delegate: rule crash the leptris lanes.
|
|
239
|
+
delegate_ref = delegate_target && rule.delegate
|
|
173
240
|
return opt_out!(:attr_nil) if attr.nil?
|
|
174
241
|
return opt_out!(:derived) if attr.derived?
|
|
175
242
|
|
|
243
|
+
# A Hash-typed value has no scalar spelling: the interpretive
|
|
244
|
+
# writer expands it into child elements and the reader
|
|
245
|
+
# rebuilds it (a scalar row serialized its to_s and crashed
|
|
246
|
+
# Hash.cast on the way back).
|
|
247
|
+
attr_type = attr.type(register)
|
|
248
|
+
return opt_out!(:hash_typed) if attr_type.is_a?(Class) &&
|
|
249
|
+
attr_type <= ::Lutaml::Model::Type::Hash
|
|
250
|
+
|
|
176
251
|
# Partition rows (TODO 34 step 2) ride native predicates
|
|
177
252
|
# only in the plain-capture shape; any other when_attribute
|
|
178
253
|
# shape stays interpretive (the suite pins nested-target
|
|
@@ -188,13 +263,6 @@ module Lutaml
|
|
|
188
263
|
return opt_out!(:non_plain_partition) unless plain_partition
|
|
189
264
|
end
|
|
190
265
|
|
|
191
|
-
# Interpretive hydration materializes every mapped
|
|
192
|
-
# collection, present or not; the fast path mirrors with
|
|
193
|
-
# constructor-time empty arrays.
|
|
194
|
-
unless rule.attribute? || !attr.collection?
|
|
195
|
-
collection_defaults << attr.name.to_sym
|
|
196
|
-
end
|
|
197
|
-
|
|
198
266
|
# Fragment deferrals lose ancestor namespace context —
|
|
199
267
|
# ns-qualified models keep those rules interpretive.
|
|
200
268
|
fragment_needed = rule.has_custom_method_for_deserialization? ||
|
|
@@ -212,21 +280,21 @@ module Lutaml
|
|
|
212
280
|
mixed_content = true
|
|
213
281
|
compiled << [rule, attr,
|
|
214
282
|
attr.collection? ? :content : :content_deferred,
|
|
215
|
-
nil,
|
|
283
|
+
nil, delegate_ref]
|
|
216
284
|
rows << { name: "__content__#{compiled.size}", kind: :content }
|
|
217
285
|
elsif rule.raw_mapping? || rule.raw == :element
|
|
218
|
-
compiled << [rule, attr, :raw, nil,
|
|
286
|
+
compiled << [rule, attr, :raw, nil, delegate_ref]
|
|
219
287
|
rows << { name: rule.name.to_s, kind: :raw }
|
|
220
288
|
elsif rule.has_custom_method_for_deserialization?
|
|
221
289
|
needs_nodes = true
|
|
222
|
-
compiled << [rule, attr, :custom_method, nil,
|
|
290
|
+
compiled << [rule, attr, :custom_method, nil, delegate_ref]
|
|
223
291
|
rows << { name: rule.name.to_s, kind: :raw }
|
|
224
|
-
elsif rule
|
|
292
|
+
elsif polymorphic_shape?(rule, attr)
|
|
225
293
|
type = attr.type(register)
|
|
226
294
|
return opt_out!(:non_serializable_poly) unless serializable_type?(type) || attr.union?
|
|
227
295
|
|
|
228
296
|
needs_nodes = true
|
|
229
|
-
compiled << [rule, attr, :polymorphic, nil,
|
|
297
|
+
compiled << [rule, attr, :polymorphic, nil, delegate_ref]
|
|
230
298
|
rows << { name: rule.name.to_s, kind: :raw }
|
|
231
299
|
else
|
|
232
300
|
type = attr.type(register)
|
|
@@ -247,15 +315,21 @@ module Lutaml
|
|
|
247
315
|
end
|
|
248
316
|
needs_nodes = true if child.nil? || child[:ordered]
|
|
249
317
|
compiled_entry, row = child_row_for(rule, attr, type, child,
|
|
250
|
-
|
|
251
|
-
model_ns
|
|
318
|
+
delegate_ref,
|
|
319
|
+
model_ns,
|
|
320
|
+
local_element_form(
|
|
321
|
+
child && child[:tree][:ns],
|
|
322
|
+
model_ns, rule,
|
|
323
|
+
unqualified_form,
|
|
324
|
+
blank_form
|
|
325
|
+
))
|
|
252
326
|
compiled << compiled_entry
|
|
253
327
|
needs_nodes ||= child && child[:needs_nodes]
|
|
254
328
|
rows << row
|
|
255
329
|
elsif rule.multiple_mappings?
|
|
256
330
|
rule.name.each do |spelling|
|
|
257
331
|
compiled << [rule, attr, :spelling, spelling.to_s,
|
|
258
|
-
|
|
332
|
+
delegate_ref]
|
|
259
333
|
rows << { name: spelling.to_s, kind: :callback,
|
|
260
334
|
type_tag: (tag += 1) }
|
|
261
335
|
end
|
|
@@ -263,22 +337,12 @@ module Lutaml
|
|
|
263
337
|
return opt_out!(:non_scalar) unless scalar_type?(attr, register)
|
|
264
338
|
|
|
265
339
|
row = { name: rule.name.to_s }
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
# type form inherit the tree namespace and land
|
|
273
|
-
# under the wrong default xmlns (uniword
|
|
274
|
-
# CoreProperties: <dc:title> spelled <title>).
|
|
275
|
-
type_ns_form = element_type_ns_form(rule, attr,
|
|
276
|
-
register, model_ns)
|
|
277
|
-
return opt_out!(:elem_type_ns_symbol) if type_ns_form == :bail_symbol
|
|
278
|
-
return opt_out!(:elem_type_ns_aliases) if type_ns_form == :bail_aliases
|
|
279
|
-
|
|
280
|
-
row[:ns] = type_ns_form if type_ns_form
|
|
281
|
-
end
|
|
340
|
+
ns = scalar_row_ns(rule, attr, register, model_ns,
|
|
341
|
+
unqualified_form, blank_form)
|
|
342
|
+
return opt_out!(:elem_type_ns_symbol) if ns == :bail_symbol
|
|
343
|
+
return opt_out!(:elem_type_ns_aliases) if ns == :bail_aliases
|
|
344
|
+
|
|
345
|
+
row[:ns] = ns if ns
|
|
282
346
|
# lutaml-model#88: same-name rows partitioned by the
|
|
283
347
|
# rule's discriminator ride the engine's exclusive
|
|
284
348
|
# predicate match (leptris 1.9.221+, #1272).
|
|
@@ -286,11 +350,11 @@ module Lutaml
|
|
|
286
350
|
|
|
287
351
|
if attr.collection?
|
|
288
352
|
compiled << [rule, attr, :collection_native, nil,
|
|
289
|
-
|
|
353
|
+
delegate_ref]
|
|
290
354
|
rows << row.merge(kind: :collection)
|
|
291
355
|
else
|
|
292
356
|
cdata ||= rule.cdata
|
|
293
|
-
compiled << [rule, attr, :scalar, nil,
|
|
357
|
+
compiled << [rule, attr, :scalar, nil, delegate_ref]
|
|
294
358
|
rows << row.merge(kind: :scalar)
|
|
295
359
|
end
|
|
296
360
|
end
|
|
@@ -391,7 +455,17 @@ module Lutaml
|
|
|
391
455
|
# Lazy: the leptris require only belongs on the
|
|
392
456
|
# engines-enabled path.
|
|
393
457
|
require "leptris/xml/descriptor"
|
|
394
|
-
|
|
458
|
+
# :blank is the serializer's no-namespace form. The engine
|
|
459
|
+
# captures such a row by name at any qualification (no ns
|
|
460
|
+
# form — main's behavior for a locally declared element):
|
|
461
|
+
# the source may spell it bare or with the parent's
|
|
462
|
+
# prefix, and the instance's own format preservation
|
|
463
|
+
# decides the spelling on the way out.
|
|
464
|
+
descriptor = ::Leptris::XML::Descriptor.build(
|
|
465
|
+
**tree, children: rows.map do |r|
|
|
466
|
+
r[:ns] == :blank ? r.except(:ns) : r
|
|
467
|
+
end
|
|
468
|
+
)
|
|
395
469
|
rescue StandardError
|
|
396
470
|
return nil
|
|
397
471
|
end
|
|
@@ -401,7 +475,6 @@ module Lutaml
|
|
|
401
475
|
row_tags: row_tags, namespaced: namespaced,
|
|
402
476
|
ordered: mapping.ordered? || mapping.mixed_content?,
|
|
403
477
|
needs_nodes: needs_nodes,
|
|
404
|
-
collection_defaults: collection_defaults,
|
|
405
478
|
contested_names: contested.empty? ? nil : contested,
|
|
406
479
|
ns_attr_names: ns_attr_names.empty? ? nil : ns_attr_names,
|
|
407
480
|
wildcard_tag: (wildcard_tag if defined?(wildcard_tag)) }
|
|
@@ -531,20 +604,73 @@ module Lutaml
|
|
|
531
604
|
# rows; nothing is lost under a namespaced parent.
|
|
532
605
|
# - otherwise: :nested with the child's tree.
|
|
533
606
|
# Returns [[compiled tuple], tree row].
|
|
534
|
-
def child_row_for(rule, attr, type, child,
|
|
535
|
-
model_ns)
|
|
607
|
+
def child_row_for(rule, attr, type, child, delegate_ref,
|
|
608
|
+
model_ns, local_form = nil)
|
|
536
609
|
if child.nil?
|
|
537
|
-
[[rule, attr, :child_deferred, nil,
|
|
610
|
+
[[rule, attr, :child_deferred, nil, delegate_ref, type],
|
|
538
611
|
{ name: rule.name.to_s, kind: :raw }]
|
|
539
612
|
elsif child[:ordered]
|
|
540
|
-
[[rule, attr, :ordered_deferred, nil,
|
|
613
|
+
[[rule, attr, :ordered_deferred, nil, delegate_ref, type],
|
|
541
614
|
{ name: rule.name.to_s, kind: :raw }]
|
|
542
615
|
else
|
|
543
616
|
row = { name: rule.name.to_s, kind: :nested,
|
|
544
617
|
plan: child[:tree] }
|
|
545
|
-
|
|
546
|
-
|
|
618
|
+
if rule.namespace_set?
|
|
619
|
+
row[:ns] = child_ns(rule, model_ns)
|
|
620
|
+
elsif local_form
|
|
621
|
+
row[:ns] = local_form
|
|
622
|
+
end
|
|
623
|
+
[[rule, attr, :nested, nil, delegate_ref, type], row]
|
|
624
|
+
end
|
|
625
|
+
end
|
|
626
|
+
|
|
627
|
+
# The ns form of a scalar element row: the rule's own
|
|
628
|
+
# namespace, else the attribute type's (the interpretive
|
|
629
|
+
# resolve step 4 — nil when it equals the model's own), else
|
|
630
|
+
# the local element's form per the parent mapping's
|
|
631
|
+
# elementFormDefault. A locally declared scalar under an
|
|
632
|
+
# explicitly :unqualified parent in its own namespace is
|
|
633
|
+
# spelled bare (apply_unqualified_form_default); a type with
|
|
634
|
+
# no namespace at all follows the parent's form. Returns the
|
|
635
|
+
# opt-out clause when the type form is not row-expressible.
|
|
636
|
+
def scalar_row_ns(rule, attr, register, model_ns, unqualified_form,
|
|
637
|
+
blank_form)
|
|
638
|
+
return child_ns(rule, model_ns) if rule.namespace_set?
|
|
639
|
+
|
|
640
|
+
type_ns_form = element_type_ns_form(rule, attr, register, model_ns)
|
|
641
|
+
return type_ns_form if type_ns_form
|
|
642
|
+
return unless unqualified_row?(rule)
|
|
643
|
+
|
|
644
|
+
local_element_form(nil, model_ns, rule, unqualified_form,
|
|
645
|
+
blank_form &&
|
|
646
|
+
attr.type_namespace_class(register).nil?)
|
|
647
|
+
end
|
|
648
|
+
|
|
649
|
+
# The ns form of a locally declared element (no rule
|
|
650
|
+
# namespace), per the parent mapping's elementFormDefault: the
|
|
651
|
+
# element's own namespace (a nested model's) is kept unless the
|
|
652
|
+
# explicit :unqualified form spells it bare; without one it
|
|
653
|
+
# follows the parent's form — :unqualified, or :blank (no
|
|
654
|
+
# namespace) when the form is not set.
|
|
655
|
+
def local_element_form(own_ns, model_ns, rule, unqualified_form,
|
|
656
|
+
blank_form)
|
|
657
|
+
return unless unqualified_row?(rule)
|
|
658
|
+
|
|
659
|
+
# The rule's own form: :unqualified always spells bare
|
|
660
|
+
# (determine_element_namespace priority 3), whatever the
|
|
661
|
+
# parent's form declares.
|
|
662
|
+
return :unqualified if rule.form == :unqualified
|
|
663
|
+
|
|
664
|
+
own_uri = own_ns.is_a?(::Hash) ? own_ns[:exact] : nil
|
|
665
|
+
if own_uri
|
|
666
|
+
return :unqualified if unqualified_form &&
|
|
667
|
+
own_uri == model_ns&.[](:exact)
|
|
668
|
+
elsif unqualified_form
|
|
669
|
+
return :unqualified
|
|
670
|
+
elsif blank_form
|
|
671
|
+
return :blank
|
|
547
672
|
end
|
|
673
|
+
nil
|
|
548
674
|
end
|
|
549
675
|
|
|
550
676
|
def compilable_mapping?(mapping)
|
|
@@ -636,6 +762,13 @@ module Lutaml
|
|
|
636
762
|
form
|
|
637
763
|
end
|
|
638
764
|
|
|
765
|
+
# A locally declared element the writer would leave to its
|
|
766
|
+
# parent's form: no rule namespace, and no :qualified form
|
|
767
|
+
# override forcing inheritance.
|
|
768
|
+
def unqualified_row?(rule)
|
|
769
|
+
!rule.namespace_set? && rule.form != :qualified
|
|
770
|
+
end
|
|
771
|
+
|
|
639
772
|
def content_rows(rows)
|
|
640
773
|
rows.count { |r| r[:kind] == :content }
|
|
641
774
|
end
|
|
@@ -653,6 +786,18 @@ module Lutaml
|
|
|
653
786
|
prefix: ns_class.prefix_default&.to_s }
|
|
654
787
|
end
|
|
655
788
|
|
|
789
|
+
# Whether a row resolves its child class at parse time — the
|
|
790
|
+
# interpretive cast's own inputs: the rule's polymorphic option
|
|
791
|
+
# (a class map or `true`), its legacy polymorphic_map, the
|
|
792
|
+
# attribute's polymorphic class, or a union. Such a row defers
|
|
793
|
+
# its subtree to the interpretive cast.
|
|
794
|
+
def polymorphic_shape?(rule, attr)
|
|
795
|
+
option = rule.polymorphic
|
|
796
|
+
rule.polymorphic_mapping? ||
|
|
797
|
+
(option.is_a?(::Hash) ? !option.empty? : !!option) ||
|
|
798
|
+
attr.polymorphic? || attr.union?
|
|
799
|
+
end
|
|
800
|
+
|
|
656
801
|
def scalar_type?(attr, register)
|
|
657
802
|
type = attr.type(register)
|
|
658
803
|
type.is_a?(Class) && type < ::Lutaml::Model::Type::Value &&
|