lutaml-model 0.8.158 → 0.8.160
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/.github/workflows/dependent-tests.yml +6 -4
- data/lib/compat/opal/lutaml_model_boot.rb +5 -0
- data/lib/lutaml/key_value/transformation/value_serializer.rb +21 -0
- data/lib/lutaml/key_value/transformation.rb +57 -6
- data/lib/lutaml/model/collection.rb +9 -1
- data/lib/lutaml/model/collection_handler.rb +9 -13
- data/lib/lutaml/model/lml/document.rb +109 -0
- data/lib/lutaml/model/lml/exporter.rb +328 -0
- data/lib/lutaml/model/lml/rejected_error.rb +32 -0
- data/lib/lutaml/model/lml/round_trip.rb +49 -0
- data/lib/lutaml/model/lml.rb +40 -0
- data/lib/lutaml/model/register.rb +6 -0
- data/lib/lutaml/model/serialize/enum_handling.rb +7 -3
- data/lib/lutaml/model/serialize/value_mapping.rb +6 -0
- data/lib/lutaml/model/transformation_registry.rb +7 -2
- data/lib/lutaml/model/utils.rb +8 -3
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model.rb +1 -0
- data/lib/lutaml/xml/adapter_element.rb +16 -21
- data/lib/lutaml/xml/declaration_planner.rb +63 -3
- data/lib/lutaml/xml/model_transform.rb +5 -0
- data/lib/lutaml/xml/schema/xsd/schema_path.rb +8 -3
- data/spec/lutaml/model/key_value_accepted_values_spec.rb +99 -0
- data/spec/lutaml/model/lml_exporter_spec.rb +150 -0
- data/spec/lutaml/xml/schema/xsd/glob_spec.rb +14 -18
- data/spec/lutaml/xml/schema/xsd/unresolvable_schema_location_spec.rb +58 -0
- metadata +10 -2
|
@@ -1078,7 +1078,27 @@ mapper_class: nil)
|
|
|
1078
1078
|
|
|
1079
1079
|
# Use the OOP decision resolver
|
|
1080
1080
|
@prefix_resolver ||= Decisions::ElementPrefixResolver.new
|
|
1081
|
-
decision
|
|
1081
|
+
# The decision is a pure function of the walk-invariant facts:
|
|
1082
|
+
# static per-model objects (mapping, needs, namespace class),
|
|
1083
|
+
# the element's own spelling, the parent-chain inputs, and the
|
|
1084
|
+
# two projections of the mutating parent_hoisted set that the
|
|
1085
|
+
# rules can see for this element's namespace. Same-shaped
|
|
1086
|
+
# elements repeat by the thousands in real documents, so the
|
|
1087
|
+
# memoized verdict replaces the 12-rule engine execution per
|
|
1088
|
+
# element (lutaml-model#1064). Per-parse memo: the planner is
|
|
1089
|
+
# built once per serialize run, so entries die with the parse.
|
|
1090
|
+
memo_key = [
|
|
1091
|
+
mapping, needs,
|
|
1092
|
+
xml_element.namespace_class, xml_element.name,
|
|
1093
|
+
input_prefix_of(xml_element), element_used_prefix,
|
|
1094
|
+
is_root, parent_format, parent_namespace_class,
|
|
1095
|
+
parent_namespace_prefix,
|
|
1096
|
+
hoisted_facts_for(xml_element, parent_hoisted),
|
|
1097
|
+
options[:use_prefix],
|
|
1098
|
+
options[:input_formats].object_id,
|
|
1099
|
+
options[:stored_xml_declaration_plan].object_id
|
|
1100
|
+
]
|
|
1101
|
+
(@element_prefix_memo ||= {})[memo_key] ||= @prefix_resolver.resolve_with_decision(
|
|
1082
1102
|
xml_element, mapping, needs, options,
|
|
1083
1103
|
is_root: is_root,
|
|
1084
1104
|
parent_format: parent_format,
|
|
@@ -1086,9 +1106,49 @@ mapper_class: nil)
|
|
|
1086
1106
|
parent_namespace_prefix: parent_namespace_prefix,
|
|
1087
1107
|
parent_hoisted: parent_hoisted,
|
|
1088
1108
|
element_used_prefix: element_used_prefix
|
|
1089
|
-
)
|
|
1109
|
+
).prefix
|
|
1110
|
+
end
|
|
1111
|
+
|
|
1112
|
+
# The element's own input prefix, the same lookup
|
|
1113
|
+
# DecisionContext#element_namespace_prefix performs.
|
|
1114
|
+
def input_prefix_of(xml_element)
|
|
1115
|
+
return nil unless xml_element
|
|
1116
|
+
|
|
1117
|
+
if xml_element.is_a?(Lutaml::Xml::XmlElement)
|
|
1118
|
+
xml_element.namespace_prefix
|
|
1119
|
+
else
|
|
1120
|
+
prefix = xml_element.xml_namespace_prefix
|
|
1121
|
+
return prefix if prefix && !prefix.empty?
|
|
1090
1122
|
|
|
1091
|
-
|
|
1123
|
+
original = xml_element.original_xml_element
|
|
1124
|
+
original.is_a?(Lutaml::Xml::XmlElement) ? original.namespace_prefix : nil
|
|
1125
|
+
end
|
|
1126
|
+
end
|
|
1127
|
+
|
|
1128
|
+
# The projections of the walk-mutating parent_hoisted set that the
|
|
1129
|
+
# decision rules read for this element's namespace: the prefix
|
|
1130
|
+
# (if any) this namespace is hoisted under, and whether the
|
|
1131
|
+
# parent's default namespace matches this element's namespace.
|
|
1132
|
+
def hoisted_facts_for(xml_element, parent_hoisted)
|
|
1133
|
+
ns_class = xml_element&.namespace_class
|
|
1134
|
+
uri = ns_class&.uri
|
|
1135
|
+
return [nil, false] unless uri
|
|
1136
|
+
|
|
1137
|
+
all_uris = if ns_class.is_a?(Class) && ns_class < Lutaml::Xml::Namespace
|
|
1138
|
+
ns_class.all_uris
|
|
1139
|
+
else
|
|
1140
|
+
[uri]
|
|
1141
|
+
end
|
|
1142
|
+
|
|
1143
|
+
hoisted_prefix = nil
|
|
1144
|
+
parent_hoisted.each do |prefix, hoisted_uri|
|
|
1145
|
+
if all_uris.include?(hoisted_uri)
|
|
1146
|
+
hoisted_prefix = prefix
|
|
1147
|
+
break
|
|
1148
|
+
end
|
|
1149
|
+
end
|
|
1150
|
+
default_matches = parent_hoisted.key?(nil) && all_uris.include?(parent_hoisted[nil])
|
|
1151
|
+
[hoisted_prefix, default_matches]
|
|
1092
1152
|
end
|
|
1093
1153
|
|
|
1094
1154
|
# Build qualified element name with prefix
|
|
@@ -20,9 +20,14 @@ module Lutaml
|
|
|
20
20
|
# The loop body used to re-derive these per parsed instance.
|
|
21
21
|
# Concurrent::Map under threaded MRI, plain Hash under Opal
|
|
22
22
|
# (Concurrent is unavailable there); class identity keys either.
|
|
23
|
+
# Concurrent is required here (not at boot) so its first load never
|
|
24
|
+
# happens inside RubyGems' unresolved-tree resolution (see
|
|
25
|
+
# TransformationRegistry#initialize).
|
|
23
26
|
RULE_RECORDS = if Lutaml::Model.opal?
|
|
24
27
|
{}
|
|
25
28
|
else
|
|
29
|
+
Lutaml::Model::RuntimeCompatibility
|
|
30
|
+
.require_native("concurrent")
|
|
26
31
|
Concurrent::Map.new # rubocop:disable Lint/HashCompareByIdentity
|
|
27
32
|
end
|
|
28
33
|
|
|
@@ -163,10 +163,15 @@ module Lutaml
|
|
|
163
163
|
|
|
164
164
|
def read_absolute_path(path, original_location, mapped: false)
|
|
165
165
|
unless File.exist?(path)
|
|
166
|
+
# schemaLocation is a hint, not a mandate (XSD 1.0 §4.2.3):
|
|
167
|
+
# an unresolvable include/import/redefine warns and the
|
|
168
|
+
# assembly continues without the referenced components —
|
|
169
|
+
# the W3C suite's expected reading (lutaml-model#1087).
|
|
166
170
|
message = mapped ? "Mapped schema file not found" : "Schema file not found"
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
171
|
+
warn "#{message}: #{path} (original location: #{original_location}); " \
|
|
172
|
+
"treating the schemaLocation hint as unresolvable and assembling " \
|
|
173
|
+
"without the referenced components"
|
|
174
|
+
return nil
|
|
170
175
|
end
|
|
171
176
|
|
|
172
177
|
File.read(path)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1089: the KeyValue serializer raised IncorrectModelError
|
|
6
|
+
# on values the model layer had accepted — raw scalars and hashes
|
|
7
|
+
# stored through the cast chain's pass-through, and Serializable
|
|
8
|
+
# siblings accepted at construction via already-serialized pass-through.
|
|
9
|
+
# The serializer now coerces accepted values to the declared nested
|
|
10
|
+
# type instead of exploding mid-render.
|
|
11
|
+
module KvAcceptedValuesSpec
|
|
12
|
+
class Content < Lutaml::Model::Serializable
|
|
13
|
+
attribute :content, :string
|
|
14
|
+
|
|
15
|
+
xml do
|
|
16
|
+
map_content to: :content
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
key_value do
|
|
20
|
+
map "content", to: :content
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class TypedContent < Content
|
|
25
|
+
attribute :type, :string
|
|
26
|
+
|
|
27
|
+
xml do
|
|
28
|
+
map_attribute "type", to: :type
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
key_value do
|
|
32
|
+
map "type", to: :type
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class Thing < Lutaml::Model::Serializable
|
|
37
|
+
attribute :label, Content
|
|
38
|
+
attribute :names, TypedContent, collection: true
|
|
39
|
+
|
|
40
|
+
key_value do
|
|
41
|
+
map "label", to: :label
|
|
42
|
+
map "names", to: :names
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
RSpec.describe "KeyValue serialization of accepted nested values (#1089)" do
|
|
48
|
+
subject(:thing) { KvAcceptedValuesSpec::Thing.new(label: value, names: names) }
|
|
49
|
+
|
|
50
|
+
context "with a raw scalar the constructor stored" do
|
|
51
|
+
let(:value) { "JTA" }
|
|
52
|
+
let(:names) { [] }
|
|
53
|
+
|
|
54
|
+
it "wraps onto the declared type's content attribute" do
|
|
55
|
+
expect(thing.to_yaml).to include("content: JTA")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "deserializes back to the declared type" do
|
|
59
|
+
parsed = KvAcceptedValuesSpec::Thing.from_yaml(thing.to_yaml)
|
|
60
|
+
expect(parsed.label).to be_a(KvAcceptedValuesSpec::Content)
|
|
61
|
+
expect(parsed.label.content).to eq("JTA")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "with a raw hash the constructor stored" do
|
|
66
|
+
let(:value) { { "content" => "Hash form" } }
|
|
67
|
+
let(:names) { [] }
|
|
68
|
+
|
|
69
|
+
it "constructs the declared type from the hash" do
|
|
70
|
+
expect(thing.to_yaml).to include("content: Hash form")
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context "with a Serializable sibling of the declared type" do
|
|
75
|
+
let(:value) { KvAcceptedValuesSpec::Content.new(content: "X") }
|
|
76
|
+
let(:names) { [KvAcceptedValuesSpec::Content.new(content: "Sibling")] }
|
|
77
|
+
|
|
78
|
+
it "round-trips through the framework hash into the declared type" do
|
|
79
|
+
expect(thing.to_yaml).to include("content: X")
|
|
80
|
+
expect(thing.to_yaml).to include("content: Sibling")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "deserializes as the declared type" do
|
|
84
|
+
parsed = KvAcceptedValuesSpec::Thing.from_yaml(thing.to_yaml)
|
|
85
|
+
expect(parsed.names.first).to be_a(KvAcceptedValuesSpec::TypedContent)
|
|
86
|
+
expect(parsed.names.first.content).to eq("Sibling")
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context "with an already-cast value" do
|
|
91
|
+
let(:value) { KvAcceptedValuesSpec::Content.new(content: "fine") }
|
|
92
|
+
let(:names) { [KvAcceptedValuesSpec::TypedContent.new(content: "t")] }
|
|
93
|
+
|
|
94
|
+
it "serializes unchanged" do
|
|
95
|
+
expect(thing.to_yaml).to include("content: fine")
|
|
96
|
+
expect(thing.to_yaml).to include("content: t")
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/model"
|
|
4
|
+
require "json"
|
|
5
|
+
require "yaml"
|
|
6
|
+
|
|
7
|
+
# lutaml-model#1033 Phase 1: the LML declaration exporter. Ruby model →
|
|
8
|
+
# neutral LML document (attributes + per-format mappings), checksummed
|
|
9
|
+
# over the canonical form, with the round-trip gate pinned from day one.
|
|
10
|
+
# Named fixture classes: the document addresses models by class path,
|
|
11
|
+
# so anonymous classes are unnameable (the exporter rejects them).
|
|
12
|
+
module LmlSpecFixtures # rubocop:disable Lint/ConstantDefinitionInBlock -- named fixtures, see below
|
|
13
|
+
class Dimension < Lutaml::Model::Serializable
|
|
14
|
+
attribute :si_name, :string
|
|
15
|
+
attribute :si_symbol, :string
|
|
16
|
+
|
|
17
|
+
xml do
|
|
18
|
+
root "dimension"
|
|
19
|
+
map_attribute "siName", to: :si_name
|
|
20
|
+
map_element "siSymbol", to: :si_symbol
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Unit < Lutaml::Model::Serializable
|
|
25
|
+
attribute :id, :string
|
|
26
|
+
attribute :quantity_type, :string, values: %w[length mass time]
|
|
27
|
+
attribute :dimensions, Dimension, collection: 0..10
|
|
28
|
+
attribute :symbol, :string, default: "u"
|
|
29
|
+
|
|
30
|
+
xml do
|
|
31
|
+
root "unit"
|
|
32
|
+
map_attribute "id", to: :id
|
|
33
|
+
map_attribute "quantityType", to: :quantity_type
|
|
34
|
+
map_element "dimension", to: :dimensions
|
|
35
|
+
map_element "symbol", to: :symbol
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
json do
|
|
39
|
+
map "id", to: :id
|
|
40
|
+
map "quantityType", to: :quantity_type
|
|
41
|
+
map "dimensions", to: :dimensions
|
|
42
|
+
map "symbol", to: :symbol
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class OrderedMixed < Lutaml::Model::Serializable
|
|
47
|
+
attribute :text, :string
|
|
48
|
+
attribute :other, :string
|
|
49
|
+
|
|
50
|
+
xml do
|
|
51
|
+
root "mixed", ordered: true
|
|
52
|
+
map_element "text", to: :text
|
|
53
|
+
map_element "other", to: :other
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
RSpec.describe Lutaml::Model::Lml do
|
|
59
|
+
let(:unit_class) { LmlSpecFixtures::Unit }
|
|
60
|
+
|
|
61
|
+
def export(klass)
|
|
62
|
+
described_class.export(klass)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "projects attributes with types, collections, defaults and enums" do
|
|
66
|
+
document = export(unit_class)
|
|
67
|
+
dimensions = document.attributes.find { |attr| attr["name"] == "dimensions" }
|
|
68
|
+
symbol = document.attributes.find { |attr| attr["name"] == "symbol" }
|
|
69
|
+
quantity = document.attributes.find { |attr| attr["name"] == "quantity_type" }
|
|
70
|
+
|
|
71
|
+
expect(dimensions).to include(
|
|
72
|
+
"type" => "LmlSpecFixtures::Dimension",
|
|
73
|
+
"collection" => { "min" => 0, "max" => 10 },
|
|
74
|
+
)
|
|
75
|
+
expect(symbol).to include("default" => "u")
|
|
76
|
+
expect(quantity).to include("values" => %w[length mass time])
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "projects per-format mappings, not per-DSL blocks" do
|
|
80
|
+
document = export(unit_class)
|
|
81
|
+
expect(document.mappings.keys).to eq(["xml", "json"])
|
|
82
|
+
|
|
83
|
+
xml = document.mappings["xml"]
|
|
84
|
+
expect(xml["root"]).to include("element" => "unit")
|
|
85
|
+
expect(xml["rules"]).to include(
|
|
86
|
+
{ "kind" => "attribute", "name" => ["id"], "to" => "id" },
|
|
87
|
+
)
|
|
88
|
+
expect(document.mappings["json"]["rules"]).to include(
|
|
89
|
+
{ "key" => ["id"], "to" => "id" },
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "pins a checksum over the canonical form" do
|
|
94
|
+
document = export(unit_class)
|
|
95
|
+
expect(document.checksum).to start_with("sha256:")
|
|
96
|
+
expect(export(unit_class).checksum).to eq(document.checksum)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "is byte-stable across renders and key order" do
|
|
100
|
+
document = export(unit_class)
|
|
101
|
+
expect(document.to_yaml).to include("model:")
|
|
102
|
+
expect(JSON.parse(document.to_json)).to eq(JSON.parse(document.canonical_json))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "round-trips: the document re-derives the model" do
|
|
106
|
+
document = export(unit_class)
|
|
107
|
+
verified = described_class.verify(
|
|
108
|
+
Lutaml::Model::Lml::Document.from_hash(document.to_h),
|
|
109
|
+
)
|
|
110
|
+
expect(verified.checksum).to eq(document.checksum)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "rejects lambda defaults" do
|
|
114
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
115
|
+
attribute :x, :string, default: -> { "d" }
|
|
116
|
+
end
|
|
117
|
+
expect { export(klass) }.to raise_error(
|
|
118
|
+
Lutaml::Model::Lml::RejectedError,
|
|
119
|
+
/lambda_default/,
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "rejects a custom initialize" do
|
|
124
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
125
|
+
attribute :x, :string
|
|
126
|
+
|
|
127
|
+
def initialize(attrs = {})
|
|
128
|
+
super
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
expect { export(klass) }.to raise_error(
|
|
132
|
+
Lutaml::Model::Lml::RejectedError,
|
|
133
|
+
/custom_initialize/,
|
|
134
|
+
)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "rejects ordered content with no declared sequence" do
|
|
138
|
+
expect { export(LmlSpecFixtures::OrderedMixed) }.to raise_error(
|
|
139
|
+
Lutaml::Model::Lml::RejectedError,
|
|
140
|
+
/imperative_element_order/,
|
|
141
|
+
)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "rejects a non-serializable class" do
|
|
145
|
+
expect { export(String) }.to raise_error(
|
|
146
|
+
Lutaml::Model::Lml::RejectedError,
|
|
147
|
+
/not_serializable/,
|
|
148
|
+
)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -278,21 +278,20 @@ RSpec.describe Lutaml::Xml::Schema::Xsd::Glob do
|
|
|
278
278
|
end
|
|
279
279
|
|
|
280
280
|
context "when mapped file does not exist" do
|
|
281
|
-
it "
|
|
281
|
+
it "warns and returns nil for absolute path mapping" do
|
|
282
282
|
nonexistent_path = "/nonexistent/path/to/schema.xsd"
|
|
283
283
|
described_class.schema_mappings = [
|
|
284
284
|
{ from: "http://example.com/schema.xsd", to: nonexistent_path },
|
|
285
285
|
]
|
|
286
286
|
|
|
287
287
|
expect do
|
|
288
|
-
described_class.include_schema("http://example.com/schema.xsd")
|
|
289
|
-
end.to
|
|
290
|
-
Lutaml::Xml::Schema::Xsd::Error,
|
|
288
|
+
expect(described_class.include_schema("http://example.com/schema.xsd")).to be_nil
|
|
289
|
+
end.to output(
|
|
291
290
|
/Mapped schema file not found: #{Regexp.escape(nonexistent_path)}/,
|
|
292
|
-
)
|
|
291
|
+
).to_stderr
|
|
293
292
|
end
|
|
294
293
|
|
|
295
|
-
it "includes original location in
|
|
294
|
+
it "includes original location in the warning" do
|
|
296
295
|
nonexistent_path = "/nonexistent/path/to/schema.xsd"
|
|
297
296
|
described_class.schema_mappings = [
|
|
298
297
|
{ from: "http://example.com/schema.xsd", to: nonexistent_path },
|
|
@@ -300,30 +299,27 @@ RSpec.describe Lutaml::Xml::Schema::Xsd::Glob do
|
|
|
300
299
|
|
|
301
300
|
expect do
|
|
302
301
|
described_class.include_schema("http://example.com/schema.xsd")
|
|
303
|
-
end.to
|
|
304
|
-
Lutaml::Xml::Schema::Xsd::Error,
|
|
302
|
+
end.to output(
|
|
305
303
|
%r{original location: http://example\.com/schema\.xsd},
|
|
306
|
-
)
|
|
304
|
+
).to_stderr
|
|
307
305
|
end
|
|
308
306
|
end
|
|
309
307
|
|
|
310
308
|
context "when schema file does not exist" do
|
|
311
|
-
it "
|
|
309
|
+
it "warns and returns nil" do
|
|
312
310
|
expect do
|
|
313
|
-
described_class.include_schema("nonexistent_schema.xsd")
|
|
314
|
-
end.to
|
|
315
|
-
Lutaml::Xml::Schema::Xsd::Error,
|
|
311
|
+
expect(described_class.include_schema("nonexistent_schema.xsd")).to be_nil
|
|
312
|
+
end.to output(
|
|
316
313
|
/Schema file not found:.*nonexistent_schema\.xsd/,
|
|
317
|
-
)
|
|
314
|
+
).to_stderr
|
|
318
315
|
end
|
|
319
316
|
|
|
320
|
-
it "includes original location in
|
|
317
|
+
it "includes original location in the warning" do
|
|
321
318
|
expect do
|
|
322
319
|
described_class.include_schema("../../missing/schema.xsd")
|
|
323
|
-
end.to
|
|
324
|
-
Lutaml::Xml::Schema::Xsd::Error,
|
|
320
|
+
end.to output(
|
|
325
321
|
%r{original location:.*missing/schema\.xsd},
|
|
326
|
-
)
|
|
322
|
+
).to_stderr
|
|
327
323
|
end
|
|
328
324
|
end
|
|
329
325
|
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../../spec_helper"
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
require "lutaml/xml/schema/xsd"
|
|
6
|
+
|
|
7
|
+
# lutaml-model#1087: schemaLocation on xs:include / xs:import /
|
|
8
|
+
# xs:redefine is a hint (XSD 1.0 §4.2.3). An unresolvable hint warns
|
|
9
|
+
# and the assembly continues without the referenced components — the
|
|
10
|
+
# W3C suite's expected reading (msData anyURI_a001 et al.) — instead
|
|
11
|
+
# of raising Schema file not found.
|
|
12
|
+
RSpec.describe "Xsd unresolvable schemaLocation hints" do
|
|
13
|
+
let(:xsd) do
|
|
14
|
+
<<~XSD
|
|
15
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
|
16
|
+
<xsd:include schemaLocation="0"/>
|
|
17
|
+
<xsd:import schemaLocation="123" namespace="2"/>
|
|
18
|
+
<xsd:redefine schemaLocation="123"/>
|
|
19
|
+
</xsd:schema>
|
|
20
|
+
XSD
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "warns for each unresolvable hint and still parses" do
|
|
24
|
+
doc = nil
|
|
25
|
+
Dir.mktmpdir do |dir|
|
|
26
|
+
expect do
|
|
27
|
+
doc = Lutaml::Xml::Schema::Xsd.parse(xsd, location: dir)
|
|
28
|
+
end.to output(/Schema file not found/).to_stderr
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
expect(doc.includes.first.schema_path).to eq("0")
|
|
32
|
+
expect(doc.imports.first.schema_path).to eq("123")
|
|
33
|
+
expect(doc.redefine.first.schema_path).to eq("123")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "warns for the unresolvable include" do
|
|
37
|
+
expect do
|
|
38
|
+
parse_with_warnings
|
|
39
|
+
end.to output(%r{original location: 0\)}).to_stderr
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "warns for the unresolvable import" do
|
|
43
|
+
# xs:redefine's schemaLocation resolves through the composition
|
|
44
|
+
# route (schema_path_without_base), not at parse time — the
|
|
45
|
+
# parse-time fetches are the include and the import.
|
|
46
|
+
expect do
|
|
47
|
+
parse_with_warnings
|
|
48
|
+
end.to output(%r{original location: 123\)}).to_stderr
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def parse_with_warnings
|
|
54
|
+
Dir.mktmpdir do |dir|
|
|
55
|
+
Lutaml::Xml::Schema::Xsd.parse(xsd, location: dir)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
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.160
|
|
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-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -531,6 +531,11 @@ files:
|
|
|
531
531
|
- lib/lutaml/model/liquid.rb
|
|
532
532
|
- lib/lutaml/model/liquid/indexed_access.rb
|
|
533
533
|
- lib/lutaml/model/liquid/mapping.rb
|
|
534
|
+
- lib/lutaml/model/lml.rb
|
|
535
|
+
- lib/lutaml/model/lml/document.rb
|
|
536
|
+
- lib/lutaml/model/lml/exporter.rb
|
|
537
|
+
- lib/lutaml/model/lml/rejected_error.rb
|
|
538
|
+
- lib/lutaml/model/lml/round_trip.rb
|
|
534
539
|
- lib/lutaml/model/mapping/listener.rb
|
|
535
540
|
- lib/lutaml/model/mapping/mapping.rb
|
|
536
541
|
- lib/lutaml/model/mapping/mapping_rule.rb
|
|
@@ -1801,6 +1806,7 @@ files:
|
|
|
1801
1806
|
- spec/lutaml/model/json_state_nesting_spec.rb
|
|
1802
1807
|
- spec/lutaml/model/jsonl/standard_adapter_spec.rb
|
|
1803
1808
|
- spec/lutaml/model/jsonl_spec.rb
|
|
1809
|
+
- spec/lutaml/model/key_value_accepted_values_spec.rb
|
|
1804
1810
|
- spec/lutaml/model/key_value_data_model/key_value_element_spec.rb
|
|
1805
1811
|
- spec/lutaml/model/key_value_mapping_spec.rb
|
|
1806
1812
|
- spec/lutaml/model/late_attribute_declaration_spec.rb
|
|
@@ -1809,6 +1815,7 @@ files:
|
|
|
1809
1815
|
- spec/lutaml/model/liquefiable_spec.rb
|
|
1810
1816
|
- spec/lutaml/model/liquid/indexed_access_spec.rb
|
|
1811
1817
|
- spec/lutaml/model/liquid_compatibility_spec.rb
|
|
1818
|
+
- spec/lutaml/model/lml_exporter_spec.rb
|
|
1812
1819
|
- spec/lutaml/model/logger_spec.rb
|
|
1813
1820
|
- spec/lutaml/model/map_all_attributes_spec.rb
|
|
1814
1821
|
- spec/lutaml/model/map_all_spec.rb
|
|
@@ -2084,6 +2091,7 @@ files:
|
|
|
2084
2091
|
- spec/lutaml/xml/schema/xsd/schema_mapping_spec.rb
|
|
2085
2092
|
- spec/lutaml/xml/schema/xsd/schema_validator_spec.rb
|
|
2086
2093
|
- spec/lutaml/xml/schema/xsd/spec_helper.rb
|
|
2094
|
+
- spec/lutaml/xml/schema/xsd/unresolvable_schema_location_spec.rb
|
|
2087
2095
|
- spec/lutaml/xml/schema/xsd/validation_error_spec.rb
|
|
2088
2096
|
- spec/lutaml/xml/schema/xsd/validation_result_spec.rb
|
|
2089
2097
|
- spec/lutaml/xml/schema/xsd/xsd_spec.rb
|