lutaml-model 0.8.165 → 0.8.166
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/version.rb +1 -1
- data/lib/lutaml/yamls/adapter/standard_adapter.rb +7 -1
- data/lib/lutaml/yamls/adapter/yeptris_adapter.rb +16 -2
- data/spec/lutaml/model/yamls/standard_adapter_spec.rb +7 -0
- data/spec/lutaml/model/yamls/yeptris_adapter_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5e26cb512515f146956b2f1f1b601a9fd810ef0fdf606e98963001e28b6fe249
|
|
4
|
+
data.tar.gz: 72e5bbd3f54f084abb92c34d63442cb0dee383851a1f4a78580b48bdf3651b8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 682c8dd4ea109bd97314cc01f32a4ea32f489176603e4a0a115679d2c6cd3f517490da31f72c6df6c5059389f12037827d9933cf35eeb7b8e33eb86cb31d1657
|
|
7
|
+
data.tar.gz: 98beef43e550b5cd69d76824a0c3a0a5cd266477aefd6382315ef0fdb06026b8fea0662e7f76b774c5094efe396140305f2b4146d82596c7d3f5b1e8969c92a7
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -23,8 +23,14 @@ module Lutaml
|
|
|
23
23
|
|
|
24
24
|
results
|
|
25
25
|
rescue *Lutaml::Model::Utils.yaml_parse_errors => e
|
|
26
|
+
results = parse_with_split(yamls)
|
|
27
|
+
# A stream that yields no valid document is invalid, not empty —
|
|
28
|
+
# raise so transports skip the file instead of registering a
|
|
29
|
+
# blank model.
|
|
30
|
+
raise e if results.empty?
|
|
31
|
+
|
|
26
32
|
warn "Skipping invalid yaml: #{e.message}"
|
|
27
|
-
|
|
33
|
+
results
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
def self.parse_with_split(yamls)
|
|
@@ -27,11 +27,22 @@ module Lutaml
|
|
|
27
27
|
# Tolerant iteration (yeptris#921): the engine frames the
|
|
28
28
|
# documents and reports failures per document; the host
|
|
29
29
|
# never touches the YAML text.
|
|
30
|
+
invalid_seen = false
|
|
30
31
|
# rubocop:disable-next Naming/VariableNumber -- upstream schema literal
|
|
31
32
|
::Yeptris::YAML.each_document(yamls, schema: :compat_11) do |doc, error|
|
|
32
|
-
|
|
33
|
+
if error
|
|
34
|
+
invalid_seen = true
|
|
35
|
+
warn "Skipping invalid yaml: #{error.message}"
|
|
36
|
+
end
|
|
33
37
|
results << doc unless error || doc.nil?
|
|
34
38
|
end
|
|
39
|
+
# A stream that yields no valid document is invalid, not
|
|
40
|
+
# empty — raise so transports skip the file instead of
|
|
41
|
+
# registering a blank model.
|
|
42
|
+
if results.empty? && invalid_seen
|
|
43
|
+
raise Lutaml::Model::InvalidFormatError,
|
|
44
|
+
"no valid documents in the yaml stream"
|
|
45
|
+
end
|
|
35
46
|
return results
|
|
36
47
|
end
|
|
37
48
|
|
|
@@ -39,8 +50,11 @@ module Lutaml
|
|
|
39
50
|
results = Yeptris::YAML.load_stream(yamls, schema: :compat_11)
|
|
40
51
|
results.compact
|
|
41
52
|
rescue Yeptris::ParseError => e
|
|
53
|
+
results = parse_with_split(yamls)
|
|
54
|
+
raise e if results.empty?
|
|
55
|
+
|
|
42
56
|
warn "Skipping invalid yaml: #{e.message}"
|
|
43
|
-
|
|
57
|
+
results
|
|
44
58
|
end
|
|
45
59
|
|
|
46
60
|
def self.require_engine
|
|
@@ -65,6 +65,13 @@ RSpec.describe Lutaml::Model::Yamls::StandardAdapter do
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
context "with a fully-invalid stream" do
|
|
69
|
+
it "raises instead of returning a blank document set" do
|
|
70
|
+
expect { described_class.parse("not: valid: yaml: [") }
|
|
71
|
+
.to raise_error(Psych::SyntaxError)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
68
75
|
context "with single document" do
|
|
69
76
|
let(:single_yaml_doc) do
|
|
70
77
|
<<~YAMLS
|
|
@@ -66,5 +66,15 @@ RSpec.describe Lutaml::Yamls::Adapter::YeptrisAdapter, if: Lutaml::Yamls::Adapte
|
|
|
66
66
|
results = described_class.parse("name: John\nage: 30\n")
|
|
67
67
|
expect(results).to eq([{ "name" => "John", "age" => 30 }])
|
|
68
68
|
end
|
|
69
|
+
|
|
70
|
+
it "raises on a fully-invalid stream instead of returning a blank set" do
|
|
71
|
+
expect { described_class.parse("not: valid: yaml: [") }
|
|
72
|
+
.to raise_error(StandardError)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "tolerates mixed streams but raises when nothing valid remains" do
|
|
76
|
+
results = described_class.parse("name: a\n---\nbad: [\n---\nname: c\n")
|
|
77
|
+
expect(results).to eq([{ "name" => "a" }, { "name" => "c" }])
|
|
78
|
+
end
|
|
69
79
|
end
|
|
70
80
|
end
|