lutaml-model 0.8.196 → 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/docs/_references/plan-schema-spec.adoc +308 -0
- data/lib/compat/opal/lutaml_model_boot.rb +1 -0
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +10 -3
- data/lib/lutaml/lml/models/top_element_attribute.rb +7 -2
- data/lib/lutaml/model/schema/xml_compiler/spec_builder.rb +9 -0
- data/lib/lutaml/model/serialize/annotations.rb +74 -0
- data/lib/lutaml/model/serialize.rb +2 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/mapping.rb +15 -0
- data/lib/lutaml/xml/schema/xsd/all.rb +2 -0
- data/lib/lutaml/xml/schema/xsd/attribute.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/element.rb +3 -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/max_scale.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/min_scale.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/override.rb +91 -0
- data/lib/lutaml/xml/schema/xsd/restriction_simple_type.rb +9 -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/vc_conditional_attributes.rb +62 -0
- data/lib/lutaml/xml/schema/xsd.rb +10 -3
- data/lib/lutaml/xml/schema/xsd_schema.rb +2 -0
- data/spec/lml/lutaml/lml/format_adapter_spec.rb +24 -0
- data/spec/lml/lutaml/lml/json_transfer_spec.rb +188 -0
- data/spec/lml/lutaml/lml/property_laws_spec.rb +3 -38
- data/spec/lml/support/lml_property_support.rb +168 -0
- data/spec/lutaml/model/annotations_spec.rb +97 -0
- 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
- data/spec/lutaml/xml/schema/xsd_scale_vc_spec.rb +59 -0
- metadata +16 -2
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
ENV["RANTLY_VERBOSE"] ||= "0"
|
|
4
|
+
require "rantly"
|
|
5
|
+
require "rantly/rspec_extensions"
|
|
6
|
+
require "rantly/shrinks"
|
|
7
|
+
require "lutaml/lml/format"
|
|
8
|
+
|
|
9
|
+
# Constants shared by the generative laws (TODO.next/sota/properties.md).
|
|
10
|
+
# Seeded and reproducible: the seed is printed before every property run,
|
|
11
|
+
# and Rantly shrinks the generated tuple on failure. PR runs use a
|
|
12
|
+
# reduced count and depth; the nightly workflow raises both through
|
|
13
|
+
# LML_PROPERTY_COUNT / LML_PROPERTY_DEPTH and supplies a fresh seed.
|
|
14
|
+
module PropertyLawsSupport
|
|
15
|
+
SEED = Integer(ENV.fetch("LML_PROPERTY_SEED", "20261020"))
|
|
16
|
+
COUNT = Integer(ENV.fetch("LML_PROPERTY_COUNT", "40"))
|
|
17
|
+
DEPTH = Integer(ENV.fetch("LML_PROPERTY_DEPTH", "2"))
|
|
18
|
+
|
|
19
|
+
TYPES = {
|
|
20
|
+
string: :string, integer: :integer, float: :float, boolean: :boolean
|
|
21
|
+
}.freeze
|
|
22
|
+
|
|
23
|
+
# Values that a bare-word emission would read back as something other
|
|
24
|
+
# than a string (or not read at all).
|
|
25
|
+
EDGE_STRINGS = [
|
|
26
|
+
"", "null", "true", "false", "01", "1.50", "2dCi9o", "0x10",
|
|
27
|
+
"with space", "a-b", 'quote"x', "back\\slash", " padded ",
|
|
28
|
+
"line\nbreak", "tab\there", "üñï", "🎨", "12", "-3"
|
|
29
|
+
].freeze
|
|
30
|
+
|
|
31
|
+
STRING_GEN = proc do
|
|
32
|
+
case choose(:print, :ascii, :edge)
|
|
33
|
+
when :print then string(:print)
|
|
34
|
+
when :ascii then string(:ascii)
|
|
35
|
+
else choose(*EDGE_STRINGS)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# The document-model comparison defined with TODO.canon/5.
|
|
40
|
+
DEFAULT_VALUES = {
|
|
41
|
+
"visibility" => "public", "literal" => false, "is_derived" => false,
|
|
42
|
+
"is_static" => false, "is_read_only" => false, "is_abstract" => false,
|
|
43
|
+
"direction" => "in"
|
|
44
|
+
}.freeze
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Grammar-directed LML document generator shared by the generative laws.
|
|
48
|
+
module LmlDocumentGenerator
|
|
49
|
+
# ---- grammar-directed document generation ----
|
|
50
|
+
|
|
51
|
+
def generated_document(params)
|
|
52
|
+
numbers = params.array
|
|
53
|
+
counts = Array.new(7) { |i| numbers[i] % (PropertyLawsSupport::DEPTH + 1) }
|
|
54
|
+
seed = numbers[7]
|
|
55
|
+
|
|
56
|
+
model = []
|
|
57
|
+
model.concat(generated_classes(seed, counts[0]))
|
|
58
|
+
model.concat(generated_enums(seed, counts[1], counts[2]))
|
|
59
|
+
model.concat(generated_packages(seed, counts[3]))
|
|
60
|
+
model.concat(generated_mappings(counts[4]))
|
|
61
|
+
|
|
62
|
+
source = +""
|
|
63
|
+
source << "lml \"1.0\"\n\n" if numbers[9].even?
|
|
64
|
+
source << "require \"gen.lml\"\n\n" if numbers[8].even?
|
|
65
|
+
source << wrap_models(seed, model) unless model.empty?
|
|
66
|
+
source << generated_instances(counts[5], counts[6])
|
|
67
|
+
source
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def wrap_models(seed, members)
|
|
71
|
+
"models Gen#{seed % 10} {\n#{indent(members.join("\n\n"))}\n}\n\n"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def generated_classes(seed, count)
|
|
75
|
+
Array.new(count) do |i|
|
|
76
|
+
attrs = Array.new((seed + i) % (PropertyLawsSupport::DEPTH + 2)) do |j|
|
|
77
|
+
generated_attribute(seed + i + j, j)
|
|
78
|
+
end
|
|
79
|
+
body = attrs.map { |line| indent(line) }
|
|
80
|
+
body << indent("definition \"generated class #{i}\"") if seed.even?
|
|
81
|
+
body << indent("op#{i}(in x: String) : Boolean") if (seed + i) % 4 == 1
|
|
82
|
+
body << indent("** class comment #{i}") if (seed + i) % 4 == 2
|
|
83
|
+
|
|
84
|
+
header = "class C#{i}"
|
|
85
|
+
header += " < Base" if (seed + i) % 5 == 3
|
|
86
|
+
"#{header} {\n#{body.join("\n\n")}\n}"
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def generated_attribute(seed, index)
|
|
91
|
+
name = "a#{index}"
|
|
92
|
+
type = PropertyLawsSupport::TYPES.keys.map { |key| key.to_s.capitalize }[seed % 4]
|
|
93
|
+
case seed % 6
|
|
94
|
+
when 0 then "attribute #{name}, #{type}"
|
|
95
|
+
when 1 then "attribute #{name}, #{type} { cardinality 0..n }"
|
|
96
|
+
when 2 then "attribute #{name}, #{type} { values { \"x\", \"y\" } }"
|
|
97
|
+
when 3 then "attribute #{name}, #{type} { pattern /a[0-9]+/ }"
|
|
98
|
+
when 4 then "-a#{index}: #{type} [1..2]"
|
|
99
|
+
else "attribute #{name}, #{type} { default: \"d#{index}\" }"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def generated_enums(seed, count, members)
|
|
104
|
+
Array.new(count) do |i|
|
|
105
|
+
body = ["definition \"generated enum #{i}\""]
|
|
106
|
+
Array.new(members) do |m|
|
|
107
|
+
body << generated_enum_member(seed + m, m)
|
|
108
|
+
end
|
|
109
|
+
"enum E#{i} {\n#{indent(body.join("\n\n"))}\n}"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def generated_enum_member(seed, index)
|
|
114
|
+
case seed % 4
|
|
115
|
+
when 0 then "value \"v#{index}\" {\n definition \"member #{index}\"\n}"
|
|
116
|
+
when 1 then "value v#{index}"
|
|
117
|
+
when 2 then "m#{index}: String"
|
|
118
|
+
else "value \"p#{index}\" {\n payload = \"x\"\n instance Payload {\n a = \"b\"\n }\n}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def generated_packages(seed, count)
|
|
123
|
+
Array.new(count) do
|
|
124
|
+
"package P#{seed % 10} {\n" \
|
|
125
|
+
"#{indent('class PClass { attribute x, String }')}\n\n" \
|
|
126
|
+
"#{indent('enum PEnum { value "p" }')}\n}"
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def generated_mappings(count)
|
|
131
|
+
return [] if count.zero?
|
|
132
|
+
|
|
133
|
+
["mapping xml Thing {\n" \
|
|
134
|
+
"#{indent('element "thing"')}\n\n" \
|
|
135
|
+
"#{indent('map_element "wire" a0')}\n}"]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def generated_instances(collections, instances)
|
|
139
|
+
lines = []
|
|
140
|
+
instances.times do |i|
|
|
141
|
+
lines << "instance \"t#{i}\" Thing {"
|
|
142
|
+
lines << indent("a0 = \"value #{i}\"")
|
|
143
|
+
lines << indent("a1 = 1")
|
|
144
|
+
lines << indent("a2 = true")
|
|
145
|
+
lines << indent("a3 = null")
|
|
146
|
+
lines << indent("a4 = [\"x\", \"null\", \"é\"]")
|
|
147
|
+
lines << "}"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
if collections.positive?
|
|
151
|
+
lines << "instances GenInstances {"
|
|
152
|
+
Array.new(collections) do |i|
|
|
153
|
+
lines << indent("collection \"col#{i}\" {")
|
|
154
|
+
lines << indent(indent("includes [\"t#{i}\"]"))
|
|
155
|
+
lines << indent(indent('validation { condition "count >= 0" }'))
|
|
156
|
+
lines << indent("}")
|
|
157
|
+
end
|
|
158
|
+
lines << "}"
|
|
159
|
+
end
|
|
160
|
+
return "" if lines.empty?
|
|
161
|
+
|
|
162
|
+
"#{lines.join("\n\n")}\n"
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def indent(text)
|
|
166
|
+
text.lines.map { |line| " #{line}" }.join
|
|
167
|
+
end
|
|
168
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#288 step 1: the class-level annotation DSL —
|
|
6
|
+
# description/example/annotation — stored in a frozen per-class table.
|
|
7
|
+
# Purely additive: the table is invisible to serialization and to the
|
|
8
|
+
# #1033 exporter's declaration walk.
|
|
9
|
+
RSpec.describe "class-level annotations DSL" do
|
|
10
|
+
let(:annotated_class) do
|
|
11
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
12
|
+
attribute :name, :string
|
|
13
|
+
xml do
|
|
14
|
+
element "annotated"
|
|
15
|
+
map_element "name", to: :name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
description "A model carrying annotations."
|
|
19
|
+
description "Second prose line."
|
|
20
|
+
example %(name: "x"), description: "minimal shape"
|
|
21
|
+
example %(name: "y")
|
|
22
|
+
annotation :schema, "follows the base pattern"
|
|
23
|
+
annotation :schema, "extended per the profile"
|
|
24
|
+
annotation :source, "the base register"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
before do
|
|
29
|
+
stub_const("AnnotatedSpecModel", annotated_class)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "stores repeatable descriptions in declaration order" do
|
|
33
|
+
expect(AnnotatedSpecModel.annotations[:descriptions]).to eq(
|
|
34
|
+
["A model carrying annotations.", "Second prose line."],
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "stores examples with optional descriptions" do
|
|
39
|
+
expect(AnnotatedSpecModel.annotations[:examples]).to eq(
|
|
40
|
+
[
|
|
41
|
+
{ snippet: %(name: "x"), description: "minimal shape" },
|
|
42
|
+
{ snippet: %(name: "y") },
|
|
43
|
+
],
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "groups keyed annotations per term, keeping declaration order" do
|
|
48
|
+
expect(AnnotatedSpecModel.annotations[:annotations][:schema]).to eq(
|
|
49
|
+
["follows the base pattern", "extended per the profile"],
|
|
50
|
+
)
|
|
51
|
+
expect(AnnotatedSpecModel.annotations[:annotations][:source]).to eq(
|
|
52
|
+
["the base register"],
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "returns a frozen table" do
|
|
57
|
+
table = AnnotatedSpecModel.annotations
|
|
58
|
+
expect(table).to be_frozen
|
|
59
|
+
expect(table[:descriptions]).to be_frozen
|
|
60
|
+
expect(table[:examples]).to be_frozen
|
|
61
|
+
expect(table[:annotations]).to be_frozen
|
|
62
|
+
expect(table[:annotations][:schema]).to be_frozen
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "isolates classes: an unannotated class reads an empty table" do
|
|
66
|
+
plain = Class.new(Lutaml::Model::Serializable)
|
|
67
|
+
stub_const("PlainSpecModel", plain)
|
|
68
|
+
|
|
69
|
+
expect(PlainSpecModel.annotations).to eq(
|
|
70
|
+
descriptions: [], examples: [], annotations: {},
|
|
71
|
+
)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "does not leak annotations across sibling classes" do
|
|
75
|
+
sibling = Class.new(Lutaml::Model::Serializable)
|
|
76
|
+
stub_const("SiblingSpecModel", sibling)
|
|
77
|
+
SiblingSpecModel.description "sibling only"
|
|
78
|
+
|
|
79
|
+
expect(SiblingSpecModel.annotations[:descriptions]).to eq(["sibling only"])
|
|
80
|
+
expect(AnnotatedSpecModel.annotations[:descriptions]).not_to include("sibling only")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "leaves serialization byte-identical" do
|
|
84
|
+
annotated = AnnotatedSpecModel.new(name: "x")
|
|
85
|
+
plain = Class.new(Lutaml::Model::Serializable) do
|
|
86
|
+
attribute :name, :string
|
|
87
|
+
xml do
|
|
88
|
+
element "annotated"
|
|
89
|
+
map_element "name", to: :name
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
stub_const("PlainShapeSpecModel", plain)
|
|
93
|
+
|
|
94
|
+
expect(annotated.to_xml.strip).to eq(PlainShapeSpecModel.new(name: "x").to_xml.strip)
|
|
95
|
+
expect(annotated.to_json.strip).to eq(PlainShapeSpecModel.new(name: "x").to_json.strip)
|
|
96
|
+
end
|
|
97
|
+
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
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "XSD 1.1 scale facets and component-level vc: attributes" do
|
|
6
|
+
let(:source) do
|
|
7
|
+
<<~XML
|
|
8
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning">
|
|
9
|
+
<xs:attribute name="x" use="required" vc:typeUnavailable="xs:integer"/>
|
|
10
|
+
<xs:element name="e" vc:minVersion="1.1"/>
|
|
11
|
+
<xs:simpleType name="decMinMaxScale">
|
|
12
|
+
<xs:restriction base="xs:precisionDecimal">
|
|
13
|
+
<xs:minScale value="2"/>
|
|
14
|
+
<xs:maxScale value="3"/>
|
|
15
|
+
</xs:restriction>
|
|
16
|
+
</xs:simpleType>
|
|
17
|
+
</xs:schema>
|
|
18
|
+
XML
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
let(:root) { Lutaml::Xml::Schema::Xsd.parse(source, register: :xsd) }
|
|
22
|
+
|
|
23
|
+
describe "minScale/maxScale facets (XSD 1.1 §3.4.2)" do
|
|
24
|
+
it "parses the scale facets" do
|
|
25
|
+
restriction = root.simple_type.first.restriction
|
|
26
|
+
|
|
27
|
+
expect(restriction.min_scale.first.value).to eq(2)
|
|
28
|
+
expect(restriction.max_scale.first.value).to eq(3)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "round-trips the scale facets" do
|
|
32
|
+
xml = root.to_xml
|
|
33
|
+
|
|
34
|
+
expect(xml).to include("minScale")
|
|
35
|
+
expect(xml).to include("maxScale")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "component-level vc: conditional attributes (XSD 1.1 §4.2)" do
|
|
40
|
+
it "parses the declaration-level spellings" do
|
|
41
|
+
expect(root.attribute.first.vc_type_unavailable).to eq("xs:integer")
|
|
42
|
+
expect(root.element.first.vc_min_version).to eq("1.1")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "round-trips with the vc: namespace" do
|
|
46
|
+
xml = root.to_xml
|
|
47
|
+
|
|
48
|
+
expect(xml).to include("vc:typeUnavailable")
|
|
49
|
+
expect(xml).to include("vc:minVersion")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "absent vc: attributes stay absent" do
|
|
53
|
+
xml = root.to_xml
|
|
54
|
+
|
|
55
|
+
expect(xml).not_to include("vc:typeAvailable")
|
|
56
|
+
expect(xml).not_to include("vc:facetUnavailable")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
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
|
|
@@ -295,6 +295,7 @@ files:
|
|
|
295
295
|
- docs/_references/instance-serialization.adoc
|
|
296
296
|
- docs/_references/lutaml-namespace-planning.md
|
|
297
297
|
- docs/_references/parent-root-context.adoc
|
|
298
|
+
- docs/_references/plan-schema-spec.adoc
|
|
298
299
|
- docs/_references/rdf-namespaces.adoc
|
|
299
300
|
- docs/_references/reference_type.adoc
|
|
300
301
|
- docs/_references/serialization-model-mappings.adoc
|
|
@@ -752,6 +753,7 @@ files:
|
|
|
752
753
|
- lib/lutaml/model/serializable.rb
|
|
753
754
|
- lib/lutaml/model/serialization_adapter.rb
|
|
754
755
|
- lib/lutaml/model/serialize.rb
|
|
756
|
+
- lib/lutaml/model/serialize/annotations.rb
|
|
755
757
|
- lib/lutaml/model/serialize/attribute_definition.rb
|
|
756
758
|
- lib/lutaml/model/serialize/builder.rb
|
|
757
759
|
- lib/lutaml/model/serialize/conversion_caching.rb
|
|
@@ -1023,13 +1025,16 @@ files:
|
|
|
1023
1025
|
- lib/lutaml/xml/schema/xsd/max_exclusive.rb
|
|
1024
1026
|
- lib/lutaml/xml/schema/xsd/max_inclusive.rb
|
|
1025
1027
|
- lib/lutaml/xml/schema/xsd/max_length.rb
|
|
1028
|
+
- lib/lutaml/xml/schema/xsd/max_scale.rb
|
|
1026
1029
|
- lib/lutaml/xml/schema/xsd/min_exclusive.rb
|
|
1027
1030
|
- lib/lutaml/xml/schema/xsd/min_inclusive.rb
|
|
1028
1031
|
- lib/lutaml/xml/schema/xsd/min_length.rb
|
|
1032
|
+
- lib/lutaml/xml/schema/xsd/min_scale.rb
|
|
1029
1033
|
- lib/lutaml/xml/schema/xsd/namespace_mapping.rb
|
|
1030
1034
|
- lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb
|
|
1031
1035
|
- lib/lutaml/xml/schema/xsd/notation.rb
|
|
1032
1036
|
- lib/lutaml/xml/schema/xsd/open_content.rb
|
|
1037
|
+
- lib/lutaml/xml/schema/xsd/override.rb
|
|
1033
1038
|
- lib/lutaml/xml/schema/xsd/pattern.rb
|
|
1034
1039
|
- lib/lutaml/xml/schema/xsd/redefine.rb
|
|
1035
1040
|
- lib/lutaml/xml/schema/xsd/restriction_complex_content.rb
|
|
@@ -1053,6 +1058,7 @@ files:
|
|
|
1053
1058
|
- lib/lutaml/xml/schema/xsd/unique.rb
|
|
1054
1059
|
- lib/lutaml/xml/schema/xsd/validation_error.rb
|
|
1055
1060
|
- lib/lutaml/xml/schema/xsd/validation_result.rb
|
|
1061
|
+
- lib/lutaml/xml/schema/xsd/vc_conditional_attributes.rb
|
|
1056
1062
|
- lib/lutaml/xml/schema/xsd/version.rb
|
|
1057
1063
|
- lib/lutaml/xml/schema/xsd/white_space.rb
|
|
1058
1064
|
- lib/lutaml/xml/schema/xsd_namespace.rb
|
|
@@ -1971,6 +1977,7 @@ files:
|
|
|
1971
1977
|
- spec/lml/lutaml/lml/has_attributes_spec.rb
|
|
1972
1978
|
- spec/lml/lutaml/lml/import_resolver_spec.rb
|
|
1973
1979
|
- spec/lml/lutaml/lml/instance_hydration_spec.rb
|
|
1980
|
+
- spec/lml/lutaml/lml/json_transfer_spec.rb
|
|
1974
1981
|
- spec/lml/lutaml/lml/lsp/server_spec.rb
|
|
1975
1982
|
- spec/lml/lutaml/lml/model_compiler_spec.rb
|
|
1976
1983
|
- spec/lml/lutaml/lml/models/association_spec.rb
|
|
@@ -2009,6 +2016,7 @@ files:
|
|
|
2009
2016
|
- spec/lml/lutaml/parsers/dsl_spec.rb
|
|
2010
2017
|
- spec/lml/lutaml/parsers/yaml_spec.rb
|
|
2011
2018
|
- spec/lml/lutaml/qualified_type_spec.rb
|
|
2019
|
+
- spec/lml/support/lml_property_support.rb
|
|
2012
2020
|
- spec/lutaml/integration/edge_cases_spec.rb
|
|
2013
2021
|
- spec/lutaml/integration/multi_format_spec.rb
|
|
2014
2022
|
- spec/lutaml/integration/round_trip_spec.rb
|
|
@@ -2028,6 +2036,7 @@ files:
|
|
|
2028
2036
|
- spec/lutaml/model/adapter_resolver_configured_spec.rb
|
|
2029
2037
|
- spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb
|
|
2030
2038
|
- spec/lutaml/model/adapter_type_unset_restore_spec.rb
|
|
2039
|
+
- spec/lutaml/model/annotations_spec.rb
|
|
2031
2040
|
- spec/lutaml/model/any_element_mapping_spec.rb
|
|
2032
2041
|
- spec/lutaml/model/attribute_apply_value_map_spec.rb
|
|
2033
2042
|
- spec/lutaml/model/attribute_collection_spec.rb
|
|
@@ -2415,6 +2424,11 @@ files:
|
|
|
2415
2424
|
- spec/lutaml/xml/schema/xsd/vc_versioning_spec.rb
|
|
2416
2425
|
- spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb
|
|
2417
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
|
|
2431
|
+
- spec/lutaml/xml/schema/xsd_scale_vc_spec.rb
|
|
2418
2432
|
- spec/lutaml/xml/schema_primer_spec.rb
|
|
2419
2433
|
- spec/lutaml/xml/serializable_namespace_spec.rb
|
|
2420
2434
|
- spec/lutaml/xml/shared_element_rules_spec.rb
|