lutaml-model 0.8.199 → 0.8.201

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.
@@ -56,31 +56,72 @@ module Lutaml
56
56
  Glob.include_schema(schema_path) if schema_path && Glob.location?
57
57
  end
58
58
 
59
- # XSD 1.1 §4.2.4: the referenced document's components are
60
- # replaced by this override's same-named children. Matching is
61
- # by component kind and name; a child with no counterpart adds
62
- # to the referenced document (lenient); children without a name
63
- # (ref-form, anonymous) carry no replacement. Applied on a copy
64
- # of the referenced schema so the override stays local to the
65
- # referencing document.
66
- def apply_to!(target_schema)
67
- COMPONENT_KINDS.each do |kind, name_attr|
68
- Array(public_send(kind)).each do |replacement|
69
- name = replacement.public_send(name_attr)
70
- next if name.nil?
59
+ # The composed view of the referenced document (XSD 1.1 §4.2.4):
60
+ # a new schema whose component collections carry each same-named
61
+ # component replaced by this override's child and the rest of
62
+ # the children appended. Matching is by component kind and
63
+ # name; a child with no counterpart adds to the view (lenient);
64
+ # children without a name (ref-form, anonymous) carry no
65
+ # replacement. The referenced document and its components are
66
+ # shared by reference and never mutated, so every document
67
+ # overriding the same target composes against the same
68
+ # originals.
69
+ def composed
70
+ @composed
71
+ end
72
+
73
+ # Composes (once) against the referenced document; the entry is
74
+ # shared by every viewer, so a chase coming back to it finds the
75
+ # view already composed (#1299).
76
+ def compose(referenced)
77
+ return @composed if @composed
78
+
79
+ view = Schema.new(**view_attributes(referenced))
80
+ view.element_order = referenced.element_order
81
+ @composed = view
82
+ end
83
+
84
+ # Root the composed view as its own schema root, as the parsed
85
+ # document it views is.
86
+ def assign_root!(root = self, seen = nil)
87
+ seen ||= {}.compare_by_identity
88
+ super
89
+ composed&.assign_root!(composed, seen)
90
+ self
91
+ end
71
92
 
72
- components = target_schema.public_send(kind)
73
- index = components.index do |component|
74
- component.public_send(name_attr) == name
75
- end
76
- if index
77
- components[index] = replacement
78
- else
79
- components << replacement
80
- end
93
+ private
94
+
95
+ def view_attributes(referenced)
96
+ Schema.attributes.each_with_object({}) do |(name, _attribute), values|
97
+ value = referenced.public_send(name)
98
+ values[name] = if COMPONENT_KINDS.key?(name)
99
+ substitute_components(name, value)
100
+ elsif value.is_a?(Array)
101
+ value.dup
102
+ else
103
+ value
104
+ end
105
+ end
106
+ end
107
+
108
+ def substitute_components(kind, components)
109
+ name_attr = COMPONENT_KINDS[kind]
110
+ substituted = Array(components).dup
111
+ Array(public_send(kind)).each do |replacement|
112
+ name = replacement.public_send(name_attr)
113
+ next if name.nil?
114
+
115
+ index = substituted.index do |component|
116
+ component.public_send(name_attr) == name
117
+ end
118
+ if index
119
+ substituted[index] = replacement
120
+ else
121
+ substituted << replacement
81
122
  end
82
123
  end
83
- target_schema
124
+ substituted
84
125
  end
85
126
 
86
127
  Lutaml::Xml::Schema::Xsd.register_model(self, :override)
@@ -294,24 +294,31 @@ module Lutaml
294
294
  alias attributes attribute
295
295
  alias groups group
296
296
 
297
+ # XSD 1.1 §4.2.4 assembly: every override entry composes the
298
+ # view of its referenced document once. The entry is shared by
299
+ # reference with every viewer, so the view is too, and a chase
300
+ # that comes back to a location on its own chain finds the
301
+ # entry still uncomposed and leaves it so (as for a cyclic
302
+ # include) instead of chasing its own assembly forever
303
+ # (#1299). Runs after the tree is parsed (the override's
304
+ # children are populated), before root assignment.
297
305
  def apply_overrides!(seen = nil)
298
306
  seen ||= {}.compare_by_identity
299
307
  return self if seen[self]
300
308
 
301
309
  seen[self] = true
302
310
  Array(override).each do |entry|
303
- next unless entry.is_a?(Override) && entry.schema_path
304
- next if self.class.in_progress?(entry.schema_path)
311
+ next unless entry.is_a?(Override)
305
312
 
306
- self.class.add_in_progress(entry.schema_path)
307
- referenced = insert_in_processed_schemas(entry)
308
- self.class.remove_in_progress(entry.schema_path)
309
- next unless referenced
313
+ path = entry.schema_path
314
+ next unless path
315
+ next if entry.composed || self.class.in_progress?(path)
310
316
 
311
- applied = Lutaml::Model::Utils.deep_dup(referenced)
312
- entry.apply_to!(applied)
313
- override(applied)
314
- applied.apply_overrides!(seen)
317
+ self.class.add_in_progress(path)
318
+ referenced = insert_in_processed_schemas(entry)
319
+ entry.compose(referenced) if referenced
320
+ ensure
321
+ self.class.remove_in_progress(path)
315
322
  end
316
323
  %i[include import].each do |kind|
317
324
  Array(public_send(kind)).each do |nested|
@@ -338,15 +345,10 @@ module Lutaml
338
345
  namespaces.uniq
339
346
  end
340
347
 
341
- # XSD 1.1 s4.2.4 override application (the assembly pass): each
342
- # override resolves its referenced document through the same
343
- # location machinery includes use, replaces the same-named
344
- # components on a COPY (the processed-schemas memo shares
345
- # originals across references; an override is local to this
346
- # reference), and appends the applied document to the override
347
- # collection so the schema walk reaches it in place of the raw
348
- # document. Runs after the tree is parsed (the override's
349
- # children are populated), before root assignment.
348
+ # An xs:include / xs:import declaration resolves its document
349
+ # through the location machinery; a location already on the
350
+ # chain is not chased again (cyclic references compose as
351
+ # multiple inclusions of the same document).
350
352
  def setup_import_and_include(klass, model, schema, args = {})
351
353
  instance = init_instance_of(klass, schema.attributes || {}, args)
352
354
  annotation_object(instance, schema)
@@ -424,6 +426,7 @@ module Lutaml
424
426
  class << self
425
427
  def reset_processed_schemas
426
428
  @processed_schemas = {}
429
+ @in_progress = []
427
430
  end
428
431
 
429
432
  def processed_schemas
@@ -7,15 +7,18 @@ require "lutaml/lml"
7
7
 
8
8
  RSpec.configure do |config|
9
9
  config.define_derived_metadata(file_path: %r{elk_layout_spec}) do |metadata|
10
-
11
- metadata[:skip] = "elkrb gem not available" unless (require "elkrb"
12
- true)
13
- rescue StandardError
14
- false
15
-
10
+ metadata[:skip] = "elkrb gem not available" unless elkrb_available?
16
11
  end
17
12
  end
18
13
 
14
+ # elkrb is an optional layout engine; its absence skips the layout specs.
15
+ def elkrb_available?
16
+ require "elkrb"
17
+ true
18
+ rescue LoadError
19
+ false
20
+ end
21
+
19
22
  def fixtures_path(path)
20
23
  File.join(File.expand_path("fixtures", __dir__), path)
21
24
  end
@@ -223,20 +223,22 @@ RSpec.describe "KV group-then-bulk hydration" do
223
223
  expect(ranged.from_hash("tags" => %w[a b]).tags).to eq(%w[a b])
224
224
  end
225
225
 
226
- it "rejects self-referential models (cycle)" do
226
+ it "compiles self-referential models as a plan referencing itself (#1297)" do
227
227
  node = Class.new(Lutaml::Model::Serializable) do
228
228
  attribute :name, :string
229
229
  json { map "name", to: :name }
230
230
  end
231
231
  node.attribute :child, node
232
- node.json do
232
+ node.json do
233
233
  map "name", to: :name
234
234
  map "child", to: :child
235
235
  end
236
236
  stub_const("KvGroup::Node", node)
237
237
 
238
- expect(Lutaml::KeyValue::Transform.kv_group_plan(node, :json,
239
- :default)).to be(false)
238
+ plan = Lutaml::KeyValue::Transform.kv_group_plan(node, :json, :default)
239
+ expect(plan).to be_an(Array)
240
+ child_row = plan.find { |row| row[0].to == :child }
241
+ expect(child_row[4]).to equal(plan)
240
242
  parsed = node.from_hash("name" => "n", "child" => { "name" => "c" })
241
243
  expect(parsed.child.name).to eq("c")
242
244
  end
@@ -284,7 +286,7 @@ RSpec.describe "KV group-then-bulk hydration" do
284
286
  expect(verdicts.uniq.length).to eq(1)
285
287
  end
286
288
 
287
- it "keeps the cycle verdict per-build across threads" do
289
+ it "builds self-referential plans per thread, each referencing itself" do
288
290
  node = Class.new(Lutaml::Model::Serializable) do
289
291
  attribute :name, :string
290
292
  json { map "name", to: :name }
@@ -303,7 +305,10 @@ RSpec.describe "KV group-then-bulk hydration" do
303
305
  end
304
306
  end.map(&:value)
305
307
 
306
- expect(verdicts).to all(be(false))
308
+ expect(verdicts).to all(be_an(Array))
309
+ verdicts.each do |plan|
310
+ expect(plan.find { |row| row[0].to == :child }[4]).to equal(plan)
311
+ end
307
312
  end
308
313
  end
309
314
 
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # lutaml-model#1297: a recursive model graph (a tree) compiles as a
6
+ # self-referential plan instead of being refused to the interpretive
7
+ # walk, and the compiled executor hydrates on an explicit frame stack —
8
+ # hydration depth is bound by the heap, not the VM stack.
9
+ class RecursivePlanNode < Lutaml::Model::Serializable
10
+ attribute :name, :string
11
+ attribute :child, RecursivePlanNode
12
+ attribute :children, RecursivePlanNode, collection: true,
13
+ initialize_empty: true
14
+
15
+ key_value do
16
+ map "name", to: :name
17
+ map "child", to: :child
18
+ map "children", to: :children
19
+ end
20
+ end
21
+
22
+ class RecursivePlanTwig < Lutaml::Model::Serializable
23
+ attribute :name, :string
24
+ attribute :branch, "RecursivePlanBranch"
25
+
26
+ key_value do
27
+ map "name", to: :name
28
+ map "branch", to: :branch
29
+ end
30
+ end
31
+
32
+ class RecursivePlanBranch < Lutaml::Model::Serializable
33
+ attribute :name, :string
34
+ attribute :twigs, RecursivePlanTwig, collection: true,
35
+ initialize_empty: true
36
+
37
+ key_value do
38
+ map "name", to: :name
39
+ map "twigs", to: :twigs
40
+ end
41
+ end
42
+
43
+ # The outer's second row is ineligible (a custom deserializer), so the
44
+ # outer build fails after the inner completed against its rows.
45
+ class RecursivePlanInner < Lutaml::Model::Serializable
46
+ attribute :outer, "RecursivePlanOuter"
47
+
48
+ key_value { map "outer", to: :outer }
49
+ end
50
+
51
+ class RecursivePlanOuter < Lutaml::Model::Serializable
52
+ attribute :inner, RecursivePlanInner
53
+ attribute :note, :string
54
+
55
+ key_value do
56
+ map "inner", to: :inner
57
+ map "note", to: :note, with: { from: :note_from }
58
+ end
59
+
60
+ def self.note_from(_model, value)
61
+ value.to_s
62
+ end
63
+ end
64
+
65
+ RSpec.describe "recursive model graphs on the compiled KV plan" do
66
+ def plan_for(klass)
67
+ Lutaml::KeyValue::Transform.kv_group_plan(klass, :hash, :default)
68
+ end
69
+
70
+ def row_for(plan, attribute)
71
+ plan.find { |row| row[0].to == attribute }
72
+ end
73
+
74
+ def chain(depth, key = "child")
75
+ h = { "name" => "leaf" }
76
+ (depth - 1).times do
77
+ h = { "name" => "n", key => (key == "child" ? h : [h]) }
78
+ end
79
+ h
80
+ end
81
+
82
+ def thicket(depth)
83
+ h = { "name" => "leaf" }
84
+ (depth - 1).times do
85
+ h = { "name" => "b", "twigs" => [{ "name" => "t", "branch" => h }] }
86
+ end
87
+ h
88
+ end
89
+
90
+ it "compiles a self-referencing model as a plan that references itself" do
91
+ plan = plan_for(RecursivePlanNode)
92
+ expect(plan).to be_an(Array)
93
+ expect(row_for(plan, :child)[4]).to equal(plan)
94
+ expect(row_for(plan, :children)[4]).to equal(plan)
95
+ end
96
+
97
+ it "compiles a mutually recursive pair into plans that reference each other" do
98
+ branch = plan_for(RecursivePlanBranch)
99
+ twig = plan_for(RecursivePlanTwig)
100
+ expect(branch).to be_an(Array)
101
+ expect(twig).to be_an(Array)
102
+ expect(row_for(branch, :twigs)[4]).to equal(twig)
103
+ expect(row_for(twig, :branch)[4]).to equal(branch)
104
+ end
105
+
106
+ it "caches the recursive plans once the outermost build succeeds" do
107
+ first = plan_for(RecursivePlanNode)
108
+ expect(plan_for(RecursivePlanNode)).to equal(first)
109
+ twig = plan_for(RecursivePlanTwig)
110
+ expect(row_for(plan_for(RecursivePlanBranch), :twigs)[4]).to equal(twig)
111
+ end
112
+
113
+ it "commits nothing when the outer build fails after an inner completed" do
114
+ expect(plan_for(RecursivePlanOuter)).to be(false)
115
+ # a cached inner plan would reference the failed outer's partial rows
116
+ expect(plan_for(RecursivePlanInner)).to be(false)
117
+ end
118
+
119
+ it "hydrates a self-referencing tree past the VM stack depth" do
120
+ node = RecursivePlanNode.from_hash(chain(10_000))
121
+ depth = 0
122
+ while node.child
123
+ depth += 1
124
+ node = node.child
125
+ end
126
+ # 10,000 levels, one child hop each below the root
127
+ expect(depth).to eq(9_999)
128
+ expect(node.name).to eq("leaf")
129
+ end
130
+
131
+ it "hydrates a mutually recursive graph past the VM stack depth" do
132
+ branch = RecursivePlanBranch.from_hash(thicket(5000))
133
+ depth = 0
134
+ while (twig = branch.twigs.first)&.branch
135
+ depth += 1
136
+ branch = twig.branch
137
+ end
138
+ expect(depth).to eq(4999)
139
+ end
140
+
141
+ it "keeps collection order and the parent wiring through the frame stack" do
142
+ doc = {
143
+ "name" => "root",
144
+ "children" => [
145
+ { "name" => "a", "children" => [{ "name" => "aa" }] },
146
+ { "name" => "b" },
147
+ ],
148
+ }
149
+ node = RecursivePlanNode.from_hash(doc)
150
+ expect(node.children.map(&:name)).to eq(%w[a b])
151
+ expect(node.children.first.children.first.name).to eq("aa")
152
+ expect(node.children.first.lutaml_parent).to equal(node)
153
+ expect(node.children.first.children.first.lutaml_parent)
154
+ .to equal(node.children.first)
155
+ expect(node.to_hash).to eq(doc)
156
+ end
157
+
158
+ it "falls back to the walk for a non-Hash item where a model was expected" do
159
+ doc = { "name" => "root", "child" => { "name" => "c" } }
160
+ expect(RecursivePlanNode.from_hash(doc).child.name).to eq("c")
161
+ expect(RecursivePlanNode.from_hash({ "name" => "root" }).child).to be_nil
162
+ end
163
+ end
@@ -110,4 +110,61 @@ RSpec.describe "polymorphic scalar members under a Serializable base" do
110
110
  end.to raise_error(ArgumentError, /polymorphic entry :frobnicate is not a type/)
111
111
  end
112
112
  end
113
+
114
+ # lutaml-model#1306: a String entry is the lazy type-name form, as for
115
+ # a String attribute type (fontist 3.0.45 lists its import sources by
116
+ # name). The list never resolves names, so they restrict nothing
117
+ # beyond the declared base — the behavior before 0.8.199, which must
118
+ # stay: a working declaration may not start failing at require time.
119
+ describe "String entries" do
120
+ let(:name_base_class) do
121
+ Class.new(Lutaml::Model::Serializable) do
122
+ attribute :x, :string
123
+
124
+ json { map :x, to: :x }
125
+ end
126
+ end
127
+
128
+ let(:named_list_class) do
129
+ base = name_base_class
130
+ Class.new(Lutaml::Model::Serializable) do
131
+ attribute :source, base, polymorphic: [
132
+ "MacosImportSource",
133
+ "GoogleImportSource",
134
+ "SilImportSource",
135
+ ]
136
+
137
+ json { map :source, to: :source }
138
+ end
139
+ end
140
+
141
+ before do
142
+ stub_const("PolyNameBase", name_base_class)
143
+ stub_const("PolyNamedList", named_list_class)
144
+ end
145
+
146
+ it "accepts a name at class definition" do
147
+ expect { PolyNamedList }.not_to raise_error
148
+ end
149
+
150
+ it "keeps a list of names inert: the declared base governs" do
151
+ model = PolyNamedList.new(source: PolyNameBase.new(x: "v"))
152
+ expect(model.validate).to eq([])
153
+ expect(model.to_json).to eq('{"source":{"x":"v"}}')
154
+ expect(PolyNamedList.from_json(model.to_json).source).to be_a(PolyNameBase)
155
+ end
156
+
157
+ it "keeps the class entries authoritative beside a name" do
158
+ member = model_member_class
159
+ other = Class.new(Lutaml::Model::Serializable) { attribute :y, :integer }
160
+ stub_const("PolyOtherMember", other)
161
+ mixed = Class.new(Lutaml::Model::Serializable) do
162
+ attribute :content, Lutaml::Model::Serializable, polymorphic: [member, "OtherMember"]
163
+ end
164
+
165
+ expect(mixed.new(content: member.new(x: "v")).validate).to eq([])
166
+ expect(mixed.new(content: other.new(y: 1)).validate.first)
167
+ .to be_a(Lutaml::Model::PolymorphicError)
168
+ end
169
+ end
113
170
  end
@@ -4,14 +4,14 @@ require "spec_helper"
4
4
  require "tmpdir"
5
5
  require "fileutils"
6
6
 
7
- # lutaml-model#1286 part 2: override APPLICATION in the schema assembly.
7
+ # lutaml-model#1286 part 2: override COMPOSITION in the schema assembly.
8
8
  # The Override model (the parse substrate) is pinned in xsd_override_spec;
9
- # these cells pin the assembly pass — the referenced document's
10
- # same-named components are replaced by the override's children
11
- # (XSD 1.1 §4.2.4), on a copy so the override stays local to the
12
- # referencing document, and the compiler's schema walk reaches the
13
- # applied document in place of the raw one.
14
- RSpec.describe "xs:override application in the assembly" do
9
+ # these cells pin the composition — the referenced document's same-named
10
+ # components are replaced by the override's children (XSD 1.1 §4.2.4) in
11
+ # a view the entry owns, composed against the referenced document by
12
+ # reference so it stays untouched, and the compiler's schema walk reaches
13
+ # the view in place of the raw document.
14
+ RSpec.describe "xs:override composition in the assembly" do
15
15
  let(:dir) { Dir.mktmpdir }
16
16
 
17
17
  let(:base_schema) do
@@ -45,49 +45,126 @@ RSpec.describe "xs:override application in the assembly" do
45
45
  Lutaml::Xml::Schema::Xsd.parse(main_schema, location: dir, register: :xsd)
46
46
  end
47
47
 
48
- it "resolves the referenced document and applies the replacement" do
49
- applied = assembled.override.grep(Lutaml::Xml::Schema::Xsd::Schema).first
50
- expect(applied).not_to be_nil
48
+ def view_of(schema)
49
+ schema.override.first.composed
50
+ end
51
51
 
52
- para = applied.element.find { |e| e.name == "para" }
52
+ it "composes the referenced document with the replacement" do
53
+ para = view_of(assembled).element.find { |e| e.name == "para" }
53
54
  expect(para.type).to eq("xs:dateTime")
54
55
  end
55
56
 
56
57
  it "keeps the non-overridden components of the referenced document" do
57
- applied = assembled.override.grep(Lutaml::Xml::Schema::Xsd::Schema).first
58
- expect(applied.element.map(&:name)).to include("other")
58
+ expect(view_of(assembled).element.map(&:name)).to include("other")
59
+ end
60
+
61
+ it "leaves the referenced document untouched" do
62
+ assembled
63
+ raw = Lutaml::Xml::Schema::Xsd::Schema.processed_schemas["base.xsd"]
64
+ expect(raw.element.find { |e| e.name == "para" }.type).to eq("xs:string")
65
+ expect(view_of(assembled).element.find { |e| e.name == "para" }.type)
66
+ .to eq("xs:dateTime")
59
67
  end
60
68
 
61
- it "applies on a copy, leaving the raw referenced document intact" do
69
+ it "composes a view once per entry, shared by every reference to it" do
62
70
  root = assembled
63
- applied = root.override.grep(Lutaml::Xml::Schema::Xsd::Schema).first
64
- raw = begin
65
- Lutaml::Xml::Schema::Xsd::Schema.schema_processed(
66
- File.join(dir, "base.xsd"),
67
- )
68
- rescue StandardError
69
- nil
71
+ entry = root.override.first
72
+ expect(view_of(root)).to equal(entry.composed)
73
+ expect(root.override.size).to eq(1)
74
+ end
75
+
76
+ it "yields the replaced component to the compiler's document-order walk" do
77
+ view = view_of(assembled)
78
+ walked = view.resolved_element_order.grep(Lutaml::Xml::Schema::Xsd::Element)
79
+ expect(walked.map { |e| [e.name, e.type] })
80
+ .to eq([["para", "xs:dateTime"], ["other", "xs:string"]])
81
+ end
82
+
83
+ context "with an included document overriding the same target" do
84
+ let(:main_schema) do
85
+ <<~XSD
86
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
87
+ <xs:include schemaLocation="sibling.xsd"/>
88
+ <xs:override schemaLocation="base.xsd">
89
+ <xs:element name="para" type="xs:dateTime"/>
90
+ </xs:override>
91
+ </xs:schema>
92
+ XSD
93
+ end
94
+
95
+ let(:sibling_schema) do
96
+ <<~XSD
97
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
98
+ <xs:override schemaLocation="base.xsd">
99
+ <xs:element name="other" type="xs:integer"/>
100
+ </xs:override>
101
+ </xs:schema>
102
+ XSD
103
+ end
104
+
105
+ before do
106
+ File.write(File.join(dir, "sibling.xsd"), sibling_schema)
107
+ end
108
+
109
+ it "composes each against the same originals within one parse" do
110
+ root = assembled
111
+ sibling = root.include.grep(Lutaml::Xml::Schema::Xsd::Schema).first
112
+
113
+ expect(view_of(root).element.map { |e| [e.name, e.type] })
114
+ .to eq([["para", "xs:dateTime"], ["other", "xs:string"]])
115
+ expect(view_of(sibling).element.map { |e| [e.name, e.type] })
116
+ .to eq([["para", "xs:string"], ["other", "xs:integer"]])
70
117
  end
71
- expect(applied.element.find { |e| e.name == "para" }.type).to eq("xs:dateTime")
72
- expect(raw).to be_nil.or(satisfy { |s| s.element.find { |e| e.name == "para" }&.type == "xs:string" })
73
118
  end
74
119
 
75
- it "generates models from the overridden components end to end" do
76
- out_dir = Dir.mktmpdir
77
- begin
78
- Lutaml::Model::Schema::XmlCompiler.to_models(
79
- main_schema,
80
- location: dir,
81
- output_dir: out_dir,
82
- create_files: true,
83
- module_namespace: "OverrideAssemblySpec",
84
- )
85
- require File.join(out_dir, "overrideassemblyspec_registry.rb")
86
- expect(defined?(OverrideAssemblySpec)).to eq("constant")
87
- registry = File.read(File.join(out_dir, "overrideassemblyspec_registry.rb"))
88
- expect(registry).to include("OverrideAssemblySpec")
89
- ensure
90
- FileUtils.rm_rf(out_dir)
120
+ context "with a replaced complex type" do
121
+ let(:base_schema) do
122
+ <<~XSD
123
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
124
+ <xs:complexType name="paraType">
125
+ <xs:sequence>
126
+ <xs:element name="original" type="xs:string"/>
127
+ </xs:sequence>
128
+ </xs:complexType>
129
+ </xs:schema>
130
+ XSD
131
+ end
132
+
133
+ let(:main_schema) do
134
+ <<~XSD
135
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
136
+ <xs:override schemaLocation="base.xsd">
137
+ <xs:complexType name="paraType">
138
+ <xs:sequence>
139
+ <xs:element name="replacement" type="xs:date"/>
140
+ </xs:sequence>
141
+ </xs:complexType>
142
+ </xs:override>
143
+ </xs:schema>
144
+ XSD
145
+ end
146
+
147
+ it "generates models from the replaced components end to end" do
148
+ out_dir = Dir.mktmpdir
149
+ begin
150
+ Lutaml::Model::Schema::XmlCompiler.to_models(
151
+ main_schema,
152
+ location: dir,
153
+ output_dir: out_dir,
154
+ create_files: true,
155
+ module_namespace: "OverrideAssemblySpec",
156
+ )
157
+ expect(File.read(File.join(out_dir, "overrideassemblyspec_registry.rb")))
158
+ .to include("OverrideAssemblySpec")
159
+ # base.xsd is reachable only through the composed view: the
160
+ # replacement member reaching the sources and the original not is
161
+ # the walk running over the view.
162
+ generated = Dir.glob(File.join(out_dir, "**", "*.rb")).map { |p| File.read(p) }.join
163
+ expect(generated).to include("replacement")
164
+ expect(generated).not_to include("original")
165
+ ensure
166
+ FileUtils.rm_rf(out_dir)
167
+ end
91
168
  end
92
169
  end
93
170
  end