lutaml-model 0.6.0 → 0.6.2

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependent-repos.json +2 -1
  3. data/.rubocop_todo.yml +10 -80
  4. data/lib/lutaml/model/attribute.rb +9 -5
  5. data/lib/lutaml/model/schema/xml_compiler.rb +3 -1
  6. data/lib/lutaml/model/serialize.rb +6 -8
  7. data/lib/lutaml/model/type/float.rb +0 -4
  8. data/lib/lutaml/model/version.rb +1 -1
  9. data/lib/lutaml/model/xml_adapter/xml_document.rb +0 -4
  10. data/lib/lutaml/model/xml_adapter/xml_element.rb +1 -3
  11. data/spec/address_spec.rb +3 -3
  12. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +3 -3
  13. data/spec/lutaml/model/collection_spec.rb +0 -16
  14. data/spec/lutaml/model/custom_model_spec.rb +49 -1
  15. data/spec/lutaml/model/json_adapter_spec.rb +26 -24
  16. data/spec/lutaml/model/key_value_mapping_spec.rb +1 -13
  17. data/spec/lutaml/model/schema/json_schema_spec.rb +12 -12
  18. data/spec/lutaml/model/schema/relaxng_schema_spec.rb +12 -12
  19. data/spec/lutaml/model/schema/xml_compiler_spec.rb +447 -147
  20. data/spec/lutaml/model/schema/xsd_schema_spec.rb +12 -12
  21. data/spec/lutaml/model/schema/yaml_schema_spec.rb +12 -12
  22. data/spec/lutaml/model/sequence_spec.rb +129 -113
  23. data/spec/lutaml/model/toml_adapter_spec.rb +27 -25
  24. data/spec/lutaml/model/transformation_spec.rb +80 -80
  25. data/spec/lutaml/model/type/boolean_spec.rb +4 -10
  26. data/spec/lutaml/model/type/decimal_spec.rb +3 -3
  27. data/spec/lutaml/model/type/hash_spec.rb +39 -26
  28. data/spec/lutaml/model/type/integer_spec.rb +2 -2
  29. data/spec/lutaml/model/type/time_without_date_spec.rb +0 -6
  30. data/spec/lutaml/model/type_spec.rb +6 -26
  31. data/spec/lutaml/model/utils_spec.rb +25 -30
  32. data/spec/lutaml/model/validation_spec.rb +9 -6
  33. data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +2 -2
  34. data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +2 -2
  35. data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +280 -281
  36. data/spec/lutaml/model/xml_adapter_spec.rb +128 -120
  37. data/spec/lutaml/model/xml_mapping_spec.rb +47 -16
  38. data/spec/person_spec.rb +6 -16
  39. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9883cb9431e9cd0c40c6e30891e1fb84861f1b9e9e7eb31a1cb5c6ec0d6121dc
4
- data.tar.gz: 2d00bb121ca7486d151f4daaacb86f98824ef5950460dc4caecffe4280c93607
3
+ metadata.gz: 94d3957e15a5f50e2fc02c922f739acf71e99a592b97c4461c64b20cbc203bc5
4
+ data.tar.gz: 0daf15d9e99b94ecce154a95b86d8b24a11bc4ae89f7e21f44cd7d251ec11ab9
5
5
  SHA512:
6
- metadata.gz: df269be2c13bb4586e13d99dc79b47dbe1b445d49b8f23adf9c7ef502dae58deb77dd714431d29991c56e9aa9ac422a03910648e6f9a81414c7f375541fa6bf4
7
- data.tar.gz: ed384722ad8f1fdb81671c8318ae0190c7372780a910ffece79e50658103344bd9f293afce048afa728cc91e47d952f6812bdbf2bce7a18d652d6704f9ef69cd
6
+ metadata.gz: a05e07d0948529796da6833032c9edae933a022734f9018fc459a4caf7e8ee6d475e325b002a58c4b5de764fecde077380ab528bc0a60f87eecef8919dfa16f4
7
+ data.tar.gz: f6116e02319e52a64e6ed0817655b456ca0be1933f66fea70dab1999fbd4a1c2a70b52cfc60f153d1b18d6778b23882598c76ca7a4af0b7e7eb5eca0e563040c
@@ -8,8 +8,9 @@
8
8
  "metanorma/sts-ruby",
9
9
  "lutaml/metaschema",
10
10
  "glossarist/termium",
11
+ "glossarist/glossarist-ruby",
11
12
  "lutaml/oasis-etm",
12
13
  "lutaml/ali",
13
14
  "lutaml/reqif"
14
15
  ]
15
- }
16
+ }
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-08 01:06:17 UTC using RuboCop version 1.71.2.
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: 596
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: 19
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: 46
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: 169
141
+ # Offense count: 152
165
142
  # Configuration parameters: CountAsOne.
166
143
  RSpec/ExampleLength:
167
144
  Max: 54
168
145
 
169
- # Offense count: 2
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: 4
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: 30
156
+ # Offense count: 29
200
157
  # Configuration parameters: AllowSubject.
201
158
  RSpec/MultipleMemoizedHelpers:
202
159
  Max: 9
203
160
 
204
- # Offense count: 108
161
+ # Offense count: 109
205
162
  # Configuration parameters: AllowedGroups.
206
163
  RSpec/NestedGroups:
207
164
  Max: 4
208
165
 
209
- # Offense count: 9
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:
@@ -248,13 +248,12 @@ module Lutaml
248
248
  end
249
249
 
250
250
  def cast(value, format, options = {})
251
- value ||= [] if collection?
251
+ return value if type <= Serialize && value.is_a?(type.model)
252
252
 
253
+ value ||= [] if collection?
253
254
  if value.is_a?(Array)
254
- value.map do |v|
255
- cast(v, format, options)
256
- end
257
- elsif type <= Serialize && value.is_a?(Hash)
255
+ value.map { |v| cast(v, format, options) }
256
+ elsif type <= Serialize && castable?(value, format)
258
257
  type.apply_mappings(value, format, options)
259
258
  elsif !value.nil? && !value.is_a?(type)
260
259
  type.send(:"from_#{format}", value)
@@ -265,6 +264,11 @@ module Lutaml
265
264
 
266
265
  private
267
266
 
267
+ def castable?(value, format)
268
+ value.is_a?(Hash) ||
269
+ (format == :xml && value.is_a?(Lutaml::Model::XmlAdapter::XmlElement))
270
+ end
271
+
268
272
  def validate_options!(options)
269
273
  if (invalid_opts = options.keys - ALLOWED_OPTIONS).any?
270
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 { |attribute_group| required_files_attribute_groups(attribute_group) }
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
@@ -493,8 +493,9 @@ module Lutaml
493
493
 
494
494
  raise Lutaml::Model::CollectionTrueMissingError(self, option[:caller_class]) if doc.is_a?(Array)
495
495
 
496
+ doc_order = doc.root.order
496
497
  if instance.respond_to?(:ordered=)
497
- instance.element_order = doc.root.order
498
+ instance.element_order = doc_order
498
499
  instance.ordered = mappings_for(:xml).ordered? || options[:ordered]
499
500
  instance.mixed = mappings_for(:xml).mixed_content? || options[:mixed_content]
500
501
  end
@@ -512,7 +513,7 @@ module Lutaml
512
513
  end
513
514
 
514
515
  defaults_used = []
515
- validate_sequence!(instance.element_order)
516
+ validate_sequence!(doc_order)
516
517
 
517
518
  mappings.each do |rule|
518
519
  raise "Attribute '#{rule.to}' not found in #{self}" unless valid_rule?(rule)
@@ -534,9 +535,7 @@ module Lutaml
534
535
  rule.deserialize(instance, value, attributes, self)
535
536
  end
536
537
 
537
- defaults_used.each do |attribute_name|
538
- instance.using_default_for(attribute_name)
539
- end
538
+ defaults_used.each { |attr_name| instance.using_default_for(attr_name) }
540
539
 
541
540
  instance
542
541
  end
@@ -548,9 +547,8 @@ module Lutaml
548
547
  doc.root.find_attribute_value(rule_names)
549
548
  else
550
549
  attr = attribute_for_rule(rule)
551
-
552
550
  children = doc.children.select do |child|
553
- rule_names.include?(child.namespaced_name)
551
+ rule_names.include?(child.namespaced_name) && !child.text?
554
552
  end
555
553
 
556
554
  if rule.using_custom_methods? || attr.type == Lutaml::Model::Type::Hash
@@ -570,7 +568,7 @@ module Lutaml
570
568
 
571
569
  values = children.map do |child|
572
570
  if !rule.using_custom_methods? && attr.type <= Serialize
573
- attr.type.apply_xml_mapping(child, attr.type.new, options.except(:mappings))
571
+ attr.cast(child, :xml, options.except(:mappings))
574
572
  elsif attr.raw?
575
573
  inner_xml_of(child)
576
574
  else
@@ -27,10 +27,6 @@ module Lutaml
27
27
  def to_json(*_args)
28
28
  value
29
29
  end
30
-
31
- def to_yaml
32
- value
33
- end
34
30
  end
35
31
  end
36
32
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.6.0"
5
+ VERSION = "0.6.2"
6
6
  end
7
7
  end
@@ -23,10 +23,6 @@ module Lutaml
23
23
  @root.children
24
24
  end
25
25
 
26
- def root
27
- @root
28
- end
29
-
30
26
  def attributes
31
27
  root.attributes
32
28
  end
@@ -6,10 +6,8 @@ module Lutaml
6
6
  class XmlElement
7
7
  attr_reader :attributes,
8
8
  :children,
9
- :text,
10
9
  :namespace_prefix,
11
- :parent_document,
12
- :default_namespace
10
+ :parent_document
13
11
 
14
12
  attr_accessor :adapter_node
15
13
 
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(:person1) do
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(:person2) do
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: [person1, person2],
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" => 5,
65
- "Ox Adapter" => 15,
66
- "Oga Adapter" => 5,
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"])
@@ -5,13 +5,53 @@ class CustomModelChild
5
5
  end
6
6
 
7
7
  class CustomModelParent
8
- attr_accessor :first_name, :middle_name, :last_name, :child_mapper
8
+ attr_accessor :first_name, :middle_name, :last_name, :child_mapper, :math
9
9
 
10
10
  def name
11
11
  "#{first_name} #{last_name}"
12
12
  end
13
13
  end
14
14
 
15
+ class GenericFormulaClass
16
+ attr_accessor :value
17
+ end
18
+
19
+ class Mi < Lutaml::Model::Serializable
20
+ model GenericFormulaClass
21
+
22
+ attribute :value, :string
23
+
24
+ xml do
25
+ root "mi"
26
+
27
+ map_content to: :value
28
+ end
29
+ end
30
+
31
+ class Mstyle < Lutaml::Model::Serializable
32
+ model GenericFormulaClass
33
+
34
+ attribute :value, Mi, collection: true
35
+
36
+ xml do
37
+ root "mstyle"
38
+
39
+ map_element :mi, to: :value
40
+ end
41
+ end
42
+
43
+ class MmlMath < Lutaml::Model::Serializable
44
+ model GenericFormulaClass
45
+
46
+ attribute :value, Mstyle, collection: true
47
+
48
+ xml do
49
+ root "math"
50
+
51
+ map_element :mstyle, to: :value
52
+ end
53
+ end
54
+
15
55
  class CustomModelChildMapper < Lutaml::Model::Serializable
16
56
  model CustomModelChild
17
57
 
@@ -31,6 +71,7 @@ class CustomModelParentMapper < Lutaml::Model::Serializable
31
71
  attribute :middle_name, Lutaml::Model::Type::String
32
72
  attribute :last_name, Lutaml::Model::Type::String
33
73
  attribute :child_mapper, CustomModelChildMapper
74
+ attribute :math, MmlMath
34
75
 
35
76
  xml do
36
77
  map_element :first_name, to: :first_name
@@ -38,6 +79,7 @@ class CustomModelParentMapper < Lutaml::Model::Serializable
38
79
  map_element :last_name, to: :last_name
39
80
  map_element :CustomModelChild,
40
81
  with: { to: :child_to_xml, from: :child_from_xml }
82
+ map_element :math, to: :math
41
83
  end
42
84
 
43
85
  def child_to_xml(model, parent, doc)
@@ -317,6 +359,11 @@ RSpec.describe "CustomModel" do
317
359
  <street>Oxford Street</street>
318
360
  <city>London</city>
319
361
  </CustomModelChild>
362
+ <math>
363
+ <mstyle>
364
+ <mi>Math</mi>
365
+ </mstyle>
366
+ </math>
320
367
  </CustomModelParent>
321
368
  XML
322
369
  end
@@ -333,6 +380,7 @@ RSpec.describe "CustomModel" do
333
380
  expect(instance.child_mapper.class).to eq(child_model)
334
381
  expect(instance.child_mapper.street).to eq("Oxford Street")
335
382
  expect(instance.child_mapper.city).to eq("London")
383
+ expect(instance.math.value.first.value.first.value).to eq("Math")
336
384
  end
337
385
  end
338
386
 
@@ -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.shared_examples "a JSON adapter" do |adapter_class|
7
- let(:attributes) { { name: "John Doe", age: 30 } }
8
- let(:model) { SampleModel.new(attributes) }
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
- let(:expected_json) do
11
- if adapter_class == Lutaml::Model::JsonAdapter::StandardJsonAdapter
12
- JSON.generate(attributes)
13
- elsif adapter_class == Lutaml::Model::JsonAdapter::MultiJsonAdapter
14
- MultiJson.dump(attributes)
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
- it "serializes to JSON" do
19
- json = adapter_class.new(attributes).to_json
20
- expect(json).to eq(expected_json)
21
- end
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
- it "deserializes from JSON" do
24
- doc = adapter_class.parse(expected_json)
25
- new_model = SampleModel.new(doc.to_h)
26
- expect(new_model.name).to eq("John Doe")
27
- expect(new_model.age).to eq(30)
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
- RSpec.describe Lutaml::Model::JsonAdapter::StandardJsonAdapter do
32
- it_behaves_like "a JSON adapter", described_class
33
- end
32
+ describe Lutaml::Model::JsonAdapter::StandardJsonAdapter do
33
+ it_behaves_like "a JSON adapter", described_class
34
+ end
34
35
 
35
- RSpec.describe Lutaml::Model::JsonAdapter::MultiJsonAdapter do
36
- it_behaves_like "a JSON adapter", described_class
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
- RSpec.describe Lutaml::Model::Schema::JsonSchema do
5
- module SchemaGeneration
6
- class Glaze < Lutaml::Model::Serializable
7
- attribute :color, Lutaml::Model::Type::String
8
- attribute :finish, Lutaml::Model::Type::String
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
- class Vase < Lutaml::Model::Serializable
12
- attribute :height, Lutaml::Model::Type::Float
13
- attribute :diameter, Lutaml::Model::Type::Float
14
- attribute :glaze, Glaze
15
- attribute :materials, Lutaml::Model::Type::String, collection: true
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
- RSpec.describe Lutaml::Model::Schema::RelaxngSchema do
5
- module SchemaGeneration
6
- class Glaze < Lutaml::Model::Serializable
7
- attribute :color, Lutaml::Model::Type::String
8
- attribute :finish, Lutaml::Model::Type::String
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
- class Vase < Lutaml::Model::Serializable
12
- attribute :height, Lutaml::Model::Type::Float
13
- attribute :diameter, Lutaml::Model::Type::Float
14
- attribute :glaze, Glaze
15
- attribute :materials, Lutaml::Model::Type::String, collection: true
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)