lutaml-model 0.8.178 → 0.8.179
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/compat/opal/lutaml_model_boot.rb +5 -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.rb +10 -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 +47 -0
- data/spec/lutaml/xml/validate_xml_with_constructs_spec.rb +11 -7
- data/spec/lutaml/xml/validate_xml_with_spec.rb +5 -3
- 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: 5bcb549c4874d482186701e9dab0f679acbdd607e8de1881f456addad166ffe8
|
|
4
|
+
data.tar.gz: 5730a91820996ad70d240521f7562268d92f1a682cea0c89ffded960a93e6b70
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d86a6050dcabfb0d5c9fc1850b4cabac230c90f7ecea5ef2cdb22ab7f6114c7dd488d4ba4e4049182414e218150dc9e5f2ba6caecd60a731d9840ae9c0b95a09
|
|
7
|
+
data.tar.gz: 02c8df9d2b236471abff47a0cbc225a1c4fd00179c5bd543361f4eb9b72575cc2b696f4c490d9230c96c02e2cc7c4eb51aac6cd495f54233a2bac04adb8c35a1
|
|
@@ -346,6 +346,11 @@ 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"
|
|
@@ -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
|
data/lib/lutaml/model/type.rb
CHANGED
|
@@ -38,6 +38,11 @@ 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"
|
|
41
46
|
|
|
42
47
|
# Error classes (defined in error/type/ but under Type namespace)
|
|
43
48
|
autoload :InvalidValueError, "#{__dir__}/error/type/invalid_value_error"
|
|
@@ -82,6 +87,11 @@ module Lutaml
|
|
|
82
87
|
date_time_with_timezone: "Lutaml::Model::Type::DateTimeWithTimezone",
|
|
83
88
|
day_time_duration: "Lutaml::Model::Type::DayTimeDuration",
|
|
84
89
|
year_month_duration: "Lutaml::Model::Type::YearMonthDuration",
|
|
90
|
+
g_year: "Lutaml::Model::Type::GYear",
|
|
91
|
+
g_year_month: "Lutaml::Model::Type::GYearMonth",
|
|
92
|
+
g_month: "Lutaml::Model::Type::GMonth",
|
|
93
|
+
g_month_day: "Lutaml::Model::Type::GMonthDay",
|
|
94
|
+
g_day: "Lutaml::Model::Type::GDay",
|
|
85
95
|
}.freeze
|
|
86
96
|
|
|
87
97
|
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,51 @@ 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
|
|
170
217
|
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,14 +188,15 @@ 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
|
|
189
|
-
#
|
|
190
|
-
# engine
|
|
191
|
-
#
|
|
191
|
+
# The leptris engine's targetNamespace qualification fix
|
|
192
|
+
# (leptris#2158, tracked as leptris/leptris-ruby#679) merged after
|
|
193
|
+
# the v1.9.442 engine tag, so no released leptris gem carries it
|
|
194
|
+
# yet; the cell gates until a gem build ships the fix. The default
|
|
195
|
+
# nokogiri lane enforces it and runs the assertion.
|
|
192
196
|
engine = Lutaml::Model::Config.xml_adapter_type&.to_s
|
|
193
197
|
if engine == "leptris"
|
|
194
|
-
skip "leptris targetNamespace enforcement pending " \
|
|
195
|
-
"leptris
|
|
198
|
+
skip "leptris targetNamespace enforcement pending a leptris " \
|
|
199
|
+
"gem carrying leptris#2158"
|
|
196
200
|
end
|
|
197
201
|
|
|
198
202
|
xml = "<address><city>Berlin</city></address>"
|
|
@@ -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.179
|
|
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,6 +674,11 @@ 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
|