lutaml-model 0.8.183 → 0.8.185
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/serialize/format_conversion.rb +6 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/schema/xsd/alternative.rb +33 -0
- data/lib/lutaml/xml/schema/xsd/assert.rb +31 -0
- data/lib/lutaml/xml/schema/xsd/complex_type.rb +7 -0
- data/lib/lutaml/xml/schema/xsd/element.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/extension_complex_content.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/extension_simple_content.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/open_content.rb +30 -0
- data/lib/lutaml/xml/schema/xsd/restriction_complex_content.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/restriction_simple_content.rb +3 -0
- data/lib/lutaml/xml/schema/xsd.rb +13 -9
- data/spec/lutaml/model/model_declaration_from_xml_spec.rb +77 -0
- data/spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb +120 -0
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b26ea4574929a6043881ef30b2d06dda2f92c1d45ec4c3fd02ccaf6fd960106e
|
|
4
|
+
data.tar.gz: bfdd0d769e016a8b2bb81c5e501e7c4e6da1cf209da9085d5200fab95d21ae20
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 687960e7428c5b0da2ffe6acba59f08a8ccc5e120fb87cd2311f00e1eec8de3f49985046a0411f29736c935e0135189630d68f692b79b6efc58c43d0606ba5ad
|
|
7
|
+
data.tar.gz: 1af00fce805b3d9982a25a8f79b9cac56ee5dbb697284c5080ef15c1e81d1e5759e0b1da8b97206776e852eb7456f245a11634781c0440b6023646af04b95c72
|
|
@@ -201,6 +201,12 @@ module Lutaml
|
|
|
201
201
|
return nil if options.key?(:adapter) || options.key?(:only) ||
|
|
202
202
|
options.key?(:except) || options.key?(:mappings) ||
|
|
203
203
|
options.key?(:register)
|
|
204
|
+
# A declared model class (the `model` macro) is hydrated by the
|
|
205
|
+
# interpretive transformer, which instantiates the declared
|
|
206
|
+
# class and writes through its accessors; the plan hydrator's
|
|
207
|
+
# construction machinery is Serializable-bound and would build
|
|
208
|
+
# the declaring class instead (#1208).
|
|
209
|
+
return nil if model && model != self
|
|
204
210
|
|
|
205
211
|
adapter_name = Lutaml::Model::Config.adapter_for(:xml)
|
|
206
212
|
adapter_name = adapter_name&.name
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Schema
|
|
6
|
+
module Xsd
|
|
7
|
+
# XSD 1.1 conditional type assignment — a type alternative on an
|
|
8
|
+
# element declaration, selected by an XPath test (#1203).
|
|
9
|
+
class Alternative < Base
|
|
10
|
+
attribute :id, :string
|
|
11
|
+
attribute :test, :string
|
|
12
|
+
attribute :type, :string
|
|
13
|
+
attribute :xpath_default_namespace, :string
|
|
14
|
+
attribute :annotation, :annotation
|
|
15
|
+
|
|
16
|
+
xml do
|
|
17
|
+
element "alternative"
|
|
18
|
+
mixed_content
|
|
19
|
+
namespace Lutaml::Xml::Schema::XsdNamespace
|
|
20
|
+
|
|
21
|
+
map_attribute :id, to: :id
|
|
22
|
+
map_attribute :test, to: :test
|
|
23
|
+
map_attribute :type, to: :type
|
|
24
|
+
map_attribute :xpathDefaultNamespace, to: :xpath_default_namespace
|
|
25
|
+
map_element :annotation, to: :annotation
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Lutaml::Xml::Schema::Xsd.register_model(self, :alternative)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Schema
|
|
6
|
+
module Xsd
|
|
7
|
+
# XSD 1.1 assertion — an XPath predicate evaluated against the
|
|
8
|
+
# owning complex type's instance (#1203).
|
|
9
|
+
class Assert < Base
|
|
10
|
+
attribute :id, :string
|
|
11
|
+
attribute :test, :string
|
|
12
|
+
attribute :xpath_default_namespace, :string
|
|
13
|
+
attribute :annotation, :annotation
|
|
14
|
+
|
|
15
|
+
xml do
|
|
16
|
+
element "assert"
|
|
17
|
+
mixed_content
|
|
18
|
+
namespace Lutaml::Xml::Schema::XsdNamespace
|
|
19
|
+
|
|
20
|
+
map_attribute :id, to: :id
|
|
21
|
+
map_attribute :test, to: :test
|
|
22
|
+
map_attribute :xpathDefaultNamespace, to: :xpath_default_namespace
|
|
23
|
+
map_element :annotation, to: :annotation
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Lutaml::Xml::Schema::Xsd.register_model(self, :assert)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -10,6 +10,8 @@ module Lutaml
|
|
|
10
10
|
AnyAttribute
|
|
11
11
|
Annotation
|
|
12
12
|
Attribute
|
|
13
|
+
Assert
|
|
14
|
+
OpenContent
|
|
13
15
|
].freeze
|
|
14
16
|
|
|
15
17
|
attribute :id, :string
|
|
@@ -26,6 +28,9 @@ module Lutaml
|
|
|
26
28
|
attribute :annotation, :annotation
|
|
27
29
|
attribute :simple_content, :simple_content
|
|
28
30
|
attribute :complex_content, :complex_content
|
|
31
|
+
attribute :assert, :assert, collection: true,
|
|
32
|
+
initialize_empty: true
|
|
33
|
+
attribute :open_content, :open_content
|
|
29
34
|
attribute :attribute, :attribute, collection: true,
|
|
30
35
|
initialize_empty: true
|
|
31
36
|
attribute :attribute_group, :attribute_group, collection: true,
|
|
@@ -54,6 +59,8 @@ module Lutaml
|
|
|
54
59
|
map_element :anyAttribute, to: :any_attribute
|
|
55
60
|
map_element :simpleContent, to: :simple_content
|
|
56
61
|
map_element :complexContent, to: :complex_content
|
|
62
|
+
map_element :assert, to: :assert
|
|
63
|
+
map_element :openContent, to: :open_content
|
|
57
64
|
end
|
|
58
65
|
|
|
59
66
|
liquid do
|
|
@@ -25,6 +25,8 @@ module Lutaml
|
|
|
25
25
|
attribute :key, :key, collection: true, initialize_empty: true
|
|
26
26
|
attribute :keyref, :keyref, collection: true, initialize_empty: true
|
|
27
27
|
attribute :unique, :unique, collection: true, initialize_empty: true
|
|
28
|
+
attribute :alternative, :alternative, collection: true,
|
|
29
|
+
initialize_empty: true
|
|
28
30
|
|
|
29
31
|
xml do
|
|
30
32
|
element "element"
|
|
@@ -51,6 +53,7 @@ module Lutaml
|
|
|
51
53
|
map_element :keyref, to: :keyref
|
|
52
54
|
map_element :unique, to: :unique
|
|
53
55
|
map_element :key, to: :key
|
|
56
|
+
map_element :alternative, to: :alternative
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
liquid do
|
|
@@ -12,6 +12,8 @@ module Lutaml
|
|
|
12
12
|
attribute :choice, :choice
|
|
13
13
|
attribute :sequence, :sequence
|
|
14
14
|
attribute :annotation, :annotation
|
|
15
|
+
attribute :assert, :assert, collection: true,
|
|
16
|
+
initialize_empty: true
|
|
15
17
|
attribute :any_attribute, :any_attribute
|
|
16
18
|
attribute :attribute, :attribute, collection: true,
|
|
17
19
|
initialize_empty: true
|
|
@@ -31,6 +33,7 @@ module Lutaml
|
|
|
31
33
|
map_element :sequence, to: :sequence
|
|
32
34
|
map_element :attribute, to: :attribute
|
|
33
35
|
map_element :annotation, to: :annotation
|
|
36
|
+
map_element :assert, to: :assert
|
|
34
37
|
map_element :anyAttribute, to: :any_attribute
|
|
35
38
|
map_element :attributeGroup, to: :attribute_group
|
|
36
39
|
end
|
|
@@ -8,6 +8,8 @@ module Lutaml
|
|
|
8
8
|
attribute :id, :string
|
|
9
9
|
attribute :base, :string
|
|
10
10
|
attribute :annotation, :annotation
|
|
11
|
+
attribute :assert, :assert, collection: true,
|
|
12
|
+
initialize_empty: true
|
|
11
13
|
attribute :any_attribute, :any_attribute
|
|
12
14
|
attribute :attribute, :attribute, collection: true,
|
|
13
15
|
initialize_empty: true
|
|
@@ -23,6 +25,7 @@ module Lutaml
|
|
|
23
25
|
map_attribute :base, to: :base
|
|
24
26
|
map_element :attribute, to: :attribute
|
|
25
27
|
map_element :annotation, to: :annotation
|
|
28
|
+
map_element :assert, to: :assert
|
|
26
29
|
map_element :anyAttribute, to: :any_attribute
|
|
27
30
|
map_element :attributeGroup, to: :attribute_group
|
|
28
31
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Schema
|
|
6
|
+
module Xsd
|
|
7
|
+
# XSD 1.1 open content — relaxes the owning complex type's content
|
|
8
|
+
# model to admit foreign-namespace elements (mode: interleave or
|
|
9
|
+
# suffix) (#1203).
|
|
10
|
+
class OpenContent < Base
|
|
11
|
+
attribute :id, :string
|
|
12
|
+
attribute :mode, :string
|
|
13
|
+
attribute :annotation, :annotation
|
|
14
|
+
|
|
15
|
+
xml do
|
|
16
|
+
element "openContent"
|
|
17
|
+
mixed_content
|
|
18
|
+
namespace Lutaml::Xml::Schema::XsdNamespace
|
|
19
|
+
|
|
20
|
+
map_attribute :id, to: :id
|
|
21
|
+
map_attribute :mode, to: :mode
|
|
22
|
+
map_element :annotation, to: :annotation
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Lutaml::Xml::Schema::Xsd.register_model(self, :open_content)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -12,6 +12,8 @@ module Lutaml
|
|
|
12
12
|
attribute :choice, :choice
|
|
13
13
|
attribute :sequence, :sequence
|
|
14
14
|
attribute :annotation, :annotation
|
|
15
|
+
attribute :assert, :assert, collection: true,
|
|
16
|
+
initialize_empty: true
|
|
15
17
|
attribute :any_attribute, :any_attribute
|
|
16
18
|
attribute :attribute, :attribute, collection: true,
|
|
17
19
|
initialize_empty: true
|
|
@@ -31,6 +33,7 @@ module Lutaml
|
|
|
31
33
|
map_element :sequence, to: :sequence
|
|
32
34
|
map_element :attribute, to: :attribute
|
|
33
35
|
map_element :annotation, to: :annotation
|
|
36
|
+
map_element :assert, to: :assert
|
|
34
37
|
map_element :anyAttribute, to: :any_attribute
|
|
35
38
|
map_element :attributeGroup, to: :attribute_group
|
|
36
39
|
end
|
|
@@ -8,6 +8,8 @@ module Lutaml
|
|
|
8
8
|
attribute :id, :string
|
|
9
9
|
attribute :base, :string
|
|
10
10
|
attribute :annotation, :annotation
|
|
11
|
+
attribute :assert, :assert, collection: true,
|
|
12
|
+
initialize_empty: true
|
|
11
13
|
attribute :simple_type, :simple_type
|
|
12
14
|
attribute :any_attribute, :any_attribute
|
|
13
15
|
attribute :length, :length, collection: true, initialize_empty: true
|
|
@@ -56,6 +58,7 @@ module Lutaml
|
|
|
56
58
|
map_element :simpleType, to: :simple_type
|
|
57
59
|
map_element :whiteSpace, to: :white_space
|
|
58
60
|
map_element :annotation, to: :annotation
|
|
61
|
+
map_element :assert, to: :assert
|
|
59
62
|
map_element :maxLength, to: :max_length
|
|
60
63
|
map_element :minLength, to: :min_length
|
|
61
64
|
map_element :attribute, to: :attribute
|
|
@@ -28,15 +28,16 @@ module Lutaml
|
|
|
28
28
|
# List of all XSD model classes that need to be autoloaded and registered.
|
|
29
29
|
# This is used in parse() to ensure all types are registered before parsing.
|
|
30
30
|
XSD_AUTOLOAD_CLASSES = %i[
|
|
31
|
-
All Annotation Any AnyAttribute Appinfo Attribute
|
|
32
|
-
Choice ComplexContent ComplexType Documentation
|
|
33
|
-
ExtensionComplexContent ExtensionSimpleContent
|
|
34
|
-
Glob Group Import Include Key Keyref Length List
|
|
35
|
-
MaxInclusive MaxLength MinExclusive MinInclusive
|
|
36
|
-
Notation Pattern Redefine
|
|
37
|
-
RestrictionSimpleContent
|
|
38
|
-
Selector Sequence SimpleContent
|
|
39
|
-
WhiteSpace
|
|
31
|
+
All Alternative Annotation Any AnyAttribute Appinfo Assert Attribute
|
|
32
|
+
AttributeGroup Choice ComplexContent ComplexType Documentation
|
|
33
|
+
Element Enumeration ExtensionComplexContent ExtensionSimpleContent
|
|
34
|
+
Field FractionDigits Glob Group Import Include Key Keyref Length List
|
|
35
|
+
MaxExclusive MaxInclusive MaxLength MinExclusive MinInclusive
|
|
36
|
+
MinLength Notation OpenContent Pattern Redefine
|
|
37
|
+
RestrictionComplexContent RestrictionSimpleContent
|
|
38
|
+
RestrictionSimpleType Schema SchemaPath Selector Sequence SimpleContent
|
|
39
|
+
SimpleType TotalDigits Union Unique WhiteSpace
|
|
40
|
+
SchemaFileValidationResults
|
|
40
41
|
].freeze
|
|
41
42
|
|
|
42
43
|
# Autoload all XSD model files (lazy loading)
|
|
@@ -57,10 +58,12 @@ module Lutaml
|
|
|
57
58
|
autoload :SerializedSchema, "#{__dir__}/xsd/serialized_schema"
|
|
58
59
|
autoload :SchemaNameResolver, "#{__dir__}/xsd/schema_name_resolver"
|
|
59
60
|
autoload :All, "#{__dir__}/xsd/all"
|
|
61
|
+
autoload :Alternative, "#{__dir__}/xsd/alternative"
|
|
60
62
|
autoload :Annotation, "#{__dir__}/xsd/annotation"
|
|
61
63
|
autoload :Any, "#{__dir__}/xsd/any"
|
|
62
64
|
autoload :AnyAttribute, "#{__dir__}/xsd/any_attribute"
|
|
63
65
|
autoload :Appinfo, "#{__dir__}/xsd/appinfo"
|
|
66
|
+
autoload :Assert, "#{__dir__}/xsd/assert"
|
|
64
67
|
autoload :Attribute, "#{__dir__}/xsd/attribute"
|
|
65
68
|
autoload :AttributeGroup, "#{__dir__}/xsd/attribute_group"
|
|
66
69
|
autoload :Choice, "#{__dir__}/xsd/choice"
|
|
@@ -73,6 +76,7 @@ module Lutaml
|
|
|
73
76
|
"#{__dir__}/xsd/extension_complex_content"
|
|
74
77
|
autoload :ExtensionSimpleContent,
|
|
75
78
|
"#{__dir__}/xsd/extension_simple_content"
|
|
79
|
+
autoload :OpenContent, "#{__dir__}/xsd/open_content"
|
|
76
80
|
autoload :Field, "#{__dir__}/xsd/field"
|
|
77
81
|
autoload :FractionDigits, "#{__dir__}/xsd/fraction_digits"
|
|
78
82
|
autoload :Glob, "#{__dir__}/xsd/glob"
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "`model` declaration under every XML adapter (#1208)" do
|
|
6
|
+
let(:xml) { "<book><title>Hi</title></book>" }
|
|
7
|
+
|
|
8
|
+
# Mirrors the issue repro: the Serializable class declares `model
|
|
9
|
+
# BookData`; the helpers live on the plain model class.
|
|
10
|
+
let(:build_classes) do
|
|
11
|
+
stub_const("BookData", Class.new do
|
|
12
|
+
attr_accessor :title
|
|
13
|
+
|
|
14
|
+
def shout = title.upcase
|
|
15
|
+
end)
|
|
16
|
+
stub_const("Book", Class.new(Lutaml::Model::Serializable) do
|
|
17
|
+
model BookData
|
|
18
|
+
|
|
19
|
+
attribute :title, :string
|
|
20
|
+
|
|
21
|
+
xml do
|
|
22
|
+
element "book"
|
|
23
|
+
map_element "title", to: :title
|
|
24
|
+
end
|
|
25
|
+
end)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "returns the declared model class on the configured adapter" do
|
|
29
|
+
build_classes
|
|
30
|
+
|
|
31
|
+
book = Book.from_xml(xml)
|
|
32
|
+
|
|
33
|
+
expect(book).to be_a(BookData)
|
|
34
|
+
expect(book.shout).to eq("HI")
|
|
35
|
+
expect(book.title).to eq("Hi")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "returns the declared model class on the leptris lane", if: defined?(Leptris) do
|
|
39
|
+
build_classes
|
|
40
|
+
previous = Lutaml::Model::Config.xml_adapter_type
|
|
41
|
+
Lutaml::Model::Config.xml_adapter_type = :leptris
|
|
42
|
+
|
|
43
|
+
book = Book.from_xml(xml)
|
|
44
|
+
|
|
45
|
+
expect(book).to be_a(BookData)
|
|
46
|
+
expect(book.shout).to eq("HI")
|
|
47
|
+
ensure
|
|
48
|
+
Lutaml::Model::Config.xml_adapter_type = previous
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "returns the declared model class on the nokogiri lane", if: defined?(Nokogiri) do
|
|
52
|
+
build_classes
|
|
53
|
+
previous = Lutaml::Model::Config.xml_adapter_type
|
|
54
|
+
Lutaml::Model::Config.xml_adapter_type = :nokogiri
|
|
55
|
+
|
|
56
|
+
book = Book.from_xml(xml)
|
|
57
|
+
|
|
58
|
+
expect(book).to be_a(BookData)
|
|
59
|
+
expect(book.shout).to eq("HI")
|
|
60
|
+
ensure
|
|
61
|
+
Lutaml::Model::Config.xml_adapter_type = previous
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "round-trips a model-class instance through to_xml" do
|
|
65
|
+
build_classes
|
|
66
|
+
|
|
67
|
+
data = BookData.new
|
|
68
|
+
data.title = "Hi"
|
|
69
|
+
|
|
70
|
+
emitted = Book.to_xml(data)
|
|
71
|
+
expect(emitted).to include("<title>Hi</title>")
|
|
72
|
+
|
|
73
|
+
reparsed = Book.from_xml(emitted)
|
|
74
|
+
expect(reparsed).to be_a(BookData)
|
|
75
|
+
expect(reparsed.title).to eq("Hi")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "XSD 1.1 constructs (#1203)" do
|
|
6
|
+
it "maps xs:assert on a complexType from the parsed XSD" do
|
|
7
|
+
xsd = <<~XSD
|
|
8
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
9
|
+
<xs:complexType name="t">
|
|
10
|
+
<xs:sequence>
|
|
11
|
+
<xs:element name="a" maxOccurs="unbounded"/>
|
|
12
|
+
</xs:sequence>
|
|
13
|
+
<xs:assert test="count(xs:a) > 1"
|
|
14
|
+
xpathDefaultNamespace="##targetNamespace"/>
|
|
15
|
+
</xs:complexType>
|
|
16
|
+
</xs:schema>
|
|
17
|
+
XSD
|
|
18
|
+
|
|
19
|
+
schema = Lutaml::Xml::Schema::Xsd.parse(xsd)
|
|
20
|
+
assert = schema.complex_type.first.assert.first
|
|
21
|
+
|
|
22
|
+
expect(assert).not_to be_nil
|
|
23
|
+
expect(assert.test).to eq("count(xs:a) > 1")
|
|
24
|
+
expect(assert.xpath_default_namespace).to eq("##targetNamespace")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "maps xs:assert inside simpleContent and complexContent " \
|
|
28
|
+
"derivations" do
|
|
29
|
+
xsd = <<~XSD
|
|
30
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
31
|
+
<xs:complexType name="simple">
|
|
32
|
+
<xs:simpleContent>
|
|
33
|
+
<xs:extension base="xs:string">
|
|
34
|
+
<xs:assert test="string-length(.) > 0"/>
|
|
35
|
+
</xs:extension>
|
|
36
|
+
</xs:simpleContent>
|
|
37
|
+
</xs:complexType>
|
|
38
|
+
<xs:complexType name="complex">
|
|
39
|
+
<xs:complexContent>
|
|
40
|
+
<xs:restriction base="xs:anyType">
|
|
41
|
+
<xs:assert test="true()"/>
|
|
42
|
+
</xs:restriction>
|
|
43
|
+
</xs:complexContent>
|
|
44
|
+
</xs:complexType>
|
|
45
|
+
</xs:schema>
|
|
46
|
+
XSD
|
|
47
|
+
|
|
48
|
+
schema = Lutaml::Xml::Schema::Xsd.parse(xsd)
|
|
49
|
+
simple = schema.complex_type.find { |t| t.name == "simple" }
|
|
50
|
+
complex = schema.complex_type.find { |t| t.name == "complex" }
|
|
51
|
+
|
|
52
|
+
expect(simple.simple_content.extension.assert.first.test)
|
|
53
|
+
.to eq("string-length(.) > 0")
|
|
54
|
+
expect(complex.complex_content.restriction.assert.first.test)
|
|
55
|
+
.to eq("true()")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "maps xs:openContent on a complexType" do
|
|
59
|
+
xsd = <<~XSD
|
|
60
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
61
|
+
<xs:complexType name="t">
|
|
62
|
+
<xs:sequence>
|
|
63
|
+
<xs:element name="a"/>
|
|
64
|
+
</xs:sequence>
|
|
65
|
+
<xs:openContent mode="suffix"/>
|
|
66
|
+
</xs:complexType>
|
|
67
|
+
</xs:schema>
|
|
68
|
+
XSD
|
|
69
|
+
|
|
70
|
+
schema = Lutaml::Xml::Schema::Xsd.parse(xsd)
|
|
71
|
+
open_content = schema.complex_type.first.open_content
|
|
72
|
+
|
|
73
|
+
expect(open_content).not_to be_nil
|
|
74
|
+
expect(open_content.mode).to eq("suffix")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "maps xs:alternative on an element declaration" do
|
|
78
|
+
xsd = <<~XSD
|
|
79
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
80
|
+
<xs:element name="shape">
|
|
81
|
+
<xs:alternative test="@kind='circle'" type="CircleType"
|
|
82
|
+
xpathDefaultNamespace="##targetNamespace"/>
|
|
83
|
+
<xs:alternative type="DefaultType"/>
|
|
84
|
+
</xs:element>
|
|
85
|
+
</xs:schema>
|
|
86
|
+
XSD
|
|
87
|
+
|
|
88
|
+
schema = Lutaml::Xml::Schema::Xsd.parse(xsd)
|
|
89
|
+
alternatives = schema.element.first.alternative
|
|
90
|
+
|
|
91
|
+
expect(alternatives.map(&:type)).to eq(%w[CircleType DefaultType])
|
|
92
|
+
expect(alternatives.first.test).to eq("@kind='circle'")
|
|
93
|
+
expect(alternatives.first.xpath_default_namespace)
|
|
94
|
+
.to eq("##targetNamespace")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "round-trips the constructs through to_xml" do
|
|
98
|
+
xsd = <<~XSD
|
|
99
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
100
|
+
<xs:complexType name="t">
|
|
101
|
+
<xs:openContent mode="interleave"/>
|
|
102
|
+
<xs:assert test="true()"/>
|
|
103
|
+
</xs:complexType>
|
|
104
|
+
<xs:element name="e">
|
|
105
|
+
<xs:alternative test="@k='v'" type="T"/>
|
|
106
|
+
</xs:element>
|
|
107
|
+
</xs:schema>
|
|
108
|
+
XSD
|
|
109
|
+
|
|
110
|
+
schema = Lutaml::Xml::Schema::Xsd.parse(xsd)
|
|
111
|
+
emitted = schema.to_xml
|
|
112
|
+
|
|
113
|
+
expect(emitted).to include("<xs:assert")
|
|
114
|
+
expect(emitted).to include('test="true()"')
|
|
115
|
+
expect(emitted).to include("<xs:openContent")
|
|
116
|
+
expect(emitted).to include('mode="interleave"')
|
|
117
|
+
expect(emitted).to include("<xs:alternative")
|
|
118
|
+
expect(emitted).to include('type="T"')
|
|
119
|
+
end
|
|
120
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.185
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -883,10 +883,12 @@ files:
|
|
|
883
883
|
- lib/lutaml/xml/schema/relaxng_schema.rb
|
|
884
884
|
- lib/lutaml/xml/schema/xsd.rb
|
|
885
885
|
- lib/lutaml/xml/schema/xsd/all.rb
|
|
886
|
+
- lib/lutaml/xml/schema/xsd/alternative.rb
|
|
886
887
|
- lib/lutaml/xml/schema/xsd/annotation.rb
|
|
887
888
|
- lib/lutaml/xml/schema/xsd/any.rb
|
|
888
889
|
- lib/lutaml/xml/schema/xsd/any_attribute.rb
|
|
889
890
|
- lib/lutaml/xml/schema/xsd/appinfo.rb
|
|
891
|
+
- lib/lutaml/xml/schema/xsd/assert.rb
|
|
890
892
|
- lib/lutaml/xml/schema/xsd/attribute.rb
|
|
891
893
|
- lib/lutaml/xml/schema/xsd/attribute_group.rb
|
|
892
894
|
- lib/lutaml/xml/schema/xsd/base.rb
|
|
@@ -925,6 +927,7 @@ files:
|
|
|
925
927
|
- lib/lutaml/xml/schema/xsd/namespace_mapping.rb
|
|
926
928
|
- lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb
|
|
927
929
|
- lib/lutaml/xml/schema/xsd/notation.rb
|
|
930
|
+
- lib/lutaml/xml/schema/xsd/open_content.rb
|
|
928
931
|
- lib/lutaml/xml/schema/xsd/pattern.rb
|
|
929
932
|
- lib/lutaml/xml/schema/xsd/redefine.rb
|
|
930
933
|
- lib/lutaml/xml/schema/xsd/restriction_complex_content.rb
|
|
@@ -1849,6 +1852,7 @@ files:
|
|
|
1849
1852
|
- spec/lutaml/model/mapping_type_validation_spec.rb
|
|
1850
1853
|
- spec/lutaml/model/metaschema_types_spec.rb
|
|
1851
1854
|
- spec/lutaml/model/mixed_content_spec.rb
|
|
1855
|
+
- spec/lutaml/model/model_declaration_from_xml_spec.rb
|
|
1852
1856
|
- spec/lutaml/model/model_import_reentry_spec.rb
|
|
1853
1857
|
- spec/lutaml/model/model_transformer_spec.rb
|
|
1854
1858
|
- spec/lutaml/model/multiple_mapping_spec.rb
|
|
@@ -2129,6 +2133,7 @@ files:
|
|
|
2129
2133
|
- spec/lutaml/xml/schema/xsd/unresolvable_schema_location_spec.rb
|
|
2130
2134
|
- spec/lutaml/xml/schema/xsd/validation_error_spec.rb
|
|
2131
2135
|
- spec/lutaml/xml/schema/xsd/validation_result_spec.rb
|
|
2136
|
+
- spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb
|
|
2132
2137
|
- spec/lutaml/xml/schema/xsd/xsd_spec.rb
|
|
2133
2138
|
- spec/lutaml/xml/schema_primer_spec.rb
|
|
2134
2139
|
- spec/lutaml/xml/serializable_namespace_spec.rb
|