lutaml-model 0.8.178 → 0.8.180
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/Gemfile +5 -2
- data/lib/compat/opal/lutaml_model_boot.rb +7 -0
- data/lib/lutaml/model/schema/xml_compiler/supported_data_types.rb +3 -0
- data/lib/lutaml/model/type/g_day.rb +32 -0
- data/lib/lutaml/model/type/g_month.rb +31 -0
- data/lib/lutaml/model/type/g_month_day.rb +32 -0
- data/lib/lutaml/model/type/g_year.rb +32 -0
- data/lib/lutaml/model/type/g_year_month.rb +32 -0
- data/lib/lutaml/model/type/id_refs.rb +33 -0
- data/lib/lutaml/model/type/nm_tokens.rb +33 -0
- data/lib/lutaml/model/type.rb +16 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/xsd_validator.rb +11 -4
- data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +112 -0
- data/spec/lutaml/xml/validate_xml_with_constructs_spec.rb +4 -11
- data/spec/lutaml/xml/validate_xml_with_spec.rb +5 -3
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e923a0e0792f0329e8bd5f4008d17baa30e80f4622f772d1b877c0ec13952c8b
|
|
4
|
+
data.tar.gz: a59f92e90c98a6d0f1e77016616486be237c61db69410f1e412d1f91864d6345
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86d5ec47de95898724f2517e9d206a7e027baa85178b0312de4f1f3aa4fc477d4ac4c77948c1a36c91187c3597b5d22a00c789c3adb23f0500f11ddc5cf2ae16
|
|
7
|
+
data.tar.gz: 28abd3d0802117bfe05b9c5f825f825fc962c2aaa091b9eccfc2003bdcf60f011a629227d8a580743f7efb3400fcddebbf6e65c0a8d90ce897173e06e4ed0b94
|
data/Gemfile
CHANGED
|
@@ -48,8 +48,11 @@ gem "rexml"
|
|
|
48
48
|
# (see Lutaml::Xml::Leptris::MIN_LEPTRIS_VERSION) — child snapshots,
|
|
49
49
|
# exact-URI attribute rows, nested-attribute capture, wildcard rows,
|
|
50
50
|
# walk-side ns retention and leniency, :unqualified rows, and the
|
|
51
|
-
# address-based text attach all ride it.
|
|
52
|
-
|
|
51
|
+
# address-based text attach all ride it. The dev floor additionally
|
|
52
|
+
# pins the XSD lane's targetNamespace qualification (leptris#2158,
|
|
53
|
+
# first shipped in 1.9.443.0) so CI validates against the enforcing
|
|
54
|
+
# engine; consumer runtime support stays at MIN_LEPTRIS_VERSION.
|
|
55
|
+
gem "leptris", ">= 1.9.443.0" # dev floor: RAW op (leptris#1941) capability line plus the XSD targetNamespace enforcement (leptris#2158); MIN_LEPTRIS_VERSION stays 1.9.406.0 for consumers, and the emission lane additionally version-gates namespaced trees to >= 1.9.407.0 (attr ns_prefix deep-copy, leptris#1967/#1968)
|
|
53
56
|
gem "teptris"
|
|
54
57
|
gem "yeptris" unless Gem.win_platform?
|
|
55
58
|
# TODO: revert rng branch to main when lutaml/rng#32 is merged
|
|
@@ -346,13 +346,20 @@ require "lutaml/model/type/decimal"
|
|
|
346
346
|
require "lutaml/model/type/duration"
|
|
347
347
|
require "lutaml/model/type/email_address"
|
|
348
348
|
require "lutaml/model/type/float"
|
|
349
|
+
require "lutaml/model/type/g_day"
|
|
350
|
+
require "lutaml/model/type/g_month"
|
|
351
|
+
require "lutaml/model/type/g_month_day"
|
|
352
|
+
require "lutaml/model/type/g_year"
|
|
353
|
+
require "lutaml/model/type/g_year_month"
|
|
349
354
|
require "lutaml/model/type/hash"
|
|
350
355
|
require "lutaml/model/type/hex_binary"
|
|
351
356
|
require "lutaml/model/type/hostname"
|
|
357
|
+
require "lutaml/model/type/id_refs"
|
|
352
358
|
require "lutaml/model/type/integer"
|
|
353
359
|
require "lutaml/model/type/ip_v4_address"
|
|
354
360
|
require "lutaml/model/type/ip_v6_address"
|
|
355
361
|
require "lutaml/model/type/metaschema_pattern"
|
|
362
|
+
require "lutaml/model/type/nm_tokens"
|
|
356
363
|
require "lutaml/model/type/non_negative_integer"
|
|
357
364
|
require "lutaml/model/type/positive_integer"
|
|
358
365
|
require "lutaml/model/type/qname"
|
|
@@ -112,6 +112,9 @@ module Lutaml
|
|
|
112
112
|
# when the name is not a skippable built-in.
|
|
113
113
|
def primitive_symbol(value)
|
|
114
114
|
info = TABLE[value.to_sym]
|
|
115
|
+
info ||= TABLE.find do |name, _|
|
|
116
|
+
Utils.snake_case(name.to_s) == value.to_s
|
|
117
|
+
end&.last
|
|
115
118
|
return nil unless info && info[:skippable]
|
|
116
119
|
|
|
117
120
|
Utils.snake_case(info[:class_name].split("::").last)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Type
|
|
6
|
+
# XML Schema gDay datatype: a recurring calendar day of month —
|
|
7
|
+
# ---24, ---24Z, ---24+05:30.
|
|
8
|
+
#
|
|
9
|
+
# @example Using GDay type
|
|
10
|
+
# attribute :closes_on, :g_day
|
|
11
|
+
class GDay < String
|
|
12
|
+
PATTERN = /\A---(?:0[1-9]|[12]\d|3[01])(Z|[+-]\d{2}:\d{2})?\z/
|
|
13
|
+
|
|
14
|
+
def self.cast(value, _options = EMPTY_OPTIONS)
|
|
15
|
+
value&.to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.valid?(value)
|
|
19
|
+
value.is_a?(::String) ? value.match?(PATTERN) : !cast(value).nil?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.json_schema_format
|
|
23
|
+
"gday"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.default_xsd_type
|
|
27
|
+
"xs:gDay"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Type
|
|
6
|
+
# XML Schema gMonth datatype: a calendar month — --11, --11Z, --11+05:30.
|
|
7
|
+
#
|
|
8
|
+
# @example Using GMonth type
|
|
9
|
+
# attribute :renews_in, :g_month
|
|
10
|
+
class GMonth < String
|
|
11
|
+
PATTERN = /\A--(?:0[1-9]|1[0-2])(Z|[+-]\d{2}:\d{2})?\z/
|
|
12
|
+
|
|
13
|
+
def self.cast(value, _options = EMPTY_OPTIONS)
|
|
14
|
+
value&.to_s
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.valid?(value)
|
|
18
|
+
value.is_a?(::String) ? value.match?(PATTERN) : !cast(value).nil?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.json_schema_format
|
|
22
|
+
"gmonth"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.default_xsd_type
|
|
26
|
+
"xs:gMonth"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Type
|
|
6
|
+
# XML Schema gMonthDay datatype: a recurring calendar day —
|
|
7
|
+
# --11-24, --11-24Z, --11-24+05:30.
|
|
8
|
+
#
|
|
9
|
+
# @example Using GMonthDay type
|
|
10
|
+
# attribute :anniversary, :g_month_day
|
|
11
|
+
class GMonthDay < String
|
|
12
|
+
PATTERN = /\A--(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])(Z|[+-]\d{2}:\d{2})?\z/
|
|
13
|
+
|
|
14
|
+
def self.cast(value, _options = EMPTY_OPTIONS)
|
|
15
|
+
value&.to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.valid?(value)
|
|
19
|
+
value.is_a?(::String) ? value.match?(PATTERN) : !cast(value).nil?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.json_schema_format
|
|
23
|
+
"gmonthday"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.default_xsd_type
|
|
27
|
+
"xs:gMonthDay"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Type
|
|
6
|
+
# XML Schema gYear datatype: a calendar year — 2026, 0942, 2026Z,
|
|
7
|
+
# 2026+05:30.
|
|
8
|
+
#
|
|
9
|
+
# @example Using GYear type
|
|
10
|
+
# attribute :reported, :g_year
|
|
11
|
+
class GYear < String
|
|
12
|
+
PATTERN = /\A-?\d{4,}(Z|[+-]\d{2}:\d{2})?\z/
|
|
13
|
+
|
|
14
|
+
def self.cast(value, _options = EMPTY_OPTIONS)
|
|
15
|
+
value&.to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.valid?(value)
|
|
19
|
+
value.is_a?(::String) ? value.match?(PATTERN) : !cast(value).nil?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.json_schema_format
|
|
23
|
+
"gyear"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.default_xsd_type
|
|
27
|
+
"xs:gYear"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Type
|
|
6
|
+
# XML Schema gYearMonth datatype: a calendar year and month —
|
|
7
|
+
# 2026-11, 0942-01Z, 2026-11+05:30.
|
|
8
|
+
#
|
|
9
|
+
# @example Using GYearMonth type
|
|
10
|
+
# attribute :issued, :g_year_month
|
|
11
|
+
class GYearMonth < String
|
|
12
|
+
PATTERN = /\A-?\d{4,}-(?:0[1-9]|1[0-2])(Z|[+-]\d{2}:\d{2})?\z/
|
|
13
|
+
|
|
14
|
+
def self.cast(value, _options = EMPTY_OPTIONS)
|
|
15
|
+
value&.to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.valid?(value)
|
|
19
|
+
value.is_a?(::String) ? value.match?(PATTERN) : !cast(value).nil?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.json_schema_format
|
|
23
|
+
"gyearmonth"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.default_xsd_type
|
|
27
|
+
"xs:gYearMonth"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Type
|
|
6
|
+
# XML Schema IDREFS datatype: a whitespace-separated list of IDREF
|
|
7
|
+
# values — "a1 b2", "a1".
|
|
8
|
+
#
|
|
9
|
+
# @example Using IdRefs type
|
|
10
|
+
# attribute :see_also, :idrefs
|
|
11
|
+
class IdRefs < String
|
|
12
|
+
IDREF = /[a-zA-Z_][\w.-]*/
|
|
13
|
+
PATTERN = /\A#{IDREF}(?:\s+#{IDREF})*\z/
|
|
14
|
+
|
|
15
|
+
def self.cast(value, _options = EMPTY_OPTIONS)
|
|
16
|
+
value&.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.valid?(value)
|
|
20
|
+
value.is_a?(::String) ? value.match?(PATTERN) : !cast(value).nil?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.json_schema_format
|
|
24
|
+
"idrefs"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.default_xsd_type
|
|
28
|
+
"xs:IDREFS"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Type
|
|
6
|
+
# XML Schema NMTOKENS datatype: a whitespace-separated list of
|
|
7
|
+
# NMTOKEN values — "en-US de-DE", "en-US".
|
|
8
|
+
#
|
|
9
|
+
# @example Using NmTokens type
|
|
10
|
+
# attribute :locales, :nmtokens
|
|
11
|
+
class NmTokens < String
|
|
12
|
+
NMTOKEN = /[\w.:-]+/
|
|
13
|
+
PATTERN = /\A#{NMTOKEN}(?:\s+#{NMTOKEN})*\z/
|
|
14
|
+
|
|
15
|
+
def self.cast(value, _options = EMPTY_OPTIONS)
|
|
16
|
+
value&.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.valid?(value)
|
|
20
|
+
value.is_a?(::String) ? value.match?(PATTERN) : !cast(value).nil?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.json_schema_format
|
|
24
|
+
"nmtokens"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.default_xsd_type
|
|
28
|
+
"xs:NMTOKENS"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/lutaml/model/type.rb
CHANGED
|
@@ -38,6 +38,13 @@ module Lutaml
|
|
|
38
38
|
autoload :DateTimeWithTimezone, "#{__dir__}/type/date_time_with_timezone"
|
|
39
39
|
autoload :DayTimeDuration, "#{__dir__}/type/day_time_duration"
|
|
40
40
|
autoload :YearMonthDuration, "#{__dir__}/type/year_month_duration"
|
|
41
|
+
autoload :GYear, "#{__dir__}/type/g_year"
|
|
42
|
+
autoload :GYearMonth, "#{__dir__}/type/g_year_month"
|
|
43
|
+
autoload :GMonth, "#{__dir__}/type/g_month"
|
|
44
|
+
autoload :GMonthDay, "#{__dir__}/type/g_month_day"
|
|
45
|
+
autoload :GDay, "#{__dir__}/type/g_day"
|
|
46
|
+
autoload :IdRefs, "#{__dir__}/type/id_refs"
|
|
47
|
+
autoload :NmTokens, "#{__dir__}/type/nm_tokens"
|
|
41
48
|
|
|
42
49
|
# Error classes (defined in error/type/ but under Type namespace)
|
|
43
50
|
autoload :InvalidValueError, "#{__dir__}/error/type/invalid_value_error"
|
|
@@ -55,6 +62,7 @@ module Lutaml
|
|
|
55
62
|
integer: "Lutaml::Model::Type::Integer",
|
|
56
63
|
float: "Lutaml::Model::Type::Float",
|
|
57
64
|
double: "Lutaml::Model::Type::Float",
|
|
65
|
+
int: "Lutaml::Model::Type::Integer",
|
|
58
66
|
decimal: "Lutaml::Model::Type::Decimal",
|
|
59
67
|
date: "Lutaml::Model::Type::Date",
|
|
60
68
|
time: "Lutaml::Model::Type::Time",
|
|
@@ -67,6 +75,9 @@ module Lutaml
|
|
|
67
75
|
duration: "Lutaml::Model::Type::Duration",
|
|
68
76
|
uri: "Lutaml::Model::Type::Uri",
|
|
69
77
|
qname: "Lutaml::Model::Type::QName",
|
|
78
|
+
q_name: "Lutaml::Model::Type::QName",
|
|
79
|
+
idrefs: "Lutaml::Model::Type::IdRefs",
|
|
80
|
+
nmtokens: "Lutaml::Model::Type::NmTokens",
|
|
70
81
|
base64_binary: "Lutaml::Model::Type::Base64Binary",
|
|
71
82
|
hex_binary: "Lutaml::Model::Type::HexBinary",
|
|
72
83
|
email_address: "Lutaml::Model::Type::EmailAddress",
|
|
@@ -82,6 +93,11 @@ module Lutaml
|
|
|
82
93
|
date_time_with_timezone: "Lutaml::Model::Type::DateTimeWithTimezone",
|
|
83
94
|
day_time_duration: "Lutaml::Model::Type::DayTimeDuration",
|
|
84
95
|
year_month_duration: "Lutaml::Model::Type::YearMonthDuration",
|
|
96
|
+
g_year: "Lutaml::Model::Type::GYear",
|
|
97
|
+
g_year_month: "Lutaml::Model::Type::GYearMonth",
|
|
98
|
+
g_month: "Lutaml::Model::Type::GMonth",
|
|
99
|
+
g_month_day: "Lutaml::Model::Type::GMonthDay",
|
|
100
|
+
g_day: "Lutaml::Model::Type::GDay",
|
|
85
101
|
}.freeze
|
|
86
102
|
|
|
87
103
|
BUILTIN_CLASSES =
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -11,9 +11,7 @@ module Lutaml
|
|
|
11
11
|
# on the CONFIGURED engine — `Moxml::XSD.supported?` answers without
|
|
12
12
|
# raising, and engines without a validator (ox, oga, rexml) fall back
|
|
13
13
|
# to the historical Nokogiri path, keeping its requirement error when
|
|
14
|
-
# the gem is absent. The leptris engine carries a validator
|
|
15
|
-
# pending targetNamespace-enforcement gap tracked upstream
|
|
16
|
-
# (leptris/leptris-ruby#679).
|
|
14
|
+
# the gem is absent. The leptris engine carries a validator.
|
|
17
15
|
#
|
|
18
16
|
# Strict parsing: libxml2 recovery would otherwise repair malformed
|
|
19
17
|
# input and report it as schema-valid. Malformed input raises
|
|
@@ -87,7 +85,16 @@ module Lutaml
|
|
|
87
85
|
end
|
|
88
86
|
|
|
89
87
|
def self.schema_for(path)
|
|
90
|
-
@schemas.compute_if_absent(path)
|
|
88
|
+
@schemas.compute_if_absent(path) do
|
|
89
|
+
# One error contract across lanes: engines with file-based
|
|
90
|
+
# compilation (leptris) read the schema themselves and would
|
|
91
|
+
# surface their own error for a missing path; checking here
|
|
92
|
+
# keeps the missing-schema case a plain Errno::ENOENT on
|
|
93
|
+
# every engine.
|
|
94
|
+
raise Errno::ENOENT, path unless File.exist?(path)
|
|
95
|
+
|
|
96
|
+
context.xsd_file(path)
|
|
97
|
+
end
|
|
91
98
|
end
|
|
92
99
|
|
|
93
100
|
def self.ensure_nokogiri!
|
|
@@ -167,4 +167,116 @@ RSpec.describe "runtime XSD class loading" do
|
|
|
167
167
|
expect(minimal.note).to be_nil
|
|
168
168
|
end
|
|
169
169
|
end
|
|
170
|
+
|
|
171
|
+
describe "snake-spelled builtin union members" do
|
|
172
|
+
let(:xsd) do
|
|
173
|
+
<<~XSD
|
|
174
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
175
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
176
|
+
<xs:simpleType name="dateOrYear">
|
|
177
|
+
<xs:union memberTypes="xs:date xs:gYearMonth xs:gYear"/>
|
|
178
|
+
</xs:simpleType>
|
|
179
|
+
<xs:complexType name="StampType">
|
|
180
|
+
<xs:sequence>
|
|
181
|
+
<xs:element name="when" type="dateOrYear"/>
|
|
182
|
+
</xs:sequence>
|
|
183
|
+
</xs:complexType>
|
|
184
|
+
<xs:element name="stamp" type="StampType"/>
|
|
185
|
+
</xs:schema>
|
|
186
|
+
XSD
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it "resolves union memberTypes against the table in either spelling" do
|
|
190
|
+
sources = Lutaml::Model::Schema.from_xml(
|
|
191
|
+
xsd, output_dir: "snake_builtin_models", load_classes: true
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
stamp_source = sources.values.find { |src| src.include?("StampType") }
|
|
195
|
+
expect(stamp_source).not_to include("g_year_month")
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
describe "g-date types" do
|
|
200
|
+
it "registers :g_year_month so relaton-style models parse" do
|
|
201
|
+
expect(Lutaml::Model::Type::GYearMonth.cast("2026-11")).to eq("2026-11")
|
|
202
|
+
expect(Lutaml::Model::Type::TYPE_CODES).to include(:g_year_month)
|
|
203
|
+
expect(Lutaml::Model::Type::TYPE_CODES[:g_year_month])
|
|
204
|
+
.to eq("Lutaml::Model::Type::GYearMonth")
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it "validates the lexical forms" do
|
|
208
|
+
expect(Lutaml::Model::Type::GYearMonth.valid?("2026-11")).to be(true)
|
|
209
|
+
expect(Lutaml::Model::Type::GYearMonth.valid?("2026-13")).to be(false)
|
|
210
|
+
expect(Lutaml::Model::Type::GYear.valid?("0942")).to be(true)
|
|
211
|
+
expect(Lutaml::Model::Type::GDay.valid?("---24")).to be(true)
|
|
212
|
+
expect(Lutaml::Model::Type::GDay.valid?("24")).to be(false)
|
|
213
|
+
expect(Lutaml::Model::Type::GMonthDay.valid?("--11-24")).to be(true)
|
|
214
|
+
expect(Lutaml::Model::Type::GMonth.valid?("--11")).to be(true)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# The union builder blanket-snakes member names, so every skippable
|
|
219
|
+
# builtin spelling that a union can carry must resolve to a registered
|
|
220
|
+
# type — #1190 covers the four the g-date work left out.
|
|
221
|
+
describe "union members over the remaining skippable builtins" do
|
|
222
|
+
{
|
|
223
|
+
"xs:int" => ["int", "<rint><v>42</v></rint>", 42],
|
|
224
|
+
"xs:QName" => ["qname", "<rqname><v>p:foo</v></rqname>", "p:foo"],
|
|
225
|
+
"xs:IDREFS" => ["idrefs", "<ridrefs><v>a1 b2</v></ridrefs>", "a1 b2"],
|
|
226
|
+
"xs:NMTOKENS" => ["nmtokens", "<rnmtokens><v>a1 b2</v></rnmtokens>",
|
|
227
|
+
"a1 b2"],
|
|
228
|
+
}.each do |member, (suffix, xml, expected)|
|
|
229
|
+
it "resolves a #{member} union member and parses an instance" do
|
|
230
|
+
xsd = <<~XSD
|
|
231
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
232
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
233
|
+
<xs:simpleType name="u#{suffix}">
|
|
234
|
+
<xs:union memberTypes="#{member}"/>
|
|
235
|
+
</xs:simpleType>
|
|
236
|
+
<xs:complexType name="T#{suffix}">
|
|
237
|
+
<xs:sequence>
|
|
238
|
+
<xs:element name="v" type="u#{suffix}"/>
|
|
239
|
+
</xs:sequence>
|
|
240
|
+
</xs:complexType>
|
|
241
|
+
<xs:element name="r#{suffix}" type="T#{suffix}"/>
|
|
242
|
+
</xs:schema>
|
|
243
|
+
XSD
|
|
244
|
+
dir = "union_#{suffix}_models"
|
|
245
|
+
Lutaml::Model::Schema.from_xml(
|
|
246
|
+
xsd, output_dir: dir, load_classes: true
|
|
247
|
+
)
|
|
248
|
+
namespace = dir.split("_").map(&:capitalize).join
|
|
249
|
+
|
|
250
|
+
parsed = Object.const_get("#{namespace}::T#{suffix}").from_xml(xml)
|
|
251
|
+
|
|
252
|
+
expect(parsed.v).to eq(expected)
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
describe "builtin list spellings and aliases" do
|
|
258
|
+
it "registers the union-facing symbols" do
|
|
259
|
+
codes = Lutaml::Model::Type::TYPE_CODES
|
|
260
|
+
|
|
261
|
+
expect(codes[:int]).to eq("Lutaml::Model::Type::Integer")
|
|
262
|
+
expect(codes[:q_name]).to eq("Lutaml::Model::Type::QName")
|
|
263
|
+
expect(codes[:idrefs]).to eq("Lutaml::Model::Type::IdRefs")
|
|
264
|
+
expect(codes[:nmtokens]).to eq("Lutaml::Model::Type::NmTokens")
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it "validates the IDREFS lexical form" do
|
|
268
|
+
expect(Lutaml::Model::Type::IdRefs.valid?("a1")).to be(true)
|
|
269
|
+
expect(Lutaml::Model::Type::IdRefs.valid?("a1 b2")).to be(true)
|
|
270
|
+
expect(Lutaml::Model::Type::IdRefs.valid?("1a b2")).to be(false)
|
|
271
|
+
expect(Lutaml::Model::Type::IdRefs.valid?("a1,b2")).to be(false)
|
|
272
|
+
expect(Lutaml::Model::Type::IdRefs.valid?("")).to be(false)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it "validates the NMTOKENS lexical form" do
|
|
276
|
+
expect(Lutaml::Model::Type::NmTokens.valid?("en-US")).to be(true)
|
|
277
|
+
expect(Lutaml::Model::Type::NmTokens.valid?("en-US de-DE")).to be(true)
|
|
278
|
+
expect(Lutaml::Model::Type::NmTokens.valid?("en US,fr")).to be(false)
|
|
279
|
+
expect(Lutaml::Model::Type::NmTokens.valid?("")).to be(false)
|
|
280
|
+
end
|
|
281
|
+
end
|
|
170
282
|
end
|
|
@@ -91,8 +91,11 @@ RSpec.describe "validate_xml_with XSD constructs" do
|
|
|
91
91
|
it "collects missing required attribute violations" do
|
|
92
92
|
errors = product(id: nil).validate
|
|
93
93
|
|
|
94
|
+
# Engines phrase the violation differently ("attribute 'id' is
|
|
95
|
+
# required" on the nokogiri lane, "attribute 'id': required but
|
|
96
|
+
# absent" on the leptris lane); the assertion stays phrasing-neutral.
|
|
94
97
|
expect(errors.map(&:message)).to include(
|
|
95
|
-
a_string_including("
|
|
98
|
+
a_string_including("id", "required"),
|
|
96
99
|
)
|
|
97
100
|
end
|
|
98
101
|
|
|
@@ -185,16 +188,6 @@ RSpec.describe "validate_xml_with XSD constructs" do
|
|
|
185
188
|
end
|
|
186
189
|
|
|
187
190
|
it "rejects a document missing the target namespace" do
|
|
188
|
-
# leptris's XSD compiler does not yet enforce targetNamespace
|
|
189
|
-
# qualification (leptris/leptris-ruby#679); the cell gates on the
|
|
190
|
-
# engine until the engine fix lands. The default nokogiri lane
|
|
191
|
-
# enforces it and runs the assertion.
|
|
192
|
-
engine = Lutaml::Model::Config.xml_adapter_type&.to_s
|
|
193
|
-
if engine == "leptris"
|
|
194
|
-
skip "leptris targetNamespace enforcement pending " \
|
|
195
|
-
"leptris/leptris-ruby#679"
|
|
196
|
-
end
|
|
197
|
-
|
|
198
191
|
xml = "<address><city>Berlin</city></address>"
|
|
199
192
|
|
|
200
193
|
expect(XsdNamespacedDoc.validate_xml(xml)).not_to be_empty
|
|
@@ -85,12 +85,14 @@ RSpec.describe "validate_xml_with" do
|
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
# Malformed input raises instead of recovering; the error class is
|
|
88
|
-
# moxml's normalized ParseError (engine-independent
|
|
89
|
-
#
|
|
88
|
+
# moxml's normalized ParseError (engine-independent) now that
|
|
89
|
+
# validation routes through the moxml layer (#1184). The position
|
|
90
|
+
# format is engine-specific (libxml2 reports a line, leptris a byte
|
|
91
|
+
# offset), so the assertion accepts either.
|
|
90
92
|
it "raises a parse error for malformed XML instead of recovering" do
|
|
91
93
|
expect do
|
|
92
94
|
XsdValidatedPerson.validate_xml("<person><name>Alice</name>")
|
|
93
|
-
end.to raise_error(Moxml::ParseError, /Line:
|
|
95
|
+
end.to raise_error(Moxml::ParseError, /Line: \d+|byte \d+/)
|
|
94
96
|
end
|
|
95
97
|
end
|
|
96
98
|
|
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.180
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -674,13 +674,20 @@ files:
|
|
|
674
674
|
- lib/lutaml/model/type/duration.rb
|
|
675
675
|
- lib/lutaml/model/type/email_address.rb
|
|
676
676
|
- lib/lutaml/model/type/float.rb
|
|
677
|
+
- lib/lutaml/model/type/g_day.rb
|
|
678
|
+
- lib/lutaml/model/type/g_month.rb
|
|
679
|
+
- lib/lutaml/model/type/g_month_day.rb
|
|
680
|
+
- lib/lutaml/model/type/g_year.rb
|
|
681
|
+
- lib/lutaml/model/type/g_year_month.rb
|
|
677
682
|
- lib/lutaml/model/type/hash.rb
|
|
678
683
|
- lib/lutaml/model/type/hex_binary.rb
|
|
679
684
|
- lib/lutaml/model/type/hostname.rb
|
|
685
|
+
- lib/lutaml/model/type/id_refs.rb
|
|
680
686
|
- lib/lutaml/model/type/integer.rb
|
|
681
687
|
- lib/lutaml/model/type/ip_v4_address.rb
|
|
682
688
|
- lib/lutaml/model/type/ip_v6_address.rb
|
|
683
689
|
- lib/lutaml/model/type/metaschema_pattern.rb
|
|
690
|
+
- lib/lutaml/model/type/nm_tokens.rb
|
|
684
691
|
- lib/lutaml/model/type/non_negative_integer.rb
|
|
685
692
|
- lib/lutaml/model/type/positive_integer.rb
|
|
686
693
|
- lib/lutaml/model/type/qname.rb
|