lutaml-model 0.8.188 → 0.8.190
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/adapter/hash/standard_adapter.rb +12 -0
- data/lib/lutaml/model/attribute.rb +72 -0
- data/lib/lutaml/model/services/rule_value_extractor.rb +19 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/leptris/native_emission.rb +25 -3
- data/lutaml-model.gemspec +6 -1
- data/spec/lutaml/model/from_json_scalar_cast_spec.rb +40 -12
- data/spec/lutaml/xml/text_content_verbatim_spec.rb +51 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4bf537581002dd396b97a11220752f0600bb80a58dc343320b8394385a1f265
|
|
4
|
+
data.tar.gz: 12623cab236b0591a57cdb37a4f76fdab54e3c3758f207ffb348076b6882cd6a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: deb150dd1560a00f96c4de1818344360705bf1e6528fdaa950a022e1d47ca8efdd294b06af707843d672b8b91bc984f59917e25c9346b1ff8054aa1206477732
|
|
7
|
+
data.tar.gz: 4bfe54a99e7d0fbd34368328ee991a570bd6a7bde3657bf2ddc143b7cde6b0e2d5f59babd4c5667e0aa2bff77f02bac411516cde1f81edecbb31b5169a447c55
|
|
@@ -6,6 +6,18 @@ module Lutaml
|
|
|
6
6
|
module Hash
|
|
7
7
|
class StandardAdapter < Document
|
|
8
8
|
def self.parse(hsh, _options = {})
|
|
9
|
+
# from_hash's root contract: the document IS a hash. A
|
|
10
|
+
# non-hash previously crashed deep in the value extractor
|
|
11
|
+
# (a NoMethodError wrapped as InvalidFormatError); the
|
|
12
|
+
# #1228 guard made that path reachable by scalar values for
|
|
13
|
+
# mapped complex attributes, so the root validation lives
|
|
14
|
+
# here where it belongs.
|
|
15
|
+
unless hsh.respond_to?(:key?)
|
|
16
|
+
raise Lutaml::Model::InvalidFormatError.new(
|
|
17
|
+
:hash, "the document is not a Hash (got #{hsh.class})"
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
9
21
|
hsh
|
|
10
22
|
end
|
|
11
23
|
|
|
@@ -643,6 +643,18 @@ module Lutaml
|
|
|
643
643
|
return resolved_type.new(value)
|
|
644
644
|
end
|
|
645
645
|
|
|
646
|
+
# A plain scalar for a mapped complex attribute coerces onto the
|
|
647
|
+
# type's `content` mapping — the 0.8.x contract (#1228:
|
|
648
|
+
# `title: "Coll"` builds the localized-title with content
|
|
649
|
+
# "Coll"). On the derived/inline path a type mapping no content
|
|
650
|
+
# keeps the legacy verbatim behavior (the deserialization
|
|
651
|
+
# boundary raises instead — see cast_present).
|
|
652
|
+
if value.is_a?(::String) && !hash_type? &&
|
|
653
|
+
resolved_type.include?(Lutaml::Model::Serialize)
|
|
654
|
+
content_attr = scalar_content_attribute_for(resolved_type)
|
|
655
|
+
return resolved_type.new(content_attr => value) if content_attr
|
|
656
|
+
end
|
|
657
|
+
|
|
646
658
|
# Special handling for Reference types - pass the metadata
|
|
647
659
|
# (the comparison is attribute-constant; memoize the verdict)
|
|
648
660
|
if reference_type?
|
|
@@ -665,6 +677,40 @@ module Lutaml
|
|
|
665
677
|
type == Lutaml::Model::Type::Hash
|
|
666
678
|
end
|
|
667
679
|
|
|
680
|
+
# The attribute a plain scalar coerces onto for a Serializable
|
|
681
|
+
# type (#1228): the whole-value `map to: :content` form (a
|
|
682
|
+
# content/root mapping whose sole target is a scalar attribute)
|
|
683
|
+
# or the keyed rule named "content".
|
|
684
|
+
def scalar_content_attribute_for(resolved_type)
|
|
685
|
+
%i[key_value yaml json hash].each do |format|
|
|
686
|
+
mapping = begin
|
|
687
|
+
resolved_type.mappings_for(format)
|
|
688
|
+
rescue StandardError
|
|
689
|
+
nil
|
|
690
|
+
end
|
|
691
|
+
next unless mapping
|
|
692
|
+
|
|
693
|
+
# Whole-value form: `map to: :content` (no wire key) — the
|
|
694
|
+
# collection-item coercion contract.
|
|
695
|
+
whole = Array(mapping.mappings).find do |rule|
|
|
696
|
+
rule.name.nil? && rule.to && !rule.delegate
|
|
697
|
+
end
|
|
698
|
+
if whole
|
|
699
|
+
target_attr = resolved_type.attributes[whole.to]
|
|
700
|
+
return whole.to if target_attr && !target_attr.collection?
|
|
701
|
+
end
|
|
702
|
+
|
|
703
|
+
# Keyed form: the rule named "content".
|
|
704
|
+
Array(mapping.mappings).each do |rule|
|
|
705
|
+
next unless rule.name == "content"
|
|
706
|
+
|
|
707
|
+
target_attr = resolved_type.attributes[rule.to]
|
|
708
|
+
return rule.to if target_attr && !target_attr.collection?
|
|
709
|
+
end
|
|
710
|
+
end
|
|
711
|
+
nil
|
|
712
|
+
end
|
|
713
|
+
|
|
668
714
|
def setter
|
|
669
715
|
:"#{@name}="
|
|
670
716
|
end
|
|
@@ -1097,6 +1143,32 @@ instance_object = nil)
|
|
|
1097
1143
|
"not build one (received #{casted.class})"
|
|
1098
1144
|
end
|
|
1099
1145
|
|
|
1146
|
+
# The 0.8.x scalar-coercion contract (#1228): a plain string for
|
|
1147
|
+
# a mapped-model attribute whose type does not own a scalar
|
|
1148
|
+
# .cast coerces onto the type's `content` mapping (title:
|
|
1149
|
+
# "Coll" builds the localized title with content "Coll"). A
|
|
1150
|
+
# type mapping no scalar `content` cannot host the scalar —
|
|
1151
|
+
# that is a junk document and raises (the group-walk junk-item
|
|
1152
|
+
# contract).
|
|
1153
|
+
if serializable_type?(register) && value.is_a?(::String) &&
|
|
1154
|
+
!(klass.respond_to?(:cast) &&
|
|
1155
|
+
klass.method(:cast).owner == klass.singleton_class)
|
|
1156
|
+
content_attr = scalar_content_attribute_for(klass)
|
|
1157
|
+
unless content_attr
|
|
1158
|
+
raise Lutaml::Model::InvalidFormatError.new(
|
|
1159
|
+
format,
|
|
1160
|
+
"scalar value for '#{name}' whose type #{klass.name} " \
|
|
1161
|
+
"maps no `content` attribute",
|
|
1162
|
+
)
|
|
1163
|
+
end
|
|
1164
|
+
|
|
1165
|
+
propagated = Serialize::DeserializationContext.propagate(options)
|
|
1166
|
+
return klass.apply_mappings(
|
|
1167
|
+
{ content_attr => value }, format,
|
|
1168
|
+
propagated.merge(register: register)
|
|
1169
|
+
)
|
|
1170
|
+
end
|
|
1171
|
+
|
|
1100
1172
|
if can_serialize?(klass, value, format, options)
|
|
1101
1173
|
propagated = Serialize::DeserializationContext.propagate(options)
|
|
1102
1174
|
klass.apply_mappings(value, format,
|
|
@@ -49,7 +49,25 @@ instance_object, name)
|
|
|
49
49
|
|
|
50
50
|
return doc if name.nil? || rule.root_mapping?
|
|
51
51
|
return convert_to_format(doc, format) if rule.raw_mapping?
|
|
52
|
-
|
|
52
|
+
# The hash-key probe runs only on hash-like values (#1228): a
|
|
53
|
+
# plain string for a mapped complex attribute flows through to
|
|
54
|
+
# the type's own cast, it never keys a probe.
|
|
55
|
+
if doc.respond_to?(:key?) && Utils.string_or_symbol_key?(doc, name)
|
|
56
|
+
return Utils.fetch_str_or_sym(doc, name)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# A scalar document for a complex-typed attribute rides to the
|
|
60
|
+
# cast, which coerces it onto the type's content mapping
|
|
61
|
+
# (#1228) — the default-value path would drop it.
|
|
62
|
+
if attr && !doc.is_a?(::Hash)
|
|
63
|
+
resolved = begin
|
|
64
|
+
attr.type(register)
|
|
65
|
+
rescue StandardError
|
|
66
|
+
nil
|
|
67
|
+
end
|
|
68
|
+
return doc if resolved.is_a?(Class) &&
|
|
69
|
+
resolved.include?(Lutaml::Model::Serialize)
|
|
70
|
+
end
|
|
53
71
|
|
|
54
72
|
if attr
|
|
55
73
|
resolved = attr.default_value(register, instance_object)
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -377,9 +377,31 @@ module Lutaml
|
|
|
377
377
|
else
|
|
378
378
|
plan[:descriptor]
|
|
379
379
|
end
|
|
380
|
-
compact =
|
|
381
|
-
|
|
382
|
-
|
|
380
|
+
compact = nil
|
|
381
|
+
begin
|
|
382
|
+
compact = d.serialize(d.build_result(buf[base, len - base]))
|
|
383
|
+
rescue ::Leptris::XML::Error => e
|
|
384
|
+
# The engine rejected the ops stream (status=-5: an
|
|
385
|
+
# ops plan_index the descriptor's row scoping refuses —
|
|
386
|
+
# the theme/styles class, leptris#1966; the deep
|
|
387
|
+
# ieee-idams shapes are the #1243 repro). The abort
|
|
388
|
+
# message already carries the shape (op count, plan
|
|
389
|
+
# count, max plan_index). Surface the fallback and
|
|
390
|
+
# bail to the DOM lane, whose output is byte-identical;
|
|
391
|
+
# correctness first, the ops/descriptor numbering for
|
|
392
|
+
# these shapes is engine-side work with the repro
|
|
393
|
+
# attached.
|
|
394
|
+
warn "[Lutaml::Model] leptris native emission aborted " \
|
|
395
|
+
"on #{instance.class.name}; falling back to the " \
|
|
396
|
+
"DOM lane (#{e.message})"
|
|
397
|
+
raise if ENV["LUTAML_NATIVE_EMISSION_STRICT"]
|
|
398
|
+
|
|
399
|
+
len = base
|
|
400
|
+
end
|
|
401
|
+
if compact
|
|
402
|
+
result = ::Leptris::XML.parse(compact).to_xml(indent: 2,
|
|
403
|
+
no_decl: true)
|
|
404
|
+
end
|
|
383
405
|
end
|
|
384
406
|
ensure
|
|
385
407
|
buf.slice!(len..) if buf.size > len
|
data/lutaml-model.gemspec
CHANGED
|
@@ -50,7 +50,12 @@ Gem::Specification.new do |spec|
|
|
|
50
50
|
# workspace-local 0.5.x pin is retired with this floor — it cannot
|
|
51
51
|
# resolve against it — and the boot's lib/compat/opal append is
|
|
52
52
|
# directory-guarded in the Rakefile for both lines.
|
|
53
|
-
|
|
53
|
+
# 0.6.23: preprocess_entities stopped rewriting the declared
|
|
54
|
+
# encoding of text payloads beginning with an XML declaration
|
|
55
|
+
# (lutaml/moxml#604) — the text-emission verbatim contract
|
|
56
|
+
# (lutaml-model#1249, rfc8794's embedded-XML sourcecode). The floor
|
|
57
|
+
# is the fix version.
|
|
58
|
+
spec.add_dependency "moxml", "~> 0.6.23"
|
|
54
59
|
spec.add_dependency "ostruct"
|
|
55
60
|
# LML grammar machinery (subsumed language core)
|
|
56
61
|
spec.add_dependency "parsanol", "~> 1.5.0"
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
require "spec_helper"
|
|
4
4
|
|
|
5
|
-
# #978: a JSON scalar handed to a mapped-model
|
|
6
|
-
# an internal NoMethodError (key? on String)
|
|
7
|
-
# InvalidFormatError. A type that declares its own .cast
|
|
8
|
-
# construction from that scalar; a cast-less type
|
|
9
|
-
#
|
|
10
|
-
#
|
|
5
|
+
# lutaml-model#978 + #1228: a JSON scalar handed to a mapped-model
|
|
6
|
+
# attribute crashed with an internal NoMethodError (key? on String)
|
|
7
|
+
# wrapped as InvalidFormatError. A type that declares its own .cast
|
|
8
|
+
# owns scalar construction from that scalar; a cast-less type with a
|
|
9
|
+
# scalar `content` rule coerces onto it (#1228); a type without one
|
|
10
|
+
# keeps the format parse error — or declares .cast to own it.
|
|
11
11
|
RSpec.describe "from_json scalar into a mapped-model attribute" do
|
|
12
12
|
let(:marked_class) do
|
|
13
13
|
Class.new(Lutaml::Model::Serializable) do
|
|
@@ -60,11 +60,39 @@ RSpec.describe "from_json scalar into a mapped-model attribute" do
|
|
|
60
60
|
expect(model.description.content).to eq("text")
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
# #1228 reconciled with #978: a cast-LESS type whose key_value
|
|
64
|
+
# mapping carries a scalar `content` rule coerces the scalar onto
|
|
65
|
+
# that rule (title: "text" builds the model with content "text") —
|
|
66
|
+
# the 0.8.x contract Relaton's localized titles ride. The .cast
|
|
67
|
+
# ownership contract above still takes precedence for types that
|
|
68
|
+
# declare their own scalar construction.
|
|
69
|
+
it "coerces the scalar onto the content mapping for a cast-less mapped type" do
|
|
70
|
+
model = ScalarHolder.from_json('{"plain_desc": "text"}')
|
|
71
|
+
|
|
72
|
+
expect(model.plain_desc).to be_a(ScalarPlain)
|
|
73
|
+
expect(model.plain_desc.content).to eq("text")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "raises the format error for a scalar on a mapped type without a content rule" do
|
|
77
|
+
shape_class = Class.new(Lutaml::Model::Serializable) do
|
|
78
|
+
attribute :label, :string
|
|
79
|
+
|
|
80
|
+
key_value do
|
|
81
|
+
map "label", to: :label
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
stub_const("ScalarShapeless", shape_class)
|
|
85
|
+
|
|
86
|
+
holder = Class.new(Lutaml::Model::Serializable) do
|
|
87
|
+
attribute :shape, "ScalarShapeless"
|
|
88
|
+
|
|
89
|
+
key_value do
|
|
90
|
+
map "shape", to: :shape
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
stub_const("ScalarShapelessHolder", holder)
|
|
94
|
+
|
|
95
|
+
expect { ScalarShapelessHolder.from_json('{"shape": "text"}') }
|
|
96
|
+
.to raise_error(Lutaml::Model::InvalidFormatError, /maps no `content`/)
|
|
69
97
|
end
|
|
70
98
|
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1249: text content emission must pass verbatim payloads
|
|
6
|
+
# through — a value that begins with an embedded XML declaration keeps
|
|
7
|
+
# its original declaration spelling (rfc8794's <sourcecode> carries an
|
|
8
|
+
# escaped XML example). moxml 0.6.23 fixed preprocess_entities to skip
|
|
9
|
+
# the declared-encoding rewrite outside document-parse entry
|
|
10
|
+
# (lutaml/moxml#604); the gemspec floors moxml at that version.
|
|
11
|
+
RSpec.describe "verbatim text content emission (#1249)" do
|
|
12
|
+
let(:embedded_declaration) do
|
|
13
|
+
%(<?xml version="1.0" encoding="utf-8"?>\n<EBMLSchema xmlns="urn:ietf:rfc:8794" version="1">\n</EBMLSchema>)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:model_class) do
|
|
17
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
18
|
+
attribute :content, :string, collection: true
|
|
19
|
+
|
|
20
|
+
xml do
|
|
21
|
+
element "sourcecode"
|
|
22
|
+
mixed_content
|
|
23
|
+
map_content to: :content
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "keeps the declared encoding of an embedded declaration verbatim" do
|
|
29
|
+
instance = model_class.new(content: [embedded_declaration])
|
|
30
|
+
output = instance.to_xml
|
|
31
|
+
|
|
32
|
+
aggregate_failures do
|
|
33
|
+
expect(output).to include('encoding="utf-8"')
|
|
34
|
+
expect(output).not_to include('encoding="UTF-8"')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "round-trips the payload through parse and serialize unchanged" do
|
|
39
|
+
source = <<~XML
|
|
40
|
+
<sourcecode>#{embedded_declaration.gsub('<', '<').gsub('>', '>')}</sourcecode>
|
|
41
|
+
XML
|
|
42
|
+
|
|
43
|
+
parsed = model_class.from_xml(source)
|
|
44
|
+
output = parsed.to_xml
|
|
45
|
+
|
|
46
|
+
aggregate_failures do
|
|
47
|
+
expect(parsed.content.first).to eq(embedded_declaration)
|
|
48
|
+
expect(output).to include('encoding="utf-8"')
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
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.190
|
|
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-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -92,14 +92,14 @@ dependencies:
|
|
|
92
92
|
requirements:
|
|
93
93
|
- - "~>"
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
|
-
version: 0.6.
|
|
95
|
+
version: 0.6.23
|
|
96
96
|
type: :runtime
|
|
97
97
|
prerelease: false
|
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
|
99
99
|
requirements:
|
|
100
100
|
- - "~>"
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
|
-
version: 0.6.
|
|
102
|
+
version: 0.6.23
|
|
103
103
|
- !ruby/object:Gem::Dependency
|
|
104
104
|
name: ostruct
|
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -2423,6 +2423,7 @@ files:
|
|
|
2423
2423
|
- spec/lutaml/xml/schema_primer_spec.rb
|
|
2424
2424
|
- spec/lutaml/xml/serializable_namespace_spec.rb
|
|
2425
2425
|
- spec/lutaml/xml/shared_element_rules_spec.rb
|
|
2426
|
+
- spec/lutaml/xml/text_content_verbatim_spec.rb
|
|
2426
2427
|
- spec/lutaml/xml/transformation/custom_method_wrapper_spec.rb
|
|
2427
2428
|
- spec/lutaml/xml/transformation_spec.rb
|
|
2428
2429
|
- spec/lutaml/xml/type_namespace/collector_spec.rb
|