lutaml-model 0.8.182 → 0.8.183
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 +1 -0
- data/lib/lutaml/model/schema.rb +4 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +1 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/format.rb +16 -0
- data/lib/lutaml/xml/schema/builder/moxml.rb +51 -0
- data/lib/lutaml/xml/schema/builder.rb +8 -7
- data/lib/lutaml/xml/schema/relaxng_schema.rb +10 -4
- data/lib/lutaml/xml/schema/xsd/schema_validator.rb +22 -14
- data/lib/lutaml/xml/schema/xsd_schema.rb +75 -17
- data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +120 -0
- data/spec/lutaml/model/schema/xsd_pattern_probe_spec.rb +43 -0
- data/spec/lutaml/xml/schema/builder_moxml_spec.rb +54 -0
- data/spec/spec_helper.rb +15 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a5a76da65495bed983c333fb3eddb3c6e8785c78c7e726378c17d1832be0915
|
|
4
|
+
data.tar.gz: b7665014e43334ff712a88e1b959cef40583c2b7cd0f19c9b8c0d36150f01c63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5dc8da8474f375b8c70e7ba05a1c587beea69c1ea90b013d8113c199fbdc5330cc527e5305c33b6736fe685c138f7db8083724f24d9338636eb7aed142b77130
|
|
7
|
+
data.tar.gz: bb96ee5a1d4e3daff6ad42e94a7752084ff08e17383d0e4b42fd5ef11b8534a5678a3683403dfcbcc02e1533639defe23dc8c45d371c15d8e8a2a95cde4bf0a3
|
|
@@ -543,6 +543,7 @@ require "lutaml/xml/decisions/rules/inherit_parent_prefix_rule"
|
|
|
543
543
|
require "lutaml/xml/decisions/rules/namespace_scope_rule"
|
|
544
544
|
require "lutaml/xml/decisions/rules/reuse_parent_prefix_rule"
|
|
545
545
|
require "lutaml/xml/decisions/rules/used_prefix_rule"
|
|
546
|
+
require "lutaml/xml/schema/builder/moxml"
|
|
546
547
|
require "lutaml/model/schema/xml_compiler/spec_builder/complex_types"
|
|
547
548
|
require "lutaml/model/schema/xml_compiler/spec_builder/members"
|
|
548
549
|
require "lutaml/model/schema/xml_compiler/spec_builder/simple_types"
|
data/lib/lutaml/model/schema.rb
CHANGED
|
@@ -76,6 +76,10 @@ module Lutaml
|
|
|
76
76
|
raise "XML schema compilation requires lutaml-xml. Add it to your Gemfile."
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
+
def self.target_namespace(_xml)
|
|
80
|
+
raise "XML schema compilation requires lutaml-xml. Add it to your Gemfile."
|
|
81
|
+
end
|
|
82
|
+
|
|
79
83
|
def self.from_relaxng(_rng, _options = {})
|
|
80
84
|
raise "RELAX NG schema compilation requires lutaml-xml. Add it to your Gemfile."
|
|
81
85
|
end
|
data/lib/lutaml/model/version.rb
CHANGED
data/lib/lutaml/xml/format.rb
CHANGED
|
@@ -324,6 +324,22 @@ Lutaml::Model::Schema.register_method(:from_xml) do |xml, options = {}|
|
|
|
324
324
|
Lutaml::Model::Schema::XmlCompiler.to_models(xml, options)
|
|
325
325
|
end
|
|
326
326
|
|
|
327
|
+
# The target namespace URI of an XSD document — the value callers pass
|
|
328
|
+
# back as the compile's `namespace:` option so generated models bind
|
|
329
|
+
# their schema namespace (parse-side matching and emission both ride
|
|
330
|
+
# it; see #1204). Rides Xsd.parse so the metaschema registration
|
|
331
|
+
# preamble runs before the parse resolves attribute types.
|
|
332
|
+
Lutaml::Model::Schema.register_method(:target_namespace) do |xml|
|
|
333
|
+
if Lutaml::Model.opal?
|
|
334
|
+
raise NotImplementedError,
|
|
335
|
+
"XML schema compilation is not available under Opal."
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
parsed = Lutaml::Xml::Schema::Xsd.parse(xml, validate_schema: false)
|
|
339
|
+
schema = parsed.is_a?(Array) ? parsed.first : parsed
|
|
340
|
+
schema&.target_namespace
|
|
341
|
+
end
|
|
342
|
+
|
|
327
343
|
Lutaml::Model::Schema.register_method(:from_relaxng) do |rng, options = {}|
|
|
328
344
|
if Lutaml::Model::RuntimeCompatibility.opal?
|
|
329
345
|
raise NotImplementedError,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Schema
|
|
6
|
+
class Builder
|
|
7
|
+
# The moxml-backed schema builder (issue #1184): schema
|
|
8
|
+
# generation rides the CONFIGURED engine through the moxml
|
|
9
|
+
# layer, so every engine with a builder face generates
|
|
10
|
+
# schemas — not only the engines with a dedicated wrapper.
|
|
11
|
+
# The backend resolves from Config's plain symbol; the
|
|
12
|
+
# AdapterResolver's FIXED_ADAPTER_TYPE sentinel never reaches
|
|
13
|
+
# Moxml (the closed #1183 leak).
|
|
14
|
+
#
|
|
15
|
+
# The block receives the Moxml::Builder and drives it with
|
|
16
|
+
# the same method_missing tag DSL the Nokogiri/Oga wrappers
|
|
17
|
+
# expose: tag(attrs) { ... } closures, symbol or string
|
|
18
|
+
# attribute keys, xmlns handled as a namespace declaration.
|
|
19
|
+
class Moxml
|
|
20
|
+
attr_reader :builder
|
|
21
|
+
|
|
22
|
+
def initialize(options = {}, &block)
|
|
23
|
+
encoding = options[:encoding] || "UTF-8"
|
|
24
|
+
backend = Lutaml::Model::Config.xml_adapter_type || :nokogiri
|
|
25
|
+
@context = ::Moxml.new(backend)
|
|
26
|
+
@builder = ::Moxml::Builder.new(@context)
|
|
27
|
+
# Nokogiri's Builder emits the declaration when an
|
|
28
|
+
# encoding is given; parity here.
|
|
29
|
+
@builder.declaration(version: "1.0", encoding: encoding)
|
|
30
|
+
yield(@builder) if block
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Generate the schema XML string
|
|
34
|
+
# @param options [Hash] formatting options
|
|
35
|
+
# @option options [Boolean] :pretty Pretty print with indentation
|
|
36
|
+
# @option options [Integer] :indent Number of spaces (default: 2)
|
|
37
|
+
# @return [String] schema XML string
|
|
38
|
+
def to_xml(options = {})
|
|
39
|
+
doc = @builder.document
|
|
40
|
+
if options[:pretty]
|
|
41
|
+
indent = options[:indent] || 2
|
|
42
|
+
doc.to_xml(indent: indent)
|
|
43
|
+
else
|
|
44
|
+
doc.to_xml
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -14,6 +14,7 @@ module Lutaml
|
|
|
14
14
|
class Builder
|
|
15
15
|
autoload :Nokogiri, "#{__dir__}/builder/nokogiri"
|
|
16
16
|
autoload :Oga, "#{__dir__}/builder/oga"
|
|
17
|
+
autoload :Moxml, "#{__dir__}/builder/moxml"
|
|
17
18
|
|
|
18
19
|
attr_reader :builder, :adapter_type
|
|
19
20
|
|
|
@@ -24,13 +25,11 @@ module Lutaml
|
|
|
24
25
|
# Use specified adapter, or configured XML adapter, or default to Nokogiri
|
|
25
26
|
requested_adapter = adapter_type || Lutaml::Model::Config.xml_adapter_type || :nokogiri
|
|
26
27
|
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
:nokogiri
|
|
33
|
-
end
|
|
28
|
+
# Engines with a dedicated wrapper keep it (byte-identical
|
|
29
|
+
# emission); every other configured engine generates through
|
|
30
|
+
# the moxml layer (#1184) — the wrapper follows the engine
|
|
31
|
+
# instead of silently substituting Nokogiri.
|
|
32
|
+
@adapter_type = requested_adapter
|
|
34
33
|
@options = options
|
|
35
34
|
@builder = create_builder(&block)
|
|
36
35
|
end
|
|
@@ -51,6 +50,8 @@ module Lutaml
|
|
|
51
50
|
Nokogiri.new(@options, &block)
|
|
52
51
|
when :oga
|
|
53
52
|
Oga.new(@options, &block)
|
|
53
|
+
else
|
|
54
|
+
Moxml.new(@options, &block)
|
|
54
55
|
end
|
|
55
56
|
end
|
|
56
57
|
end
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "nokogiri"
|
|
4
|
-
|
|
5
3
|
module Lutaml
|
|
6
4
|
module Xml
|
|
7
5
|
module Schema
|
|
8
6
|
# RelaxNG schema generation for XML models
|
|
9
7
|
#
|
|
10
|
-
# Generates RELAX NG schemas from LutaML model classes.
|
|
8
|
+
# Generates RELAX NG schemas from LutaML model classes. The
|
|
9
|
+
# emission rides the configured engine through the moxml layer
|
|
10
|
+
# (#1184); an explicit adapter option keeps the dedicated
|
|
11
|
+
# Nokogiri/Oga wrappers available.
|
|
11
12
|
class RelaxngSchema
|
|
12
13
|
extend Lutaml::Model::Schema::SharedMethods
|
|
13
14
|
|
|
14
15
|
def self.generate(klass, options = {})
|
|
15
16
|
register = extract_register_from(klass)
|
|
16
|
-
|
|
17
|
+
adapter = options[:adapter] ||
|
|
18
|
+
Lutaml::Model::Config.xml_adapter_type || :nokogiri
|
|
19
|
+
builder = Builder.new(
|
|
20
|
+
adapter_type: adapter,
|
|
21
|
+
options: { encoding: "UTF-8" },
|
|
22
|
+
) do |xml|
|
|
17
23
|
xml.grammar(xmlns: "http://relaxng.org/ns/structure/1.0") do
|
|
18
24
|
generate_start(xml, klass)
|
|
19
25
|
generate_define(xml, klass, register)
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "nokogiri"
|
|
4
|
-
|
|
5
3
|
module Lutaml
|
|
6
4
|
module Xml
|
|
7
5
|
module Schema
|
|
@@ -89,7 +87,7 @@ module Lutaml
|
|
|
89
87
|
# @param content [String] XML content to analyze
|
|
90
88
|
# @return [String] Detected version ("1.0" or "1.1")
|
|
91
89
|
def self.detect_version(content)
|
|
92
|
-
doc =
|
|
90
|
+
doc = parse_context.parse(content)
|
|
93
91
|
root = doc.root
|
|
94
92
|
return "1.0" unless root
|
|
95
93
|
|
|
@@ -105,13 +103,23 @@ module Lutaml
|
|
|
105
103
|
"1.0"
|
|
106
104
|
end
|
|
107
105
|
end
|
|
108
|
-
rescue ::
|
|
106
|
+
rescue Moxml::ParseError
|
|
109
107
|
"1.0" # Default to 1.0 if cannot parse
|
|
110
108
|
end
|
|
111
109
|
|
|
110
|
+
# The configured engine as a moxml backend symbol. Config's
|
|
111
|
+
# plain symbol — NOT the AdapterResolver's configured type,
|
|
112
|
+
# whose FIXED_ADAPTER_TYPE sentinel is internal and must
|
|
113
|
+
# never reach Moxml (the closed #1183 leak). Not memoized:
|
|
114
|
+
# the backend follows the CURRENT config (hosts and suites
|
|
115
|
+
# switch adapters mid-process); construction is cheap.
|
|
116
|
+
def self.parse_context
|
|
117
|
+
Moxml.new(Lutaml::Model::Config.xml_adapter_type || :nokogiri)
|
|
118
|
+
end
|
|
119
|
+
|
|
112
120
|
# Check if document has XSD 1.1 specific features
|
|
113
121
|
#
|
|
114
|
-
# @param doc [
|
|
122
|
+
# @param doc [Moxml::Document] Parsed XML document
|
|
115
123
|
# @return [Boolean] true if XSD 1.1 features are present
|
|
116
124
|
def self.has_xsd_1_1_features?(doc)
|
|
117
125
|
# Check for XSD 1.1 specific elements
|
|
@@ -152,25 +160,25 @@ module Lutaml
|
|
|
152
160
|
# @param content [String] XML content to validate
|
|
153
161
|
# @raise [SchemaValidationError] if XML syntax is invalid
|
|
154
162
|
def validate_xml_syntax(content)
|
|
155
|
-
|
|
156
|
-
rescue ::
|
|
163
|
+
self.class.parse_context.parse(content, strict: true)
|
|
164
|
+
rescue Moxml::ParseError => e
|
|
157
165
|
raise SchemaValidationError, "Invalid XML syntax: #{e.message}"
|
|
158
166
|
end
|
|
159
167
|
|
|
160
168
|
# Parse XML with error handling
|
|
161
169
|
#
|
|
162
170
|
# @param content [String] XML content to parse
|
|
163
|
-
# @return [::
|
|
171
|
+
# @return [Moxml::Document] Parsed document
|
|
164
172
|
# @raise [SchemaValidationError] if parsing fails
|
|
165
173
|
def parse_xml(content)
|
|
166
|
-
|
|
167
|
-
rescue ::
|
|
174
|
+
self.class.parse_context.parse(content)
|
|
175
|
+
rescue Moxml::ParseError => e
|
|
168
176
|
raise SchemaValidationError, "Failed to parse XML: #{e.message}"
|
|
169
177
|
end
|
|
170
178
|
|
|
171
179
|
# Validate that root element is xs:schema
|
|
172
180
|
#
|
|
173
|
-
# @param doc [
|
|
181
|
+
# @param doc [Moxml::Document] Parsed XML document
|
|
174
182
|
# @raise [SchemaValidationError] if root element is not a valid schema element
|
|
175
183
|
def validate_schema_root(doc)
|
|
176
184
|
root = doc.root
|
|
@@ -188,7 +196,7 @@ module Lutaml
|
|
|
188
196
|
end
|
|
189
197
|
|
|
190
198
|
# Check if root element has the correct namespace
|
|
191
|
-
namespace_uri = root.namespace&.
|
|
199
|
+
namespace_uri = root.namespace&.uri
|
|
192
200
|
return if namespace_uri == XSD_NAMESPACE
|
|
193
201
|
|
|
194
202
|
if namespace_uri.nil?
|
|
@@ -204,7 +212,7 @@ module Lutaml
|
|
|
204
212
|
|
|
205
213
|
# Validate schema version compatibility
|
|
206
214
|
#
|
|
207
|
-
# @param doc [
|
|
215
|
+
# @param doc [Moxml::Document] Parsed XML document
|
|
208
216
|
# @raise [SchemaValidationError] if schema uses features incompatible with target version
|
|
209
217
|
def validate_schema_version(doc)
|
|
210
218
|
return if @version == "1.1" # 1.1 accepts all features
|
|
@@ -221,7 +229,7 @@ module Lutaml
|
|
|
221
229
|
|
|
222
230
|
# Detect which XSD 1.1 features are present
|
|
223
231
|
#
|
|
224
|
-
# @param doc [
|
|
232
|
+
# @param doc [Moxml::Document] Parsed XML document
|
|
225
233
|
# @return [Array<String>] List of detected XSD 1.1 features
|
|
226
234
|
def detect_1_1_features(doc)
|
|
227
235
|
features = []
|
|
@@ -786,23 +786,81 @@ skip_unmapped: false)
|
|
|
786
786
|
end
|
|
787
787
|
|
|
788
788
|
def self.reject_invalid_xsd_pattern!(regexp, source)
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
789
|
+
detail = structural_xsd_incompatibility(source)
|
|
790
|
+
return unless detail
|
|
791
|
+
|
|
792
|
+
raise_inexpressible_pattern!(regexp, detail)
|
|
793
|
+
end
|
|
794
|
+
|
|
795
|
+
# The structural probe for XSD's regexp subset (issue #1184).
|
|
796
|
+
# The constructs Ruby's engine adds beyond XSD 1.0's —
|
|
797
|
+
# lookaround, atomic groups, conditionals, backreferences,
|
|
798
|
+
# possessive/lazy quantifiers, \G — are detected
|
|
799
|
+
# syntactically: a compile probe cannot vouch for
|
|
800
|
+
# expressibility on every engine, because moxml lanes compile
|
|
801
|
+
# inexpressible patterns silently (and lanes without a
|
|
802
|
+
# validator never probed at all). Escapes are honored
|
|
803
|
+
# pair-wise and character classes are skipped wholesale
|
|
804
|
+
# (their interiors are literal XSD text).
|
|
805
|
+
def self.structural_xsd_incompatibility(source)
|
|
806
|
+
i = 0
|
|
807
|
+
len = source.length
|
|
808
|
+
while i < len
|
|
809
|
+
ch = source[i]
|
|
810
|
+
if ch == "\\"
|
|
811
|
+
nxt = source[i + 1]
|
|
812
|
+
return "the backreference \\#{nxt}" if nxt && ("1".."9").cover?(nxt)
|
|
813
|
+
return "the \\G anchor" if nxt == "G"
|
|
814
|
+
return "a \\k backreference" if nxt == "k"
|
|
815
|
+
|
|
816
|
+
i += 2
|
|
817
|
+
next
|
|
818
|
+
end
|
|
819
|
+
if ch == "["
|
|
820
|
+
# char class: `]` right after `[` / `[^` is literal
|
|
821
|
+
j = i + 1
|
|
822
|
+
j += 1 if source[j] == "^"
|
|
823
|
+
j += 1 if source[j] == "]"
|
|
824
|
+
while j < len && source[j] != "]"
|
|
825
|
+
j += 2 if source[j] == "\\"
|
|
826
|
+
j += 1
|
|
827
|
+
end
|
|
828
|
+
i = j + 1
|
|
829
|
+
next
|
|
830
|
+
end
|
|
831
|
+
if ch == "("
|
|
832
|
+
rest = source[i, 4]
|
|
833
|
+
return "a lookaround" if rest.start_with?("(?=", "(?!",
|
|
834
|
+
"(?<=", "(?<!")
|
|
835
|
+
return "an atomic group" if rest.start_with?("(?>")
|
|
836
|
+
return "a conditional" if rest.start_with?("(?(")
|
|
837
|
+
|
|
838
|
+
i += 1
|
|
839
|
+
next
|
|
840
|
+
end
|
|
841
|
+
if ch == "{"
|
|
842
|
+
j = i + 1
|
|
843
|
+
j += 1 while j < len && source[j] =~ /[0-9,]/
|
|
844
|
+
if source[j] == "}"
|
|
845
|
+
nxt = source[j + 1]
|
|
846
|
+
return "a possessive quantifier" if nxt == "+"
|
|
847
|
+
return "a lazy quantifier" if nxt == "?"
|
|
848
|
+
|
|
849
|
+
i = j + 1
|
|
850
|
+
next
|
|
851
|
+
end
|
|
852
|
+
i += 1
|
|
853
|
+
next
|
|
854
|
+
end
|
|
855
|
+
case ch
|
|
856
|
+
when "*", "+", "?"
|
|
857
|
+
nxt = source[i + 1]
|
|
858
|
+
return "a possessive quantifier" if nxt == "+"
|
|
859
|
+
return "a lazy quantifier" if nxt == "?"
|
|
860
|
+
end
|
|
861
|
+
i += 1
|
|
862
|
+
end
|
|
863
|
+
nil
|
|
806
864
|
end
|
|
807
865
|
|
|
808
866
|
UNSUPPORTED_XSD_REGEX_FLAGS =
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require "spec_helper"
|
|
4
4
|
require "lutaml/model/schema"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "rbconfig"
|
|
5
7
|
require "tmpdir"
|
|
6
8
|
|
|
7
9
|
# Runtime XSD-to-classes compilation (#251): Schema.from_xml compiles a
|
|
@@ -354,4 +356,122 @@ RSpec.describe "runtime XSD class loading" do
|
|
|
354
356
|
expect(source).not_to include("instance_variable_set")
|
|
355
357
|
end
|
|
356
358
|
end
|
|
359
|
+
|
|
360
|
+
describe "XSD-compile then namespaced-instance hydration (#1204)" do
|
|
361
|
+
let(:base_xsd) do
|
|
362
|
+
<<~XSD
|
|
363
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
364
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
365
|
+
targetNamespace="http://example.com/s102-base"
|
|
366
|
+
elementFormDefault="qualified">
|
|
367
|
+
<xs:complexType name="ImportedMetric">
|
|
368
|
+
<xs:sequence>
|
|
369
|
+
<xs:element name="name" type="xs:string" minOccurs="0"/>
|
|
370
|
+
<xs:element name="valueType" type="xs:string" minOccurs="0"/>
|
|
371
|
+
</xs:sequence>
|
|
372
|
+
</xs:complexType>
|
|
373
|
+
</xs:schema>
|
|
374
|
+
XSD
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
let(:main_xsd) do
|
|
378
|
+
<<~XSD
|
|
379
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
380
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
381
|
+
xmlns:b="http://example.com/s102-base"
|
|
382
|
+
targetNamespace="http://example.com/s102-main"
|
|
383
|
+
elementFormDefault="qualified">
|
|
384
|
+
<xs:import namespace="http://example.com/s102-base"
|
|
385
|
+
schemaLocation="base.xsd"/>
|
|
386
|
+
<xs:complexType name="MetricSet">
|
|
387
|
+
<xs:sequence>
|
|
388
|
+
<xs:element name="metric" type="b:ImportedMetric"
|
|
389
|
+
maxOccurs="unbounded"/>
|
|
390
|
+
</xs:sequence>
|
|
391
|
+
</xs:complexType>
|
|
392
|
+
<xs:element name="root">
|
|
393
|
+
<xs:complexType>
|
|
394
|
+
<xs:sequence>
|
|
395
|
+
<xs:element name="name" type="xs:string"/>
|
|
396
|
+
<xs:element name="metrics" type="MetricSet" minOccurs="0"/>
|
|
397
|
+
</xs:sequence>
|
|
398
|
+
</xs:complexType>
|
|
399
|
+
</xs:element>
|
|
400
|
+
</xs:schema>
|
|
401
|
+
XSD
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
let(:instance_xml) do
|
|
405
|
+
<<~XML
|
|
406
|
+
<m:root xmlns:m="http://example.com/s102-main"
|
|
407
|
+
xmlns:b="http://example.com/s102-base">
|
|
408
|
+
<m:name>S-102</m:name>
|
|
409
|
+
<m:metrics>
|
|
410
|
+
<m:metric>
|
|
411
|
+
<b:name>depth</b:name>
|
|
412
|
+
<b:valueType>real</b:valueType>
|
|
413
|
+
</m:metric>
|
|
414
|
+
<m:metric>
|
|
415
|
+
<b:name>uncertainty</b:name>
|
|
416
|
+
<b:valueType>TVU</b:valueType>
|
|
417
|
+
</m:metric>
|
|
418
|
+
</m:metrics>
|
|
419
|
+
</m:root>
|
|
420
|
+
XML
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
let(:register_id) { :s102_hydration_reg }
|
|
424
|
+
|
|
425
|
+
it "reports the schema's target namespace for the namespace: option" do
|
|
426
|
+
expect(Lutaml::Model::Schema.target_namespace(main_xsd))
|
|
427
|
+
.to eq("http://example.com/s102-main")
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
# The compile→hydrate contract runs in a subprocess: the suite's
|
|
431
|
+
# per-example GlobalRegister reset wipes the metaschema registrations
|
|
432
|
+
# that self-register at class-file load, and no in-process re-sync
|
|
433
|
+
# restores the full parse-time state. A fresh process is the honest
|
|
434
|
+
# environment for the consumer-facing contract (#406 drives it).
|
|
435
|
+
it "hydrates a prefixed instance into the compiled root model" do
|
|
436
|
+
Dir.mktmpdir do |dir|
|
|
437
|
+
File.write(File.join(dir, "base.xsd"), base_xsd)
|
|
438
|
+
File.write(File.join(dir, "main.xsd"), main_xsd)
|
|
439
|
+
File.write(File.join(dir, "instance.xml"), instance_xml)
|
|
440
|
+
|
|
441
|
+
probe = <<~RUBY
|
|
442
|
+
require "lutaml/model"
|
|
443
|
+
|
|
444
|
+
Lutaml::Model::Schema.from_xml(
|
|
445
|
+
File.read("#{dir}/main.xsd"),
|
|
446
|
+
output_dir: "#{dir}/s102_models",
|
|
447
|
+
load_classes: true,
|
|
448
|
+
namespace: Lutaml::Model::Schema.target_namespace(
|
|
449
|
+
File.read("#{dir}/main.xsd"),
|
|
450
|
+
),
|
|
451
|
+
module_namespace: "S102HydrationModels",
|
|
452
|
+
register_id: "#{register_id}",
|
|
453
|
+
location: "#{dir}/main.xsd",
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
parsed = S102HydrationModels::CTRoot
|
|
457
|
+
.from_xml(File.read("#{dir}/instance.xml"))
|
|
458
|
+
|
|
459
|
+
puts "name=\#{parsed.name.inspect}"
|
|
460
|
+
puts "value_types=\#{parsed.metrics.metric.map(&:value_type).inspect}"
|
|
461
|
+
puts "default_register=\#{Lutaml::Model::Config.default_register.inspect}"
|
|
462
|
+
RUBY
|
|
463
|
+
|
|
464
|
+
_stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-I", "lib",
|
|
465
|
+
"-e", probe)
|
|
466
|
+
expect(status).to be_success, stderr
|
|
467
|
+
|
|
468
|
+
expect(_stdout).to include('name="S-102"')
|
|
469
|
+
# maxOccurs="unbounded" members hydrate as collections and the
|
|
470
|
+
# imported-schema scalar resolves through the derivation's
|
|
471
|
+
# register at parse time
|
|
472
|
+
expect(_stdout).to include('value_types=["real", "TVU"]')
|
|
473
|
+
expect(_stdout).to include("default_register=:default")
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
end
|
|
357
477
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Lutaml::Xml::Schema::XsdSchema do
|
|
6
|
+
# issue #1184: the xs:pattern expressibility probe is structural —
|
|
7
|
+
# the constructs Ruby's engine adds beyond XSD 1.0's regexp are
|
|
8
|
+
# detected syntactically, on every lane (a compile probe cannot
|
|
9
|
+
# vouch where engines compile inexpressible patterns silently, and
|
|
10
|
+
# lanes without a validator never probed at all).
|
|
11
|
+
def probe(source)
|
|
12
|
+
described_class.reject_invalid_xsd_pattern!(/#{Regexp.escape(source)}/x, source)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
shared_examples "inexpressible" do |source, detail|
|
|
16
|
+
it "rejects #{source.inspect}" do
|
|
17
|
+
expect { probe(source) }
|
|
18
|
+
.to raise_error(Lutaml::Model::Error, /not expressible.*#{detail}/)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it_behaves_like "inexpressible", "(?=.*[0-9])[a-z]+", "lookaround"
|
|
23
|
+
it_behaves_like "inexpressible", "a(?!b)", "lookaround"
|
|
24
|
+
it_behaves_like "inexpressible", "(?<=a)b", "lookaround"
|
|
25
|
+
it_behaves_like "inexpressible", "a(?>b|c)", "atomic"
|
|
26
|
+
it_behaves_like "inexpressible", "a(?(1)b|c)", "conditional"
|
|
27
|
+
it_behaves_like "inexpressible", "(a)\\1", "backreference"
|
|
28
|
+
it_behaves_like "inexpressible", "(?<word>a)\\k<word>", "backreference"
|
|
29
|
+
it_behaves_like "inexpressible", "a*+", "possessive quantifier"
|
|
30
|
+
it_behaves_like "inexpressible", "a{2,3}+", "possessive quantifier"
|
|
31
|
+
it_behaves_like "inexpressible", "a+?", "lazy quantifier"
|
|
32
|
+
it_behaves_like "inexpressible", "a*??", "lazy quantifier"
|
|
33
|
+
it_behaves_like "inexpressible", "\\Ga+", "anchor"
|
|
34
|
+
|
|
35
|
+
it "admits plain groups and quantifiers" do
|
|
36
|
+
expect { probe("[a-z]+(foo|bar)*baz?") }.not_to raise_error
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "does not false-positive on escapes or character classes" do
|
|
40
|
+
expect { probe("\\[\\d\\]") }.not_to raise_error
|
|
41
|
+
expect { probe("[a\\-z\\*+?]{2}") }.not_to raise_error
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Lutaml::Xml::Schema::Builder do
|
|
6
|
+
# issue #1184: schema generation rides the CONFIGURED engine through
|
|
7
|
+
# the moxml layer. The dedicated Nokogiri/Oga wrappers keep their
|
|
8
|
+
# lanes; every other engine (ox, leptris, rexml) generates through
|
|
9
|
+
# the Moxml wrapper instead of silently substituting Nokogiri.
|
|
10
|
+
|
|
11
|
+
describe "engine-following selection" do
|
|
12
|
+
it "keeps the dedicated Nokogiri wrapper when Nokogiri is requested" do
|
|
13
|
+
builder = described_class.new(adapter_type: :nokogiri)
|
|
14
|
+
|
|
15
|
+
expect(builder.adapter_type).to eq(:nokogiri)
|
|
16
|
+
expect(builder.builder).to be_a(described_class::Nokogiri)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "routes other configured engines through the Moxml wrapper" do
|
|
20
|
+
builder = described_class.new(adapter_type: :ox)
|
|
21
|
+
|
|
22
|
+
expect(builder.adapter_type).to eq(:ox)
|
|
23
|
+
expect(builder.builder).to be_a(described_class::Moxml)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "Moxml wrapper emission" do
|
|
28
|
+
let(:builder) do
|
|
29
|
+
described_class.new(adapter_type: :ox) do |xml|
|
|
30
|
+
xml.schema(targetNamespace: "http://example.com") do
|
|
31
|
+
xml.element(name: "name", type: "xs:string")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "emits the XML declaration with the encoding" do
|
|
37
|
+
expect(builder.to_xml).to start_with("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "emits the nested schema DSL shape" do
|
|
41
|
+
xml = builder.to_xml
|
|
42
|
+
|
|
43
|
+
expect(xml).to include("<schema")
|
|
44
|
+
expect(xml).to include("targetNamespace=\"http://example.com\"")
|
|
45
|
+
# the empty-element form is lane-serialized; both forms are
|
|
46
|
+
# model-legal XML — the DSL shape is what parity binds here
|
|
47
|
+
expect(xml).to match(/<element name="name" type="xs:string"\s*\/?>(<\/element>)?/)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "honors the pretty option" do
|
|
51
|
+
expect(builder.to_xml(pretty: true)).to include("\n")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -33,6 +33,21 @@ RSpec.configure do |config|
|
|
|
33
33
|
Lutaml::Model::GlobalRegister.instance.reset if defined?(Lutaml::Model::GlobalRegister)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# Restore the configured XML adapter after each example:
|
|
37
|
+
# adapter-switching specs set Config.xml_adapter_type directly and
|
|
38
|
+
# the drift used to leak into later specs. The moxml-routed XSD
|
|
39
|
+
# machinery follows the CURRENT config by design (#1184), which
|
|
40
|
+
# turned that leak into order-dependent schema-suite failures —
|
|
41
|
+
# the restore pins every example back to the spec_helper default.
|
|
42
|
+
config.around do |example|
|
|
43
|
+
previous = Lutaml::Model::Config.xml_adapter_type
|
|
44
|
+
begin
|
|
45
|
+
example.run
|
|
46
|
+
ensure
|
|
47
|
+
Lutaml::Model::Config.xml_adapter_type = previous if previous
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
36
51
|
# Reset adapter state between adapter-switching tests
|
|
37
52
|
config.after(:each, :adapter_test) do
|
|
38
53
|
Lutaml::Model::AdapterScope.reset! if defined?(Lutaml::Model::AdapterScope)
|
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.183
|
|
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-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -876,6 +876,7 @@ files:
|
|
|
876
876
|
- lib/lutaml/xml/rexml/element.rb
|
|
877
877
|
- lib/lutaml/xml/schema.rb
|
|
878
878
|
- lib/lutaml/xml/schema/builder.rb
|
|
879
|
+
- lib/lutaml/xml/schema/builder/moxml.rb
|
|
879
880
|
- lib/lutaml/xml/schema/builder/nokogiri.rb
|
|
880
881
|
- lib/lutaml/xml/schema/builder/oga.rb
|
|
881
882
|
- lib/lutaml/xml/schema/builtin_types.rb
|
|
@@ -1883,6 +1884,7 @@ files:
|
|
|
1883
1884
|
- spec/lutaml/model/schema/renderers/restricted_type_spec.rb
|
|
1884
1885
|
- spec/lutaml/model/schema/renderers/union_spec.rb
|
|
1885
1886
|
- spec/lutaml/model/schema/xml_compiler_runtime_spec.rb
|
|
1887
|
+
- spec/lutaml/model/schema/xsd_pattern_probe_spec.rb
|
|
1886
1888
|
- spec/lutaml/model/schema/xsd_schema_spec.rb
|
|
1887
1889
|
- spec/lutaml/model/schema/yaml_schema_spec.rb
|
|
1888
1890
|
- spec/lutaml/model/sequence_choice_compositor_spec.rb
|
|
@@ -2096,6 +2098,7 @@ files:
|
|
|
2096
2098
|
- spec/lutaml/xml/reusable_mapping_spec.rb
|
|
2097
2099
|
- spec/lutaml/xml/reused_elements_namespace_spec.rb
|
|
2098
2100
|
- spec/lutaml/xml/root_mappings/nested_child_mappings_spec.rb
|
|
2101
|
+
- spec/lutaml/xml/schema/builder_moxml_spec.rb
|
|
2099
2102
|
- spec/lutaml/xml/schema/compiler_spec.rb
|
|
2100
2103
|
- spec/lutaml/xml/schema/facet_round_trip_spec.rb
|
|
2101
2104
|
- spec/lutaml/xml/schema/rnc_compiler_spec.rb
|