lutaml-model 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/dependent-repos.json +2 -1
- data/.rubocop_todo.yml +10 -80
- data/lib/lutaml/model/attribute.rb +6 -1
- data/lib/lutaml/model/schema/xml_compiler.rb +3 -1
- data/lib/lutaml/model/type/float.rb +0 -4
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/xml_document.rb +0 -4
- data/lib/lutaml/model/xml_adapter/xml_element.rb +1 -3
- data/spec/address_spec.rb +3 -3
- data/spec/benchmarks/xml_parsing_benchmark_spec.rb +3 -3
- data/spec/lutaml/model/collection_spec.rb +0 -16
- data/spec/lutaml/model/json_adapter_spec.rb +26 -24
- data/spec/lutaml/model/key_value_mapping_spec.rb +1 -13
- data/spec/lutaml/model/schema/json_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/relaxng_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/xml_compiler_spec.rb +447 -147
- data/spec/lutaml/model/schema/xsd_schema_spec.rb +12 -12
- data/spec/lutaml/model/schema/yaml_schema_spec.rb +12 -12
- data/spec/lutaml/model/sequence_spec.rb +129 -113
- data/spec/lutaml/model/toml_adapter_spec.rb +27 -25
- data/spec/lutaml/model/transformation_spec.rb +80 -80
- data/spec/lutaml/model/type/boolean_spec.rb +4 -10
- data/spec/lutaml/model/type/decimal_spec.rb +3 -3
- data/spec/lutaml/model/type/hash_spec.rb +39 -26
- data/spec/lutaml/model/type/integer_spec.rb +2 -2
- data/spec/lutaml/model/type/time_without_date_spec.rb +0 -6
- data/spec/lutaml/model/type_spec.rb +6 -26
- data/spec/lutaml/model/utils_spec.rb +25 -30
- data/spec/lutaml/model/validation_spec.rb +9 -6
- data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +280 -281
- data/spec/lutaml/model/xml_adapter_spec.rb +128 -120
- data/spec/lutaml/model/xml_mapping_spec.rb +23 -16
- data/spec/person_spec.rb +6 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94d3957e15a5f50e2fc02c922f739acf71e99a592b97c4461c64b20cbc203bc5
|
4
|
+
data.tar.gz: 0daf15d9e99b94ecce154a95b86d8b24a11bc4ae89f7e21f44cd7d251ec11ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a05e07d0948529796da6833032c9edae933a022734f9018fc459a4caf7e8ee6d475e325b002a58c4b5de764fecde077380ab528bc0a60f87eecef8919dfa16f4
|
7
|
+
data.tar.gz: f6116e02319e52a64e6ed0817655b456ca0be1933f66fea70dab1999fbd4a1c2a70b52cfc60f153d1b18d6778b23882598c76ca7a4af0b7e7eb5eca0e563040c
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2025-02-
|
3
|
+
# on 2025-02-13 10:44:38 UTC using RuboCop version 1.71.2.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -27,34 +27,21 @@ Layout/IndentationWidth:
|
|
27
27
|
Exclude:
|
28
28
|
- 'lib/lutaml/model/schema/xml_compiler.rb'
|
29
29
|
|
30
|
-
# Offense count:
|
30
|
+
# Offense count: 467
|
31
31
|
# This cop supports safe autocorrection (--autocorrect).
|
32
32
|
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
33
33
|
# URISchemes: http, https
|
34
34
|
Layout/LineLength:
|
35
35
|
Enabled: false
|
36
36
|
|
37
|
-
# Offense count:
|
37
|
+
# Offense count: 13
|
38
38
|
# Configuration parameters: AllowedMethods.
|
39
39
|
# AllowedMethods: enums
|
40
40
|
Lint/ConstantDefinitionInBlock:
|
41
41
|
Exclude:
|
42
42
|
- 'spec/benchmarks/xml_parsing_benchmark_spec.rb'
|
43
|
-
- 'spec/lutaml/model/schema/json_schema_spec.rb'
|
44
|
-
- 'spec/lutaml/model/schema/relaxng_schema_spec.rb'
|
45
|
-
- 'spec/lutaml/model/schema/xsd_schema_spec.rb'
|
46
|
-
- 'spec/lutaml/model/schema/yaml_schema_spec.rb'
|
47
|
-
- 'spec/lutaml/model/transformation_spec.rb'
|
48
|
-
- 'spec/lutaml/model/validation_spec.rb'
|
49
43
|
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
50
44
|
|
51
|
-
# Offense count: 4
|
52
|
-
Lint/DuplicateMethods:
|
53
|
-
Exclude:
|
54
|
-
- 'lib/lutaml/model/type/float.rb'
|
55
|
-
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
56
|
-
- 'lib/lutaml/model/xml_adapter/xml_element.rb'
|
57
|
-
|
58
45
|
# Offense count: 56
|
59
46
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
60
47
|
Metrics/AbcSize:
|
@@ -101,7 +88,7 @@ Metrics/CyclomaticComplexity:
|
|
101
88
|
# Offense count: 87
|
102
89
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
103
90
|
Metrics/MethodLength:
|
104
|
-
Max:
|
91
|
+
Max: 45
|
105
92
|
|
106
93
|
# Offense count: 8
|
107
94
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
@@ -131,16 +118,6 @@ Performance/MapCompact:
|
|
131
118
|
Exclude:
|
132
119
|
- 'lib/lutaml/model/serialize.rb'
|
133
120
|
|
134
|
-
# Offense count: 8
|
135
|
-
# Configuration parameters: Prefixes, AllowedPatterns.
|
136
|
-
# Prefixes: when, with, without
|
137
|
-
RSpec/ContextWording:
|
138
|
-
Exclude:
|
139
|
-
- 'spec/lutaml/model/xml_adapter/oga_adapter_spec.rb'
|
140
|
-
- 'spec/lutaml/model/xml_adapter/ox_adapter_spec.rb'
|
141
|
-
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
142
|
-
- 'spec/lutaml/model/xml_mapping_spec.rb'
|
143
|
-
|
144
121
|
# Offense count: 2
|
145
122
|
# Configuration parameters: IgnoredMetadata.
|
146
123
|
RSpec/DescribeClass:
|
@@ -161,80 +138,39 @@ RSpec/DescribedClass:
|
|
161
138
|
Exclude:
|
162
139
|
- 'spec/lutaml/model/xml_mapping_spec.rb'
|
163
140
|
|
164
|
-
# Offense count:
|
141
|
+
# Offense count: 152
|
165
142
|
# Configuration parameters: CountAsOne.
|
166
143
|
RSpec/ExampleLength:
|
167
144
|
Max: 54
|
168
145
|
|
169
|
-
# Offense count:
|
170
|
-
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
|
171
|
-
RSpec/IndexedLet:
|
172
|
-
Exclude:
|
173
|
-
- 'spec/address_spec.rb'
|
174
|
-
|
175
|
-
# Offense count: 30
|
146
|
+
# Offense count: 13
|
176
147
|
RSpec/LeakyConstantDeclaration:
|
177
148
|
Exclude:
|
178
149
|
- 'spec/benchmarks/xml_parsing_benchmark_spec.rb'
|
179
|
-
- 'spec/lutaml/model/schema/json_schema_spec.rb'
|
180
|
-
- 'spec/lutaml/model/schema/relaxng_schema_spec.rb'
|
181
|
-
- 'spec/lutaml/model/schema/xsd_schema_spec.rb'
|
182
|
-
- 'spec/lutaml/model/schema/yaml_schema_spec.rb'
|
183
|
-
- 'spec/lutaml/model/transformation_spec.rb'
|
184
|
-
- 'spec/lutaml/model/validation_spec.rb'
|
185
150
|
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
186
151
|
|
187
|
-
# Offense count:
|
188
|
-
RSpec/MultipleDescribes:
|
189
|
-
Exclude:
|
190
|
-
- 'spec/lutaml/model/json_adapter_spec.rb'
|
191
|
-
- 'spec/lutaml/model/toml_adapter_spec.rb'
|
192
|
-
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
193
|
-
- 'spec/lutaml/model/xml_adapter_spec.rb'
|
194
|
-
|
195
|
-
# Offense count: 213
|
152
|
+
# Offense count: 206
|
196
153
|
RSpec/MultipleExpectations:
|
197
154
|
Max: 14
|
198
155
|
|
199
|
-
# Offense count:
|
156
|
+
# Offense count: 29
|
200
157
|
# Configuration parameters: AllowSubject.
|
201
158
|
RSpec/MultipleMemoizedHelpers:
|
202
159
|
Max: 9
|
203
160
|
|
204
|
-
# Offense count:
|
161
|
+
# Offense count: 109
|
205
162
|
# Configuration parameters: AllowedGroups.
|
206
163
|
RSpec/NestedGroups:
|
207
164
|
Max: 4
|
208
165
|
|
209
|
-
# Offense count:
|
166
|
+
# Offense count: 8
|
210
167
|
RSpec/PendingWithoutReason:
|
211
168
|
Exclude:
|
212
169
|
- 'spec/lutaml/model/type/date_time_spec.rb'
|
213
|
-
- 'spec/lutaml/model/type/integer_spec.rb'
|
214
170
|
- 'spec/lutaml/model/type/time_spec.rb'
|
215
171
|
- 'spec/lutaml/model/type/time_without_date_spec.rb'
|
216
172
|
- 'spec/lutaml/model/validation_spec.rb'
|
217
173
|
|
218
|
-
# Offense count: 1
|
219
|
-
RSpec/RemoveConst:
|
220
|
-
Exclude:
|
221
|
-
- 'spec/lutaml/model/type_spec.rb'
|
222
|
-
|
223
|
-
# Offense count: 3
|
224
|
-
RSpec/RepeatedExample:
|
225
|
-
Exclude:
|
226
|
-
- 'spec/lutaml/model/key_value_mapping_spec.rb'
|
227
|
-
|
228
|
-
# Offense count: 2
|
229
|
-
RSpec/RepeatedExampleGroupBody:
|
230
|
-
Exclude:
|
231
|
-
- 'spec/lutaml/model/type/time_without_date_spec.rb'
|
232
|
-
|
233
|
-
# Offense count: 2
|
234
|
-
RSpec/RepeatedExampleGroupDescription:
|
235
|
-
Exclude:
|
236
|
-
- 'spec/lutaml/model/collection_spec.rb'
|
237
|
-
|
238
174
|
# Offense count: 3
|
239
175
|
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
|
240
176
|
# Include: **/*_spec.rb
|
@@ -245,12 +181,6 @@ RSpec/SpecFilePathFormat:
|
|
245
181
|
- 'spec/lutaml/model/defaults_spec.rb'
|
246
182
|
- 'spec/lutaml/model/type/decimal_spec.rb'
|
247
183
|
|
248
|
-
# Offense count: 1
|
249
|
-
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
|
250
|
-
RSpec/VerifiedDoubles:
|
251
|
-
Exclude:
|
252
|
-
- 'spec/lutaml/model/type/hash_spec.rb'
|
253
|
-
|
254
184
|
# Offense count: 1
|
255
185
|
Security/CompoundHash:
|
256
186
|
Exclude:
|
@@ -253,7 +253,7 @@ module Lutaml
|
|
253
253
|
value ||= [] if collection?
|
254
254
|
if value.is_a?(Array)
|
255
255
|
value.map { |v| cast(v, format, options) }
|
256
|
-
elsif type <= Serialize && (value
|
256
|
+
elsif type <= Serialize && castable?(value, format)
|
257
257
|
type.apply_mappings(value, format, options)
|
258
258
|
elsif !value.nil? && !value.is_a?(type)
|
259
259
|
type.send(:"from_#{format}", value)
|
@@ -264,6 +264,11 @@ module Lutaml
|
|
264
264
|
|
265
265
|
private
|
266
266
|
|
267
|
+
def castable?(value, format)
|
268
|
+
value.is_a?(Hash) ||
|
269
|
+
(format == :xml && value.is_a?(Lutaml::Model::XmlAdapter::XmlElement))
|
270
|
+
end
|
271
|
+
|
267
272
|
def validate_options!(options)
|
268
273
|
if (invalid_opts = options.keys - ALLOWED_OPTIONS).any?
|
269
274
|
raise StandardError,
|
@@ -611,7 +611,9 @@ module Lutaml
|
|
611
611
|
when :attributes
|
612
612
|
required_files_attribute(value)
|
613
613
|
when :attribute_groups
|
614
|
-
value.each
|
614
|
+
value.each do |attribute_group|
|
615
|
+
required_files_attribute_groups(attribute_group)
|
616
|
+
end
|
615
617
|
when :complex_content
|
616
618
|
required_files_complex_content(value)
|
617
619
|
when :simple_content
|
data/lib/lutaml/model/version.rb
CHANGED
data/spec/address_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative "fixtures/address"
|
|
3
3
|
require_relative "fixtures/person"
|
4
4
|
|
5
5
|
RSpec.describe Address do
|
6
|
-
let(:
|
6
|
+
let(:tom_warren) do
|
7
7
|
{
|
8
8
|
first_name: "Tom",
|
9
9
|
last_name: "Warren",
|
@@ -15,7 +15,7 @@ RSpec.describe Address do
|
|
15
15
|
active: true,
|
16
16
|
}
|
17
17
|
end
|
18
|
-
let(:
|
18
|
+
let(:jack_warren) do
|
19
19
|
{
|
20
20
|
first_name: "Jack",
|
21
21
|
last_name: "Warren",
|
@@ -31,7 +31,7 @@ RSpec.describe Address do
|
|
31
31
|
{
|
32
32
|
country: "USA",
|
33
33
|
post_code: "01001",
|
34
|
-
person: [
|
34
|
+
person: [tom_warren, jack_warren],
|
35
35
|
}
|
36
36
|
end
|
37
37
|
let(:address) { described_class.new(attributes) }
|
@@ -61,9 +61,9 @@ RSpec.describe "LutaML Model Performance" do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
thresholds = {
|
64
|
-
"Nokogiri Adapter" =>
|
65
|
-
"Ox Adapter" =>
|
66
|
-
"Oga Adapter" =>
|
64
|
+
"Nokogiri Adapter" => 4,
|
65
|
+
"Ox Adapter" => 10,
|
66
|
+
"Oga Adapter" => 4,
|
67
67
|
}
|
68
68
|
|
69
69
|
report.entries.each do |entry|
|
@@ -186,22 +186,6 @@ RSpec.describe CollectionTests do
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
context "when collection counts are below given ranges" do
|
190
|
-
let(:invalid_attributes) do
|
191
|
-
attributes.merge(operators: [], sensors: [])
|
192
|
-
end
|
193
|
-
|
194
|
-
it "raises CollectionCountOutOfRangeError" do
|
195
|
-
kiln = CollectionTests::Kiln.new(invalid_attributes)
|
196
|
-
expect do
|
197
|
-
kiln.validate!
|
198
|
-
end.to raise_error(Lutaml::Model::ValidationError) do |error|
|
199
|
-
expect(error).to include(Lutaml::Model::CollectionCountOutOfRangeError)
|
200
|
-
expect(error.error_messages).to include(a_string_matching(/operators count is 0, must be at least 1/))
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
189
|
context "when collection with unbounded maximum exceeds minimum" do
|
206
190
|
let(:valid_attributes) do
|
207
191
|
attributes.merge(operators: ["John", "Jane", "Jim", "Jessica"])
|
@@ -3,35 +3,37 @@ require "lutaml/model/json_adapter/standard_json_adapter"
|
|
3
3
|
require "lutaml/model/json_adapter/multi_json_adapter"
|
4
4
|
require_relative "../../fixtures/sample_model"
|
5
5
|
|
6
|
-
RSpec.
|
7
|
-
|
8
|
-
|
6
|
+
RSpec.describe "JsonAdapter" do
|
7
|
+
shared_examples "a JSON adapter" do |adapter_class|
|
8
|
+
let(:attributes) { { name: "John Doe", age: 30 } }
|
9
|
+
let(:model) { SampleModel.new(attributes) }
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
let(:expected_json) do
|
12
|
+
if adapter_class == Lutaml::Model::JsonAdapter::StandardJsonAdapter
|
13
|
+
JSON.generate(attributes)
|
14
|
+
elsif adapter_class == Lutaml::Model::JsonAdapter::MultiJsonAdapter
|
15
|
+
MultiJson.dump(attributes)
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
it "serializes to JSON" do
|
20
|
+
json = adapter_class.new(attributes).to_json
|
21
|
+
expect(json).to eq(expected_json)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
it "deserializes from JSON" do
|
25
|
+
doc = adapter_class.parse(expected_json)
|
26
|
+
new_model = SampleModel.new(doc.to_h)
|
27
|
+
expect(new_model.name).to eq("John Doe")
|
28
|
+
expect(new_model.age).to eq(30)
|
29
|
+
end
|
28
30
|
end
|
29
|
-
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
32
|
+
describe Lutaml::Model::JsonAdapter::StandardJsonAdapter do
|
33
|
+
it_behaves_like "a JSON adapter", described_class
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
describe Lutaml::Model::JsonAdapter::MultiJsonAdapter do
|
37
|
+
it_behaves_like "a JSON adapter", described_class
|
38
|
+
end
|
37
39
|
end
|
@@ -92,19 +92,7 @@ RSpec.describe Lutaml::Model::KeyValueMapping do
|
|
92
92
|
)
|
93
93
|
end
|
94
94
|
|
95
|
-
it "handles JSON mapping" do
|
96
|
-
expect(mapping.mappings[0].render_nil).to be true
|
97
|
-
expect(mapping.mappings[0].delegate).to eq(:container)
|
98
|
-
expect(mapping.mappings[0].raw_mapping?).to be true
|
99
|
-
end
|
100
|
-
|
101
|
-
it "handles YAML mapping" do
|
102
|
-
expect(mapping.mappings[0].render_nil).to be true
|
103
|
-
expect(mapping.mappings[0].delegate).to eq(:container)
|
104
|
-
expect(mapping.mappings[0].raw_mapping?).to be true
|
105
|
-
end
|
106
|
-
|
107
|
-
it "handles TOML mapping" do
|
95
|
+
it "handles JSON, YAML, TOML mapping" do
|
108
96
|
expect(mapping.mappings[0].render_nil).to be true
|
109
97
|
expect(mapping.mappings[0].delegate).to eq(:container)
|
110
98
|
expect(mapping.mappings[0].raw_mapping?).to be true
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "lutaml/model/schema"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
4
|
+
module SchemaGeneration
|
5
|
+
class Glaze < Lutaml::Model::Serializable
|
6
|
+
attribute :color, Lutaml::Model::Type::String
|
7
|
+
attribute :finish, Lutaml::Model::Type::String
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
10
|
+
class Vase < Lutaml::Model::Serializable
|
11
|
+
attribute :height, Lutaml::Model::Type::Float
|
12
|
+
attribute :diameter, Lutaml::Model::Type::Float
|
13
|
+
attribute :glaze, Glaze
|
14
|
+
attribute :materials, Lutaml::Model::Type::String, collection: true
|
17
15
|
end
|
16
|
+
end
|
18
17
|
|
18
|
+
RSpec.describe Lutaml::Model::Schema::JsonSchema do
|
19
19
|
describe ".generate" do
|
20
20
|
it "generates a JSON schema for nested Serialize objects" do
|
21
21
|
schema = described_class.generate(SchemaGeneration::Vase,
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "lutaml/model/schema"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
4
|
+
module SchemaGeneration
|
5
|
+
class Glaze < Lutaml::Model::Serializable
|
6
|
+
attribute :color, Lutaml::Model::Type::String
|
7
|
+
attribute :finish, Lutaml::Model::Type::String
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
10
|
+
class Vase < Lutaml::Model::Serializable
|
11
|
+
attribute :height, Lutaml::Model::Type::Float
|
12
|
+
attribute :diameter, Lutaml::Model::Type::Float
|
13
|
+
attribute :glaze, Glaze
|
14
|
+
attribute :materials, Lutaml::Model::Type::String, collection: true
|
17
15
|
end
|
16
|
+
end
|
18
17
|
|
18
|
+
RSpec.describe Lutaml::Model::Schema::RelaxngSchema do
|
19
19
|
describe ".generate" do
|
20
20
|
it "generates a RELAX NG schema for nested Serialize objects" do
|
21
21
|
schema = described_class.generate(SchemaGeneration::Vase, pretty: true)
|