lutaml-model 0.8.163 → 0.8.165
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/key_value/mapping.rb +10 -0
- data/lib/lutaml/key_value/transformation/value_serializer.rb +8 -0
- data/lib/lutaml/key_value/transformation.rb +11 -0
- data/lib/lutaml/model/adapter_resolver.rb +27 -2
- data/lib/lutaml/model/attribute.rb +31 -1
- data/lib/lutaml/model/serialization_adapter.rb +0 -1
- data/lib/lutaml/model/serialize.rb +11 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/leptris/plan_serializer.rb +1 -2
- data/lib/lutaml/yamls/adapter/yeptris_adapter.rb +17 -4
- data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +40 -0
- data/spec/lutaml/model/binary_attribute_value_spec.rb +32 -0
- data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +3 -2
- data/spec/lutaml/model/custom_vobject_adapter_spec.rb +3 -2
- data/spec/lutaml/model/json_hash_collection_spec.rb +37 -0
- data/spec/lutaml/model/kv_flatten_memo_spec.rb +49 -0
- data/spec/lutaml/xml/leptris/native_emission_ordered_spec.rb +12 -13
- 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: 3540b4bb5e740bd2f3bda909b1e570b822f82d04703cb11347e9b8124cda5538
|
|
4
|
+
data.tar.gz: 29e6a45a50e57f6d8b6412e60251b26c118511b1fdbfa3091fb42fabd3b6d792
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3dce5f2bc083bf9b41ab3e1959ffb828294bfedc82d102fdae4e7419df1c3b18fb707fb19388317b9a5e8f95b910ed22b8b2c124ddf4be74c7b7e1ebf5ee8f6
|
|
7
|
+
data.tar.gz: 854bd87449c9af4574ae68f44fc50ee61aa5d1906944e3a9c10c50fbc4fe8f762f6b5eec1ec48093106d7571775e9520dcf7358ff642af36a55bfe15bd3e0ac7
|
|
@@ -174,6 +174,12 @@ module Lutaml
|
|
|
174
174
|
existing << rule
|
|
175
175
|
end
|
|
176
176
|
end
|
|
177
|
+
# A later DSL block (e.g. a mixin-installed key_value combined
|
|
178
|
+
# with an in-class one) mutates @mappings directly — the frozen
|
|
179
|
+
# flattened memo must not outlive it (lutaml-model#1122: the
|
|
180
|
+
# InternetDraft "version" rule vanished from to_hash when the
|
|
181
|
+
# memo was built before the second block ran).
|
|
182
|
+
@flattened_mappings = nil
|
|
177
183
|
end
|
|
178
184
|
|
|
179
185
|
# Index of the prior partition a when_attribute rule replaces
|
|
@@ -223,6 +229,7 @@ module Lutaml
|
|
|
223
229
|
with: with,
|
|
224
230
|
delegate: delegate,
|
|
225
231
|
)]
|
|
232
|
+
@flattened_mappings = nil
|
|
226
233
|
end
|
|
227
234
|
|
|
228
235
|
alias map_all_content map_all
|
|
@@ -300,6 +307,9 @@ module Lutaml
|
|
|
300
307
|
register_id).mappings_hash),
|
|
301
308
|
)
|
|
302
309
|
end
|
|
310
|
+
# Import resolution mutates the raw rule store after the memo may
|
|
311
|
+
# have been built by an earlier access.
|
|
312
|
+
@flattened_mappings = nil
|
|
303
313
|
end
|
|
304
314
|
|
|
305
315
|
def validate!(key, to, with, render_nil, render_empty)
|
|
@@ -173,6 +173,14 @@ model_class: nil)
|
|
|
173
173
|
if plan[:identity_type] && !value.is_a?(::Lutaml::Model::Serialize) && !value.is_a?(::Hash) && !value.is_a?(::Array)
|
|
174
174
|
return value
|
|
175
175
|
end
|
|
176
|
+
# Structured data stored on a builtin-scalar-declared
|
|
177
|
+
# attribute (the #1114 parse tolerance) emits verbatim; a
|
|
178
|
+
# registered custom serializer keeps its shaping contract.
|
|
179
|
+
if value.is_a?(::Hash) &&
|
|
180
|
+
!::Lutaml::Model::Type::Value
|
|
181
|
+
.format_type_serializer_for(format, rule.attribute_type)&.fetch(:to, nil)
|
|
182
|
+
return value
|
|
183
|
+
end
|
|
176
184
|
if (to_fn = plan[:to_fn])
|
|
177
185
|
return to_fn.call(rule.attribute_type.new(value))
|
|
178
186
|
end
|
|
@@ -1254,6 +1254,17 @@ child_mappings, options)
|
|
|
1254
1254
|
# This allows custom type subclasses to override to_json, to_yaml, etc.
|
|
1255
1255
|
if rule.attribute_type.is_a?(Class) && rule.attribute_type < Lutaml::Model::Type::Value
|
|
1256
1256
|
type = rule.attribute_type
|
|
1257
|
+
# Structured data stored on a builtin-scalar-declared
|
|
1258
|
+
# attribute (the #1114 tolerance) emits verbatim — wrapping
|
|
1259
|
+
# it stringifies (to_s of the hash) and destroys it on the
|
|
1260
|
+
# round trip. Custom subclasses with a registered serializer
|
|
1261
|
+
# keep their shaping contract.
|
|
1262
|
+
if value.is_a?(::Hash) &&
|
|
1263
|
+
!::Lutaml::Model::Type::Value
|
|
1264
|
+
.format_type_serializer_for(format, type)&.fetch(:to, nil)
|
|
1265
|
+
return value
|
|
1266
|
+
end
|
|
1267
|
+
|
|
1257
1268
|
# Identity fast path (TODO.perf/07): a builtin type with no custom
|
|
1258
1269
|
# to_<format>/from_<format> behavior emits an already-native value
|
|
1259
1270
|
# unchanged — the wrap only re-casts and re-emits it.
|
|
@@ -435,14 +435,39 @@ module Lutaml
|
|
|
435
435
|
def detect_yeptris_kv_adapter(format)
|
|
436
436
|
default = metadata.dig(format, :default)
|
|
437
437
|
return default if Lutaml::Model.opal?
|
|
438
|
-
|
|
438
|
+
|
|
439
|
+
unless yeptris_opted_in?
|
|
440
|
+
warn_yeptris_present_once(format)
|
|
441
|
+
return default
|
|
442
|
+
end
|
|
439
443
|
return default unless Utils.safe_load("yeptris", :Yeptris)
|
|
440
444
|
|
|
441
445
|
load_adapter(format, :yeptris).available? ? :yeptris : default
|
|
442
446
|
end
|
|
443
447
|
|
|
448
|
+
# The consumer-neutral opt-in; FONTIST_YAML=yeptris stays honored
|
|
449
|
+
# as the legacy spelling fontist and lutaml-store already ship
|
|
450
|
+
# (#1115: glossarist is not fontist — the switch must not carry
|
|
451
|
+
# one consumer's namespace).
|
|
444
452
|
def yeptris_opted_in?
|
|
445
|
-
|
|
453
|
+
%w[LUTAML_YAML FONTIST_YAML].any? { |k| ENV[k] == "yeptris" }
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
# Make the gated engine visible (#1115 ask 3): a process whose
|
|
457
|
+
# bundle merely contains yeptris used to get it auto-selected;
|
|
458
|
+
# the gate keeps that from happening silently, but the presence
|
|
459
|
+
# of an unused native engine is exactly the kind of fact an
|
|
460
|
+
# upgrading consumer needs to see once.
|
|
461
|
+
def warn_yeptris_present_once(_format)
|
|
462
|
+
return if Lutaml::Model.opal?
|
|
463
|
+
return if @yeptris_presence_warned
|
|
464
|
+
return unless Utils.safe_load("yeptris", :Yeptris)
|
|
465
|
+
|
|
466
|
+
@yeptris_presence_warned = true
|
|
467
|
+
warn "[Lutaml::Model] yeptris is present in this bundle but the " \
|
|
468
|
+
"native YAML engine is not enabled (its parity fixes are " \
|
|
469
|
+
"still landing, leptris/yeptris#863); the standard adapter " \
|
|
470
|
+
"serves YAML. Enable explicitly with LUTAML_YAML=yeptris."
|
|
446
471
|
end
|
|
447
472
|
|
|
448
473
|
# Detect available XML adapter.
|
|
@@ -607,11 +607,41 @@ module Lutaml
|
|
|
607
607
|
cast_element_present(value, register, resolved_type)
|
|
608
608
|
end
|
|
609
609
|
|
|
610
|
+
# Builtin scalars whose parse of structured data passes the data
|
|
611
|
+
# through verbatim (#1114) instead of wrapping it — custom
|
|
612
|
+
# Type::Value subclasses keep the wrapper/shaping contract.
|
|
613
|
+
# Lazy: the Type constants load after this class body.
|
|
614
|
+
def self.native_value_types
|
|
615
|
+
@native_value_types ||= [
|
|
616
|
+
Type::String, Type::Integer, Type::Float, Type::Date,
|
|
617
|
+
Type::Time, Type::DateTime, Type::Symbol
|
|
618
|
+
].each_with_object({}.compare_by_identity) { |t, h| h[t] = true }
|
|
619
|
+
end
|
|
620
|
+
|
|
610
621
|
def cast_element_present(value, register, resolved_type = nil)
|
|
611
622
|
resolved_type ||= type(register)
|
|
612
623
|
|
|
613
624
|
return cast_union(value, nil, register) if union?
|
|
614
|
-
|
|
625
|
+
|
|
626
|
+
# The Hash branch is the nested-model constructor path: only a
|
|
627
|
+
# Serializable element type builds from a hash document. A
|
|
628
|
+
# builtin scalar Value type receiving structured data keeps the
|
|
629
|
+
# data verbatim — stringifying (Type::String#cast's to_s, or a
|
|
630
|
+
# wrapper holding the raw hash in @value) silently destroyed
|
|
631
|
+
# it (lutaml-model#1114, fontist's Google Fonts files map). A
|
|
632
|
+
# CUSTOM Value subclass keeps the wrapper contract: its custom
|
|
633
|
+
# from-shaping receives the hash deliberately (the value-policy
|
|
634
|
+
# contract).
|
|
635
|
+
if value.is_a?(::Hash) && !hash_type?
|
|
636
|
+
# Builtin scalars keep structured data verbatim (#1114 — a
|
|
637
|
+
# to_s or a raw-hash wrapper silently destroyed it); custom
|
|
638
|
+
# Value subclasses keep the wrapper contract (their
|
|
639
|
+
# constructor shapes the hash deliberately), as do
|
|
640
|
+
# Serializable element types.
|
|
641
|
+
return value if self.class.native_value_types.include?(resolved_type)
|
|
642
|
+
|
|
643
|
+
return resolved_type.new(value)
|
|
644
|
+
end
|
|
615
645
|
|
|
616
646
|
# Special handling for Reference types - pass the metadata
|
|
617
647
|
# (the comparison is attribute-constant; memoize the verdict)
|
|
@@ -427,7 +427,7 @@ module Lutaml
|
|
|
427
427
|
default = using_default?(name)
|
|
428
428
|
value = self.class.apply_value_map(value, vmap, attr)
|
|
429
429
|
# Performance: Only call ensure_utf8 for string values
|
|
430
|
-
value = self.class.ensure_utf8(value) if
|
|
430
|
+
value = self.class.ensure_utf8(value) if transcode_to_utf8?(value, attr)
|
|
431
431
|
# Interpolating the writer symbol allocated a String per
|
|
432
432
|
# attribute per instance; the per-register writer table is
|
|
433
433
|
# interned once per class.
|
|
@@ -435,6 +435,16 @@ module Lutaml
|
|
|
435
435
|
using_default_for(name) if default
|
|
436
436
|
end
|
|
437
437
|
|
|
438
|
+
# A binary String from a non-text type holds bytes, not text:
|
|
439
|
+
# transcoding it to UTF-8 would silently drop every byte above 0x7F.
|
|
440
|
+
def transcode_to_utf8?(value, attr)
|
|
441
|
+
return false unless value.is_a?(::String)
|
|
442
|
+
return true unless value.encoding == Encoding::BINARY
|
|
443
|
+
|
|
444
|
+
type = attr.type(lutaml_register)
|
|
445
|
+
type.is_a?(Class) && type <= Lutaml::Model::Type::String
|
|
446
|
+
end
|
|
447
|
+
|
|
438
448
|
def determine_value(attrs, name, attr)
|
|
439
449
|
# One hash pass: a sentinel fetch distinguishes absent keys
|
|
440
450
|
# from present-nil values, replacing two key probes plus the
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -379,8 +379,7 @@ module Lutaml
|
|
|
379
379
|
|
|
380
380
|
rows_by_name = {}
|
|
381
381
|
name_keys = ::Hash.new { |h, k| h[k] = [] }
|
|
382
|
-
plan[:rows].each_with_index do |(rule, attr, kind, spelling,
|
|
383
|
-
delegate, type), row_index|
|
|
382
|
+
plan[:rows].each_with_index do |(rule, attr, kind, spelling, delegate, type), row_index|
|
|
384
383
|
next unless rule.name
|
|
385
384
|
|
|
386
385
|
exact = row_exact_uri(rule, attr, kind, type, reg, plan)
|
|
@@ -6,10 +6,10 @@ module Lutaml
|
|
|
6
6
|
module Yamls
|
|
7
7
|
module Adapter
|
|
8
8
|
# YAMLS streams over the yeptris engine (libyeptris C11), using the
|
|
9
|
-
# multi-document stream API at Psych parity (yeptris-ruby#354)
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
9
|
+
# multi-document stream API at Psych parity (yeptris-ruby#354) and,
|
|
10
|
+
# when the engine offers it, the tolerant per-document iterator
|
|
11
|
+
# (yeptris#921): invalid documents skip in place and the valid
|
|
12
|
+
# ones stand — no host-side splitting or re-parsing, ever.
|
|
13
13
|
class YeptrisAdapter < StandardAdapter
|
|
14
14
|
def self.parse(yamls, _options = {})
|
|
15
15
|
parse_with_stream(yamls)
|
|
@@ -22,6 +22,19 @@ module Lutaml
|
|
|
22
22
|
require_engine
|
|
23
23
|
require "yeptris/yaml"
|
|
24
24
|
|
|
25
|
+
results = []
|
|
26
|
+
if ::Yeptris::YAML.respond_to?(:each_document)
|
|
27
|
+
# Tolerant iteration (yeptris#921): the engine frames the
|
|
28
|
+
# documents and reports failures per document; the host
|
|
29
|
+
# never touches the YAML text.
|
|
30
|
+
# rubocop:disable-next Naming/VariableNumber -- upstream schema literal
|
|
31
|
+
::Yeptris::YAML.each_document(yamls, schema: :compat_11) do |doc, error|
|
|
32
|
+
warn "Skipping invalid yaml: #{error.message}" if error
|
|
33
|
+
results << doc unless error || doc.nil?
|
|
34
|
+
end
|
|
35
|
+
return results
|
|
36
|
+
end
|
|
37
|
+
|
|
25
38
|
# rubocop:disable-next Naming/VariableNumber -- upstream schema literal
|
|
26
39
|
results = Yeptris::YAML.load_stream(yamls, schema: :compat_11)
|
|
27
40
|
results.compact
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1115: the yeptris opt-in is consumer-neutral
|
|
6
|
+
# (LUTAML_YAML; FONTIST_YAML stays honored as the legacy spelling), and
|
|
7
|
+
# a bundle containing yeptris without the opt-in sees a one-time
|
|
8
|
+
# warning naming the switch — the gated engine is visible, not silent.
|
|
9
|
+
RSpec.describe "yeptris engine opt-in switch" do
|
|
10
|
+
around do |example|
|
|
11
|
+
old = ENV.to_h.slice("LUTAML_YAML", "FONTIST_YAML")
|
|
12
|
+
ENV.delete("LUTAML_YAML")
|
|
13
|
+
ENV.delete("FONTIST_YAML")
|
|
14
|
+
example.run
|
|
15
|
+
old.each { |k, v| ENV[k] = v }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "selects yeptris with LUTAML_YAML=yeptris" do
|
|
19
|
+
skip "yeptris engine not available on this platform" unless
|
|
20
|
+
Lutaml::Model::AdapterResolver.send(:yeptris_opted_in?)
|
|
21
|
+
|
|
22
|
+
expect(Lutaml::Model::Config.adapter_for(:yaml))
|
|
23
|
+
.to be(Lutaml::Yaml::Adapter::YeptrisAdapter)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "honors the legacy FONTIST_YAML spelling" do
|
|
27
|
+
expect(Lutaml::Model::AdapterResolver.send(:yeptris_opted_in?)).to be(false)
|
|
28
|
+
|
|
29
|
+
ENV["FONTIST_YAML"] = "yeptris"
|
|
30
|
+
expect(Lutaml::Model::AdapterResolver.send(:yeptris_opted_in?)).to be(true)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "selects yeptris with FONTIST_YAML=yeptris" do
|
|
34
|
+
skip "yeptris engine not available on this platform" if
|
|
35
|
+
RUBY_ENGINE == "opal"
|
|
36
|
+
|
|
37
|
+
ENV["FONTIST_YAML"] = "yeptris"
|
|
38
|
+
expect(Lutaml::Model::Config.adapter_for(:yaml)).not_to be_nil
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "Binary String attribute values" do
|
|
6
|
+
let(:bytes_type) do
|
|
7
|
+
Class.new(Lutaml::Model::Type::Value) do
|
|
8
|
+
def self.cast(value, *)
|
|
9
|
+
value.is_a?(String) ? value.b : value
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:model_class) do
|
|
15
|
+
type = bytes_type
|
|
16
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
17
|
+
attribute :data, type
|
|
18
|
+
attribute :text, :string
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
let(:raw) { "\xFF\x00\xC3\x28\x89".b }
|
|
23
|
+
|
|
24
|
+
it "keeps every byte a non-text type returns" do
|
|
25
|
+
expect(model_class.new(data: raw).data.bytes).to eq(raw.bytes)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "still transcodes a binary String given to a :string attribute" do
|
|
29
|
+
text = model_class.new(text: "plain".b).text
|
|
30
|
+
expect([text, text.encoding]).to eq(["plain", Encoding::UTF_8])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
#
|
|
26
26
|
# 3. Register BibTeX format:
|
|
27
27
|
#
|
|
28
|
-
# Lutaml::Model::
|
|
28
|
+
# Lutaml::Model::FormatRegistry.register(
|
|
29
29
|
# :bibtex,
|
|
30
30
|
# mapping_class: BibtexMapping,
|
|
31
|
-
# adapter_class: BibtexAdapter
|
|
31
|
+
# adapter_class: BibtexAdapter,
|
|
32
|
+
# transformer: BibtexTransform
|
|
32
33
|
# )
|
|
33
34
|
#
|
|
34
35
|
# 4. Define BibTeX mappings using the `bibtex do` block:
|
|
@@ -99,10 +99,11 @@
|
|
|
99
99
|
#
|
|
100
100
|
# Register your custom format:
|
|
101
101
|
#
|
|
102
|
-
# Lutaml::Model::
|
|
102
|
+
# Lutaml::Model::FormatRegistry.register(
|
|
103
103
|
# :vobject,
|
|
104
104
|
# mapping_class: YourMapping,
|
|
105
|
-
# adapter_class: YourAdapter
|
|
105
|
+
# adapter_class: YourAdapter,
|
|
106
|
+
# transformer: YourTransform
|
|
106
107
|
# )
|
|
107
108
|
#
|
|
108
109
|
# == Component Types
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1114: a hash-valued entry in a string-collection
|
|
6
|
+
# attribute materialized as a Type::String wrapper holding the JSON
|
|
7
|
+
# text (data loss). Builtin scalars now keep structured data verbatim
|
|
8
|
+
# on parse and emit it verbatim on serialize; custom Value subclasses
|
|
9
|
+
# keep the wrapper/shaping contract.
|
|
10
|
+
module JsonHashCollectionSpec
|
|
11
|
+
class Probe < Lutaml::Model::Serializable
|
|
12
|
+
attribute :name, :string
|
|
13
|
+
attribute :files, :string, collection: true
|
|
14
|
+
|
|
15
|
+
key_value do
|
|
16
|
+
map "name", to: :name
|
|
17
|
+
map "files", to: :files
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
RSpec.describe "hash-valued entries on string collections (#1114)" do
|
|
23
|
+
let(:data) do
|
|
24
|
+
{ "name" => "Roboto", "files" => { "regular" => "Roboto-Regular.ttf" } }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "keeps the hash structure on parse" do
|
|
28
|
+
model = JsonHashCollectionSpec::Probe.from_json(JSON.dump(data))
|
|
29
|
+
expect(model.files).to eq([{ "regular" => "Roboto-Regular.ttf" }])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "round-trips the hash through to_json" do
|
|
33
|
+
model = JsonHashCollectionSpec::Probe.from_json(JSON.dump(data))
|
|
34
|
+
expect(JSON.parse(model.to_json)["files"])
|
|
35
|
+
.to eq([{ "regular" => "Roboto-Regular.ttf" }])
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1122: the per-register flattened-mapping memo (round 7)
|
|
6
|
+
# froze the rule list before a second DSL block (a mixin-installed
|
|
7
|
+
# key_value combined with an in-class one) added its rules — the
|
|
8
|
+
# InternetDraft "version" rule vanished from to_hash. Every DSL and
|
|
9
|
+
# import mutation point now invalidates the memo.
|
|
10
|
+
module KvFlattenMemoSpec
|
|
11
|
+
module Serialization
|
|
12
|
+
def self.included(base)
|
|
13
|
+
base.key_value do
|
|
14
|
+
map "_type", to: :type
|
|
15
|
+
map "number", to: :number
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Draft < Lutaml::Model::Serializable
|
|
21
|
+
include Serialization
|
|
22
|
+
|
|
23
|
+
attribute :type, :string
|
|
24
|
+
attribute :number, :string
|
|
25
|
+
attribute :version, :string
|
|
26
|
+
|
|
27
|
+
key_value do
|
|
28
|
+
map "version", to: :version
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
RSpec.describe "KV flatten memo vs late DSL blocks (#1122)" do
|
|
34
|
+
it "keeps rules added by a later key_value block" do
|
|
35
|
+
model = KvFlattenMemoSpec::Draft.new(
|
|
36
|
+
type: "internet_draft", number: "draft-ietf-quic-transport",
|
|
37
|
+
version: "34"
|
|
38
|
+
)
|
|
39
|
+
h = model.to_hash
|
|
40
|
+
expect(h["version"]).to eq("34")
|
|
41
|
+
expect(h["number"]).to eq("draft-ietf-quic-transport")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "keeps the memo effective for stable rule sets" do
|
|
45
|
+
model = KvFlattenMemoSpec::Draft.new(number: "x", version: "1")
|
|
46
|
+
first = model.to_hash
|
|
47
|
+
expect(model.to_hash).to eq(first)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -99,17 +99,16 @@ RSpec.describe Lutaml::Xml::Leptris::NativeEmission do
|
|
|
99
99
|
</w:document>
|
|
100
100
|
XML
|
|
101
101
|
end
|
|
102
|
-
|
|
103
|
-
around do |example|
|
|
104
|
-
Lutaml::Model::Config.with_adapter(xml: :leptris) { example.run }
|
|
105
|
-
end
|
|
106
|
-
|
|
107
102
|
let(:register) { Lutaml::Model::Config.default_register }
|
|
108
103
|
let(:instance) { doc_class.from_xml(source) }
|
|
109
104
|
let(:plan) do
|
|
110
105
|
Lutaml::Xml::Leptris::PlanCompiler.compile(doc_class, register)
|
|
111
106
|
end
|
|
112
107
|
|
|
108
|
+
around do |example|
|
|
109
|
+
Lutaml::Model::Config.with_adapter(xml: :leptris) { example.run }
|
|
110
|
+
end
|
|
111
|
+
|
|
113
112
|
it "admits parsed ordered instances in the compatibility gate" do
|
|
114
113
|
expect(described_class.compatible?(plan, instance, register)).to be(true)
|
|
115
114
|
end
|
|
@@ -117,15 +116,15 @@ RSpec.describe Lutaml::Xml::Leptris::NativeEmission do
|
|
|
117
116
|
it "emits ordered parsed instances byte-identically to the interpretive writer" do
|
|
118
117
|
_p = plan
|
|
119
118
|
_i = instance
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
Lutaml::Xml::Leptris::PlanCompiler.compile(OrderedNs::Para, register)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
127
126
|
native = described_class.emit(instance, plan, register)
|
|
128
|
-
|
|
127
|
+
|
|
129
128
|
interpretive = Lutaml::Model::Config.with_adapter(xml: :nokogiri) do
|
|
130
129
|
instance.to_xml
|
|
131
130
|
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.165
|
|
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-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -1740,6 +1740,7 @@ files:
|
|
|
1740
1740
|
- spec/lutaml/key_value/when_attribute_spec.rb
|
|
1741
1741
|
- spec/lutaml/model/absent_value_contracts_spec.rb
|
|
1742
1742
|
- spec/lutaml/model/adapter_resolver_configured_spec.rb
|
|
1743
|
+
- spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb
|
|
1743
1744
|
- spec/lutaml/model/any_element_mapping_spec.rb
|
|
1744
1745
|
- spec/lutaml/model/attribute_apply_value_map_spec.rb
|
|
1745
1746
|
- spec/lutaml/model/attribute_collection_spec.rb
|
|
@@ -1748,6 +1749,7 @@ files:
|
|
|
1748
1749
|
- spec/lutaml/model/attribute_restriction_spec.rb
|
|
1749
1750
|
- spec/lutaml/model/attribute_spec.rb
|
|
1750
1751
|
- spec/lutaml/model/attributes_memo_clear_race_spec.rb
|
|
1752
|
+
- spec/lutaml/model/binary_attribute_value_spec.rb
|
|
1751
1753
|
- spec/lutaml/model/boot_manifest_spec.rb
|
|
1752
1754
|
- spec/lutaml/model/cached_type_resolver_spec.rb
|
|
1753
1755
|
- spec/lutaml/model/cardinality_strict_spec.rb
|
|
@@ -1805,6 +1807,7 @@ files:
|
|
|
1805
1807
|
- spec/lutaml/model/inheritance_spec.rb
|
|
1806
1808
|
- spec/lutaml/model/inherited_state_isolation_spec.rb
|
|
1807
1809
|
- spec/lutaml/model/json_adapter_spec.rb
|
|
1810
|
+
- spec/lutaml/model/json_hash_collection_spec.rb
|
|
1808
1811
|
- spec/lutaml/model/json_spec.rb
|
|
1809
1812
|
- spec/lutaml/model/json_state_nesting_spec.rb
|
|
1810
1813
|
- spec/lutaml/model/jsonl/standard_adapter_spec.rb
|
|
@@ -1812,6 +1815,7 @@ files:
|
|
|
1812
1815
|
- spec/lutaml/model/key_value_accepted_values_spec.rb
|
|
1813
1816
|
- spec/lutaml/model/key_value_data_model/key_value_element_spec.rb
|
|
1814
1817
|
- spec/lutaml/model/key_value_mapping_spec.rb
|
|
1818
|
+
- spec/lutaml/model/kv_flatten_memo_spec.rb
|
|
1815
1819
|
- spec/lutaml/model/late_attribute_declaration_spec.rb
|
|
1816
1820
|
- spec/lutaml/model/lazy_collection_spec.rb
|
|
1817
1821
|
- spec/lutaml/model/liquefiable_lazy_spec.rb
|