lutaml-model 0.8.197 → 0.8.198
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/model/schema/xml_compiler/spec_builder.rb +9 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/schema/xsd/all.rb +2 -0
- data/lib/lutaml/xml/schema/xsd/key.rb +2 -0
- data/lib/lutaml/xml/schema/xsd/keyref.rb +2 -0
- data/lib/lutaml/xml/schema/xsd/override.rb +91 -0
- data/lib/lutaml/xml/schema/xsd/schema.rb +48 -0
- data/lib/lutaml/xml/schema/xsd/unique.rb +2 -0
- data/lib/lutaml/xml/schema/xsd.rb +5 -2
- data/spec/lutaml/xml/schema/xsd_all_any_spec.rb +45 -0
- data/spec/lutaml/xml/schema/xsd_identity_ref_spec.rb +60 -0
- data/spec/lutaml/xml/schema/xsd_override_assembly_spec.rb +93 -0
- data/spec/lutaml/xml/schema/xsd_override_spec.rb +62 -0
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52519a6eccfb4c87dee327752e2d4ff471c602a3965e89b4de1c7402d2230928
|
|
4
|
+
data.tar.gz: f40139e2b94c4694af956b6785ad01ec59cccbe3024ca1e2e658a0cba6d8f48e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 69512c548fcdcac33af59da6256bdca71460da66d3c575083d272a438eddf618389c78053f60913b0f914f74448bf18f9fdf5f550651928ba05f4eeb5932848b
|
|
7
|
+
data.tar.gz: 89c2e28d7c550e15880cd626d5b15e597de8beaee3d804043a1b0ac1955444458a12ee0e9327f9374b18ea3d2981ec078c44d8c75d401195d3d252e3a7bcdd85
|
|
@@ -206,6 +206,15 @@ module Lutaml
|
|
|
206
206
|
# yields each resolved element-order item with its owning schema.
|
|
207
207
|
def each_schema_item(schemas, &dispatch)
|
|
208
208
|
schemas.each do |schema|
|
|
209
|
+
# Override-applied documents ride the override collection
|
|
210
|
+
# alongside the Override declarations themselves (the mixed
|
|
211
|
+
# shape the include/import collections already have); only
|
|
212
|
+
# the applied Schema objects carry a walkable element order.
|
|
213
|
+
if schema.respond_to?(:override) && schema.override&.any?
|
|
214
|
+
schema.override.grep(Lutaml::Xml::Schema::Xsd::Schema).each do |applied|
|
|
215
|
+
each_schema_item([applied], &dispatch)
|
|
216
|
+
end
|
|
217
|
+
end
|
|
209
218
|
if schema.include&.any?
|
|
210
219
|
each_schema_item(schema.include,
|
|
211
220
|
&dispatch)
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Lutaml
|
|
|
10
10
|
attribute :min_occurs, :string
|
|
11
11
|
attribute :annotation, :annotation
|
|
12
12
|
attribute :element, :element, collection: true, initialize_empty: true
|
|
13
|
+
attribute :any, :any, collection: true, initialize_empty: true
|
|
13
14
|
|
|
14
15
|
xml do
|
|
15
16
|
element "all"
|
|
@@ -21,6 +22,7 @@ module Lutaml
|
|
|
21
22
|
map_attribute :minOccurs, to: :min_occurs
|
|
22
23
|
map_element :annotation, to: :annotation
|
|
23
24
|
map_element :element, to: :element
|
|
25
|
+
map_element :any, to: :any
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
Lutaml::Xml::Schema::Xsd.register_model(self, :all)
|
|
@@ -7,6 +7,7 @@ module Lutaml
|
|
|
7
7
|
class Key < Base
|
|
8
8
|
attribute :id, :string
|
|
9
9
|
attribute :name, :string
|
|
10
|
+
attribute :ref, :string
|
|
10
11
|
attribute :selector, :selector
|
|
11
12
|
attribute :annotation, :annotation
|
|
12
13
|
attribute :field, :field, collection: true, initialize_empty: true
|
|
@@ -19,6 +20,7 @@ module Lutaml
|
|
|
19
20
|
|
|
20
21
|
map_attribute :id, to: :id
|
|
21
22
|
map_attribute :name, to: :name
|
|
23
|
+
map_attribute :ref, to: :ref
|
|
22
24
|
map_element :annotation, to: :annotation
|
|
23
25
|
map_element :selector, to: :selector
|
|
24
26
|
map_element :field, to: :field
|
|
@@ -7,6 +7,7 @@ module Lutaml
|
|
|
7
7
|
class Keyref < Base
|
|
8
8
|
attribute :id, :string
|
|
9
9
|
attribute :name, :string
|
|
10
|
+
attribute :ref, :string
|
|
10
11
|
attribute :refer, :string
|
|
11
12
|
attribute :selector, :selector
|
|
12
13
|
attribute :annotation, :annotation
|
|
@@ -20,6 +21,7 @@ module Lutaml
|
|
|
20
21
|
|
|
21
22
|
map_attribute :id, to: :id
|
|
22
23
|
map_attribute :name, to: :name
|
|
24
|
+
map_attribute :ref, to: :ref
|
|
23
25
|
map_attribute :refer, to: :refer
|
|
24
26
|
map_element :field, to: :field
|
|
25
27
|
map_element :selector, to: :selector
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Schema
|
|
6
|
+
module Xsd
|
|
7
|
+
# xs:override (XSD 1.1 §4.2.4): a schema-wide component
|
|
8
|
+
# replacement mechanism — the referenced document's components
|
|
9
|
+
# with matching names are replaced by the children carried
|
|
10
|
+
# here (#1286).
|
|
11
|
+
class Override < Base
|
|
12
|
+
# The component kinds an override may replace, keyed by the
|
|
13
|
+
# attribute carrying the component name.
|
|
14
|
+
COMPONENT_KINDS = {
|
|
15
|
+
element: :name,
|
|
16
|
+
attribute: :name,
|
|
17
|
+
notation: :name,
|
|
18
|
+
simple_type: :name,
|
|
19
|
+
complex_type: :name,
|
|
20
|
+
group: :name,
|
|
21
|
+
attribute_group: :name,
|
|
22
|
+
}.freeze
|
|
23
|
+
|
|
24
|
+
attribute :id, :string
|
|
25
|
+
attribute :schema_path, :string
|
|
26
|
+
attribute :annotation, :annotation
|
|
27
|
+
attribute :element, :element, collection: true, initialize_empty: true
|
|
28
|
+
attribute :attribute, :attribute, collection: true, initialize_empty: true
|
|
29
|
+
attribute :notation, :notation, collection: true, initialize_empty: true
|
|
30
|
+
attribute :simple_type, :simple_type, collection: true, initialize_empty: true
|
|
31
|
+
attribute :complex_type, :complex_type, collection: true, initialize_empty: true
|
|
32
|
+
attribute :group, :group, collection: true, initialize_empty: true
|
|
33
|
+
attribute :attribute_group, :attribute_group, collection: true,
|
|
34
|
+
initialize_empty: true
|
|
35
|
+
|
|
36
|
+
xml do
|
|
37
|
+
element "override"
|
|
38
|
+
mixed_content
|
|
39
|
+
namespace Lutaml::Xml::Schema::XsdNamespace
|
|
40
|
+
|
|
41
|
+
map_attribute :id, to: :id
|
|
42
|
+
map_attribute :schemaLocation, to: :schema_path
|
|
43
|
+
map_element :annotation, to: :annotation
|
|
44
|
+
map_element :element, to: :element
|
|
45
|
+
map_element :attribute, to: :attribute
|
|
46
|
+
map_element :notation, to: :notation
|
|
47
|
+
map_element :simpleType, to: :simple_type
|
|
48
|
+
map_element :complexType, to: :complex_type
|
|
49
|
+
map_element :group, to: :group
|
|
50
|
+
map_element :attributeGroup, to: :attribute_group
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The referenced document, read through the same location
|
|
54
|
+
# machinery includes and imports use (the assembly pass).
|
|
55
|
+
def fetch_schema
|
|
56
|
+
Glob.include_schema(schema_path) if schema_path && Glob.location?
|
|
57
|
+
end
|
|
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?
|
|
71
|
+
|
|
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
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
target_schema
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
Lutaml::Xml::Schema::Xsd.register_model(self, :override)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -41,6 +41,14 @@ module Lutaml
|
|
|
41
41
|
initialize_empty: true
|
|
42
42
|
attribute :attribute_group, :attribute_group, collection: true,
|
|
43
43
|
initialize_empty: true
|
|
44
|
+
attribute :override, :override, collection: true,
|
|
45
|
+
initialize_empty: true
|
|
46
|
+
attribute :unique, :unique, collection: true,
|
|
47
|
+
initialize_empty: true
|
|
48
|
+
attribute :key, :key, collection: true,
|
|
49
|
+
initialize_empty: true
|
|
50
|
+
attribute :keyref, :keyref, collection: true,
|
|
51
|
+
initialize_empty: true
|
|
44
52
|
|
|
45
53
|
xml do
|
|
46
54
|
element "schema"
|
|
@@ -56,6 +64,10 @@ module Lutaml
|
|
|
56
64
|
map_element :simpleType, to: :simple_type
|
|
57
65
|
map_element :complexType, to: :complex_type
|
|
58
66
|
map_element :attributeGroup, to: :attribute_group
|
|
67
|
+
map_element :override, to: :override
|
|
68
|
+
map_element :unique, to: :unique
|
|
69
|
+
map_element :key, to: :key
|
|
70
|
+
map_element :keyref, to: :keyref
|
|
59
71
|
map_element :import, to: :import,
|
|
60
72
|
with: { from: :import_from_schema, to: :import_to_schema }
|
|
61
73
|
map_element :include, to: :include,
|
|
@@ -282,6 +294,33 @@ module Lutaml
|
|
|
282
294
|
alias attributes attribute
|
|
283
295
|
alias groups group
|
|
284
296
|
|
|
297
|
+
def apply_overrides!(seen = nil)
|
|
298
|
+
seen ||= {}.compare_by_identity
|
|
299
|
+
return self if seen[self]
|
|
300
|
+
|
|
301
|
+
seen[self] = true
|
|
302
|
+
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)
|
|
305
|
+
|
|
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
|
|
310
|
+
|
|
311
|
+
applied = Lutaml::Model::Utils.deep_dup(referenced)
|
|
312
|
+
entry.apply_to!(applied)
|
|
313
|
+
override(applied)
|
|
314
|
+
applied.apply_overrides!(seen)
|
|
315
|
+
end
|
|
316
|
+
%i[include import].each do |kind|
|
|
317
|
+
Array(public_send(kind)).each do |nested|
|
|
318
|
+
nested.apply_overrides!(seen) if nested.is_a?(Schema)
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
self
|
|
322
|
+
end
|
|
323
|
+
|
|
285
324
|
private
|
|
286
325
|
|
|
287
326
|
def namespace_prefix_for(element, namespace_uri)
|
|
@@ -299,6 +338,15 @@ module Lutaml
|
|
|
299
338
|
namespaces.uniq
|
|
300
339
|
end
|
|
301
340
|
|
|
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.
|
|
302
350
|
def setup_import_and_include(klass, model, schema, args = {})
|
|
303
351
|
instance = init_instance_of(klass, schema.attributes || {}, args)
|
|
304
352
|
annotation_object(instance, schema)
|
|
@@ -7,6 +7,7 @@ module Lutaml
|
|
|
7
7
|
class Unique < Base
|
|
8
8
|
attribute :id, :string
|
|
9
9
|
attribute :name, :string
|
|
10
|
+
attribute :ref, :string
|
|
10
11
|
attribute :selector, :selector
|
|
11
12
|
attribute :annotation, :annotation
|
|
12
13
|
attribute :field, :field, collection: true, initialize_empty: true
|
|
@@ -18,6 +19,7 @@ module Lutaml
|
|
|
18
19
|
|
|
19
20
|
map_attribute :id, to: :id
|
|
20
21
|
map_attribute :name, to: :name
|
|
22
|
+
map_attribute :ref, to: :ref
|
|
21
23
|
map_element :annotation, to: :annotation
|
|
22
24
|
map_element :selector, to: :selector
|
|
23
25
|
map_element :field, to: :field
|
|
@@ -34,7 +34,7 @@ module Lutaml
|
|
|
34
34
|
Element Enumeration ExtensionComplexContent ExtensionSimpleContent
|
|
35
35
|
Field FractionDigits Glob Group Import Include Key Keyref Length List
|
|
36
36
|
MaxExclusive MaxInclusive MaxLength MaxScale MinExclusive MinInclusive
|
|
37
|
-
MinLength MinScale Notation OpenContent Pattern Redefine
|
|
37
|
+
MinLength MinScale Notation OpenContent Override Pattern Redefine
|
|
38
38
|
RestrictionComplexContent RestrictionSimpleContent
|
|
39
39
|
RestrictionSimpleType Schema SchemaPath Selector Sequence SimpleContent
|
|
40
40
|
SimpleType TotalDigits Union Unique WhiteSpace
|
|
@@ -102,6 +102,7 @@ module Lutaml
|
|
|
102
102
|
autoload :Notation, "#{__dir__}/xsd/notation"
|
|
103
103
|
autoload :Pattern, "#{__dir__}/xsd/pattern"
|
|
104
104
|
autoload :Redefine, "#{__dir__}/xsd/redefine"
|
|
105
|
+
autoload :Override, "#{__dir__}/xsd/override"
|
|
105
106
|
autoload :RestrictionComplexContent,
|
|
106
107
|
"#{__dir__}/xsd/restriction_complex_content"
|
|
107
108
|
autoload :RestrictionSimpleContent,
|
|
@@ -164,7 +165,9 @@ module Lutaml
|
|
|
164
165
|
Schema.reset_processed_schemas unless nested_schema
|
|
165
166
|
|
|
166
167
|
Glob.with_location(location) do
|
|
167
|
-
Schema.from_xml(xsd, register: register)
|
|
168
|
+
Schema.from_xml(xsd, register: register)
|
|
169
|
+
.apply_overrides!
|
|
170
|
+
.assign_root!
|
|
168
171
|
end
|
|
169
172
|
end
|
|
170
173
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1287: xs:all drops xs:any members — XSD 1.1 (§3.8.2)
|
|
6
|
+
# permits wildcards as xs:all members, and the All model mapped
|
|
7
|
+
# element only, so the wildcard member was erased at parse and the
|
|
8
|
+
# content model lost its absorbing slot (the W3C suite zing shape).
|
|
9
|
+
RSpec.describe "xs:all wildcard members" do
|
|
10
|
+
let(:source) do
|
|
11
|
+
<<~XML
|
|
12
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
13
|
+
<xs:complexType name="zing">
|
|
14
|
+
<xs:all>
|
|
15
|
+
<xs:element ref="a" minOccurs="0"/>
|
|
16
|
+
<xs:element name="b" type="xs:string" minOccurs="0"/>
|
|
17
|
+
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
|
|
18
|
+
</xs:all>
|
|
19
|
+
</xs:complexType>
|
|
20
|
+
</xs:schema>
|
|
21
|
+
XML
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
let(:root) { Lutaml::Xml::Schema::Xsd.parse(source, register: :xsd) }
|
|
25
|
+
let(:all_node) { root.complex_type.first.all }
|
|
26
|
+
|
|
27
|
+
it "parses the wildcard member alongside the elements" do
|
|
28
|
+
expect(all_node.element.first.ref).to eq("a")
|
|
29
|
+
expect(all_node.element.last.name).to eq("b")
|
|
30
|
+
expect(all_node.any).not_to be_empty
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "keeps the wildcard's occurrences and processContents" do
|
|
34
|
+
any_member = all_node.any.first
|
|
35
|
+
expect(any_member.min_occurs).to eq("0")
|
|
36
|
+
expect(any_member.max_occurs).to eq("unbounded")
|
|
37
|
+
expect(any_member.process_contents).to eq("skip")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "round-trips the wildcard member through to_xml" do
|
|
41
|
+
out = root.to_xml
|
|
42
|
+
expect(out).to include('<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>')
|
|
43
|
+
expect(out).to include('<xs:element ref="a" minOccurs="0"/>')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1285: xs:key/xs:unique/xs:keyref drop the `ref` attribute
|
|
6
|
+
# — XSD 1.1 §3.11.2 permits identity constraints by reference (a
|
|
7
|
+
# top-level constraint definition reached via ref), and the reference
|
|
8
|
+
# was erased at parse, so the referring element carried no evaluable
|
|
9
|
+
# constraint (the W3C suite Id/id040 + id043 shape).
|
|
10
|
+
RSpec.describe "identity constraints by reference" do
|
|
11
|
+
let(:source) do
|
|
12
|
+
<<~XML
|
|
13
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
14
|
+
xmlns:s="http://www.example.com/schema">
|
|
15
|
+
<xs:element name="appx" type="s:chap">
|
|
16
|
+
<xs:unique ref="s:unique-clause"/>
|
|
17
|
+
<xs:key ref="s:key-clause"/>
|
|
18
|
+
<xs:keyref name="kr" refer="s:key-clause">
|
|
19
|
+
<xs:selector xpath="s:section"/>
|
|
20
|
+
<xs:field xpath="@nr"/>
|
|
21
|
+
</xs:keyref>
|
|
22
|
+
</xs:element>
|
|
23
|
+
<xs:unique name="unique-clause">
|
|
24
|
+
<xs:selector xpath="s:section"/>
|
|
25
|
+
<xs:field xpath="@nr"/>
|
|
26
|
+
</xs:unique>
|
|
27
|
+
<xs:key name="key-clause">
|
|
28
|
+
<xs:selector xpath="s:section"/>
|
|
29
|
+
<xs:field xpath="@nr"/>
|
|
30
|
+
</xs:key>
|
|
31
|
+
</xs:schema>
|
|
32
|
+
XML
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
let(:root) { Lutaml::Xml::Schema::Xsd.parse(source, register: :xsd) }
|
|
36
|
+
let(:appx) { root.element.first }
|
|
37
|
+
|
|
38
|
+
it "parses the ref on a referenced xs:unique" do
|
|
39
|
+
unique = appx.unique.first
|
|
40
|
+
expect(unique.ref).to eq("s:unique-clause")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "parses the ref on a referenced xs:key" do
|
|
44
|
+
key = appx.key.first
|
|
45
|
+
expect(key.ref).to eq("s:key-clause")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "round-trips the ref spelling through to_xml" do
|
|
49
|
+
out = root.to_xml
|
|
50
|
+
expect(out).to include('<xs:unique ref="s:unique-clause"/>')
|
|
51
|
+
expect(out).to include('<xs:key ref="s:key-clause"/>')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "keeps the named top-level constraint definitions intact" do
|
|
55
|
+
out = root.to_xml
|
|
56
|
+
expect(out).to include('<xs:unique name="unique-clause">')
|
|
57
|
+
expect(out).to include('<xs:key name="key-clause">')
|
|
58
|
+
expect(out).to include('<xs:keyref name="kr" refer="s:key-clause">')
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
require "fileutils"
|
|
6
|
+
|
|
7
|
+
# lutaml-model#1286 part 2: override APPLICATION in the schema assembly.
|
|
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
|
|
15
|
+
let(:dir) { Dir.mktmpdir }
|
|
16
|
+
|
|
17
|
+
let(:base_schema) do
|
|
18
|
+
<<~XSD
|
|
19
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
20
|
+
<xs:element name="para" type="xs:string"/>
|
|
21
|
+
<xs:element name="other" type="xs:string"/>
|
|
22
|
+
</xs:schema>
|
|
23
|
+
XSD
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:main_schema) do
|
|
27
|
+
<<~XSD
|
|
28
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
29
|
+
<xs:override schemaLocation="base.xsd">
|
|
30
|
+
<xs:element name="para" type="xs:dateTime"/>
|
|
31
|
+
</xs:override>
|
|
32
|
+
</xs:schema>
|
|
33
|
+
XSD
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
before do
|
|
37
|
+
File.write(File.join(dir, "base.xsd"), base_schema)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
after do
|
|
41
|
+
FileUtils.rm_rf(dir)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def assembled
|
|
45
|
+
Lutaml::Xml::Schema::Xsd.parse(main_schema, location: dir, register: :xsd)
|
|
46
|
+
end
|
|
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
|
|
51
|
+
|
|
52
|
+
para = applied.element.find { |e| e.name == "para" }
|
|
53
|
+
expect(para.type).to eq("xs:dateTime")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
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")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "applies on a copy, leaving the raw referenced document intact" do
|
|
62
|
+
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
|
|
70
|
+
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
|
+
end
|
|
74
|
+
|
|
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)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1286: xs:override (XSD 1.1 §4.2.4) — the schema-wide
|
|
6
|
+
# component replacement mechanism — was absent from the Schema model,
|
|
7
|
+
# so the roundtrip erased both the schemaLocation target and the
|
|
8
|
+
# replacing components (the W3C suite saxonData/Override shape).
|
|
9
|
+
RSpec.describe "xs:override" do
|
|
10
|
+
let(:source) do
|
|
11
|
+
<<~XML
|
|
12
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
13
|
+
<xs:override schemaLocation="over002a.xsd">
|
|
14
|
+
<xs:element name="para" type="xs:dateTime"/>
|
|
15
|
+
</xs:override>
|
|
16
|
+
<xs:element name="kept" type="xs:string"/>
|
|
17
|
+
</xs:schema>
|
|
18
|
+
XML
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
let(:root) { Lutaml::Xml::Schema::Xsd.parse(source, register: :xsd) }
|
|
22
|
+
|
|
23
|
+
it "parses the override with its schemaLocation target" do
|
|
24
|
+
expect(root.override).not_to be_empty
|
|
25
|
+
expect(root.override.first.schema_path).to eq("over002a.xsd")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "carries the replacing components" do
|
|
29
|
+
override = root.override.first
|
|
30
|
+
expect(override.element.size).to eq(1)
|
|
31
|
+
expect(override.element.first.name).to eq("para")
|
|
32
|
+
expect(override.element.first.type).to eq("xs:dateTime")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "keeps the non-overridden siblings" do
|
|
36
|
+
expect(root.element.first.name).to eq("kept")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "round-trips the whole override through to_xml" do
|
|
40
|
+
out = root.to_xml
|
|
41
|
+
expect(out).to include('<xs:override schemaLocation="over002a.xsd">')
|
|
42
|
+
expect(out).to include('<xs:element name="para" type="xs:dateTime"/>')
|
|
43
|
+
expect(out).to include('<xs:element name="kept" type="xs:string"/>')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "carries multiple replacing component kinds" do
|
|
47
|
+
multi = <<~XML
|
|
48
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
49
|
+
<xs:override schemaLocation="o.xsd">
|
|
50
|
+
<xs:complexType name="t1"/>
|
|
51
|
+
<xs:attribute name="a1" type="xs:string"/>
|
|
52
|
+
<xs:group ref="g1"/>
|
|
53
|
+
</xs:override>
|
|
54
|
+
</xs:schema>
|
|
55
|
+
XML
|
|
56
|
+
root_multi = Lutaml::Xml::Schema::Xsd.parse(multi, register: :xsd)
|
|
57
|
+
override = root_multi.override.first
|
|
58
|
+
expect(override.complex_type.first.name).to eq("t1")
|
|
59
|
+
expect(override.attribute.first.name).to eq("a1")
|
|
60
|
+
expect(override.group.first.ref).to eq("g1")
|
|
61
|
+
end
|
|
62
|
+
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.198
|
|
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-12-
|
|
11
|
+
date: 2026-12-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -1034,6 +1034,7 @@ files:
|
|
|
1034
1034
|
- lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb
|
|
1035
1035
|
- lib/lutaml/xml/schema/xsd/notation.rb
|
|
1036
1036
|
- lib/lutaml/xml/schema/xsd/open_content.rb
|
|
1037
|
+
- lib/lutaml/xml/schema/xsd/override.rb
|
|
1037
1038
|
- lib/lutaml/xml/schema/xsd/pattern.rb
|
|
1038
1039
|
- lib/lutaml/xml/schema/xsd/redefine.rb
|
|
1039
1040
|
- lib/lutaml/xml/schema/xsd/restriction_complex_content.rb
|
|
@@ -2423,6 +2424,10 @@ files:
|
|
|
2423
2424
|
- spec/lutaml/xml/schema/xsd/vc_versioning_spec.rb
|
|
2424
2425
|
- spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb
|
|
2425
2426
|
- spec/lutaml/xml/schema/xsd/xsd_spec.rb
|
|
2427
|
+
- spec/lutaml/xml/schema/xsd_all_any_spec.rb
|
|
2428
|
+
- spec/lutaml/xml/schema/xsd_identity_ref_spec.rb
|
|
2429
|
+
- spec/lutaml/xml/schema/xsd_override_assembly_spec.rb
|
|
2430
|
+
- spec/lutaml/xml/schema/xsd_override_spec.rb
|
|
2426
2431
|
- spec/lutaml/xml/schema/xsd_scale_vc_spec.rb
|
|
2427
2432
|
- spec/lutaml/xml/schema_primer_spec.rb
|
|
2428
2433
|
- spec/lutaml/xml/serializable_namespace_spec.rb
|