lutaml-model 0.8.12 → 0.8.13

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 (121) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +116 -103
  3. data/RELEASE_NOTES.adoc +3 -3
  4. data/benchmark/quick_benchmark.rb +2 -2
  5. data/benchmark/serialization_benchmark.rb +4 -4
  6. data/docs/_guides/advanced-mapping.adoc +1 -1
  7. data/docs/_guides/character-encoding.adoc +3 -3
  8. data/docs/_guides/missing-values-handling.adoc +6 -6
  9. data/docs/_guides/ooxml-examples.adoc +7 -7
  10. data/docs/_guides/opal.adoc +1 -1
  11. data/docs/_guides/value-transformations.adoc +7 -7
  12. data/docs/_guides/xml/namespace-presentation.adoc +1 -1
  13. data/docs/_guides/xml/namespace-semantics.adoc +15 -15
  14. data/docs/_guides/xml/type-namespaces.adoc +9 -9
  15. data/docs/_guides/xml-mapping.adoc +32 -26
  16. data/docs/_guides/xml-namespace-qualification.adoc +4 -4
  17. data/docs/_guides/xml-namespaces.adoc +2 -2
  18. data/docs/_guides/xml_mappings/04_xml_namespace_class.adoc +18 -18
  19. data/docs/_guides/xml_mappings/05_common_patterns.adoc +16 -16
  20. data/docs/_guides/xml_mappings/06_migration_guide.adoc +5 -5
  21. data/docs/_guides/xml_mappings/07_best_practices.adoc +11 -11
  22. data/docs/_migrations/0-8-0-namespace-restructuring.adoc +2 -2
  23. data/docs/_pages/attributes.adoc +2 -2
  24. data/docs/_pages/collections.adoc +26 -20
  25. data/docs/_pages/consolidation-mapping.adoc +4 -4
  26. data/docs/_pages/importable_models.adoc +14 -13
  27. data/docs/_pages/quick-start.adoc +1 -1
  28. data/docs/_pages/value_types.adoc +10 -10
  29. data/docs/_references/custom_registers.adoc +7 -7
  30. data/docs/_references/format-independent-features.adoc +4 -4
  31. data/docs/_references/instance-serialization.adoc +1 -1
  32. data/docs/_references/parent-root-context.adoc +3 -3
  33. data/docs/_tutorials/basic-model-definition.adoc +1 -1
  34. data/docs/_tutorials/first-xml-serialization.adoc +4 -4
  35. data/docs/_tutorials/lutaml-xml-architecture.adoc +4 -4
  36. data/docs/_tutorials/validation-basics.adoc +1 -1
  37. data/docs/_tutorials/working-with-collections.adoc +2 -2
  38. data/docs/_tutorials/xml-namespaces-basics.adoc +1 -1
  39. data/docs/_tutorials/xml-schema-primer-style-guide.adoc +29 -29
  40. data/docs/cli_compare.adoc +1 -1
  41. data/docs/index.adoc +1 -1
  42. data/docs/namespace-management.adoc +14 -14
  43. data/lib/lutaml/key_value/mapping.rb +31 -6
  44. data/lib/lutaml/model/collection.rb +11 -11
  45. data/lib/lutaml/model/error/no_root_mapping_error.rb +6 -5
  46. data/lib/lutaml/model/error/no_root_namespace_error.rb +6 -5
  47. data/lib/lutaml/model/error/type_only_mapping_error.rb +13 -0
  48. data/lib/lutaml/model/error/type_only_namespace_error.rb +12 -0
  49. data/lib/lutaml/model/version.rb +1 -1
  50. data/lib/lutaml/model.rb +3 -0
  51. data/lib/lutaml/xml/adapter/base_adapter.rb +0 -9
  52. data/lib/lutaml/xml/adapter/nokogiri_adapter.rb +0 -1
  53. data/lib/lutaml/xml/adapter/oga_adapter.rb +0 -1
  54. data/lib/lutaml/xml/adapter/ox_adapter.rb +0 -1
  55. data/lib/lutaml/xml/adapter/rexml_adapter.rb +0 -1
  56. data/lib/lutaml/xml/adapter/xml_serializer.rb +42 -22
  57. data/lib/lutaml/xml/adapter.rb +4 -0
  58. data/lib/lutaml/xml/builder/base.rb +64 -25
  59. data/lib/lutaml/xml/builder/nokogiri.rb +0 -2
  60. data/lib/lutaml/xml/builder/oga.rb +0 -2
  61. data/lib/lutaml/xml/builder/ox.rb +0 -2
  62. data/lib/lutaml/xml/builder/rexml.rb +0 -2
  63. data/lib/lutaml/xml/builder.rb +1 -0
  64. data/lib/lutaml/xml/configurable.rb +2 -2
  65. data/lib/lutaml/xml/declaration_handler.rb +3 -105
  66. data/lib/lutaml/xml/mapping.rb +3 -3
  67. data/lib/lutaml/xml/schema/xsd/documentation.rb +1 -1
  68. data/lib/lutaml/xml/serialization/collection_ext.rb +7 -7
  69. data/lib/lutaml/xml/serialization/format_conversion.rb +1 -1
  70. data/lib/lutaml/xml/serialization/instance_methods.rb +1 -1
  71. data/lib/lutaml/xml.rb +1 -2
  72. data/lib/tasks/memory_profile.rb +2 -2
  73. data/lib/tasks/performance_benchmark.rb +5 -5
  74. data/spec/lutaml/key_value/transformation/rule_compiler_spec.rb +1 -1
  75. data/spec/lutaml/key_value/transformation/value_serializer_spec.rb +1 -1
  76. data/spec/lutaml/model/attribute_collection_spec.rb +1 -1
  77. data/spec/lutaml/model/cli_spec.rb +1 -1
  78. data/spec/lutaml/model/collection_spec.rb +1 -1
  79. data/spec/lutaml/model/collection_validation_spec.rb +6 -6
  80. data/spec/lutaml/model/consolidation_spec.rb +8 -8
  81. data/spec/lutaml/model/custom_collection_spec.rb +3 -3
  82. data/spec/lutaml/model/default_register_spec.rb +23 -23
  83. data/spec/lutaml/model/delegation_spec.rb +3 -10
  84. data/spec/lutaml/model/derived_attribute_serialization_spec.rb +1 -1
  85. data/spec/lutaml/model/dynamic_attribute_spec.rb +2 -2
  86. data/spec/lutaml/model/enum_spec.rb +1 -1
  87. data/spec/lutaml/model/group_spec.rb +12 -12
  88. data/spec/lutaml/model/lazy_collection_spec.rb +4 -4
  89. data/spec/lutaml/model/mixed_content_spec.rb +2 -2
  90. data/spec/lutaml/model/namespace_versioning_spec.rb +4 -4
  91. data/spec/lutaml/model/processing_instruction_spec.rb +11 -11
  92. data/spec/lutaml/model/register_methods_spec.rb +2 -2
  93. data/spec/lutaml/model/render_empty_spec.rb +1 -1
  94. data/spec/lutaml/model/serialize_perf_guard_spec.rb +1 -1
  95. data/spec/lutaml/model/transform_dynamic_attributes_spec.rb +1 -1
  96. data/spec/lutaml/model/transformation_builder_spec.rb +2 -2
  97. data/spec/lutaml/model/xml_decoupling_spec.rb +3 -3
  98. data/spec/lutaml/model/xsd_patterns_spec.rb +2 -3
  99. data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
  100. data/spec/lutaml/xml/clear_parse_state_spec.rb +1 -1
  101. data/spec/lutaml/xml/content_model_validation_spec.rb +4 -2
  102. data/spec/lutaml/xml/doubly_defined_namespace_spec.rb +5 -5
  103. data/spec/lutaml/xml/enhanced_mapping_spec.rb +2 -1
  104. data/spec/lutaml/xml/entity_fragmentation_spec.rb +5 -5
  105. data/spec/lutaml/xml/indent_spec.rb +109 -0
  106. data/spec/lutaml/xml/line_ending_spec.rb +66 -0
  107. data/spec/lutaml/xml/mapping_finalization_guard_spec.rb +2 -2
  108. data/spec/lutaml/xml/model_transform_guard_spec.rb +4 -4
  109. data/spec/lutaml/xml/namespace_alias_spec.rb +4 -4
  110. data/spec/lutaml/xml/namespace_aware_parsing_spec.rb +3 -3
  111. data/spec/lutaml/xml/namespace_bound_element_roundtrip_spec.rb +2 -2
  112. data/spec/lutaml/xml/namespace_format_preservation_spec.rb +1 -1
  113. data/spec/lutaml/xml/namespace_inheritance_spec.rb +3 -3
  114. data/spec/lutaml/xml/namespace_preservation_spec.rb +5 -5
  115. data/spec/lutaml/xml/opal_xml_spec.rb +8 -8
  116. data/spec/lutaml/xml/pipeline_integration_spec.rb +145 -0
  117. data/spec/lutaml/xml/schema_primer_spec.rb +5 -5
  118. data/spec/lutaml/xml/transformation_spec.rb +20 -20
  119. data/spec/lutaml/xml/type_namespace/collector_spec.rb +1 -1
  120. data/spec/lutaml/xml/type_namespace/planner_spec.rb +3 -3
  121. metadata +7 -2
@@ -70,7 +70,7 @@ class Ceramic < Lutaml::Model::Serializable
70
70
  attribute :glaze, :string
71
71
 
72
72
  xml do
73
- root 'Ceramic'
73
+ element "Ceramic"
74
74
  namespace CeramicNamespace
75
75
 
76
76
  map_element 'Type', to: :type
@@ -46,7 +46,7 @@ class UsAddress < Lutaml::Model::Serializable
46
46
  attribute :zip, :decimal
47
47
 
48
48
  xml do
49
- root "USAddress"
49
+ element "USAddress"
50
50
  map_element "name", to: :name
51
51
  map_element "street", to: :street
52
52
  map_element "city", to: :city
@@ -81,7 +81,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
81
81
  attribute :comment, :string
82
82
 
83
83
  xml do
84
- root "purchaseOrder"
84
+ element "purchaseOrder"
85
85
  map_element "shipTo", to: :ship_to
86
86
  map_element "billTo", to: :bill_to
87
87
  map_element "comment", to: :comment
@@ -123,7 +123,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
123
123
  attribute :ship_to, UsAddress
124
124
 
125
125
  xml do
126
- root "purchaseOrder"
126
+ element "purchaseOrder"
127
127
  map_attribute "orderDate", to: :order_date
128
128
  map_element "shipTo", to: :ship_to
129
129
  end
@@ -157,7 +157,7 @@ class Item < Lutaml::Model::Serializable
157
157
  attribute :us_price, :decimal
158
158
 
159
159
  xml do
160
- root "Item"
160
+ element "Item"
161
161
  map_element "productName", to: :product_name
162
162
  map_element "quantity", to: :quantity
163
163
  map_element "USPrice", to: :us_price
@@ -168,7 +168,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
168
168
  attribute :items, Item, collection: true
169
169
 
170
170
  xml do
171
- root "purchaseOrder"
171
+ element "purchaseOrder"
172
172
  map_element "items", to: :items
173
173
  end
174
174
  end
@@ -239,7 +239,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
239
239
  attribute :bill_to, UsAddress
240
240
 
241
241
  xml do
242
- root "purchaseOrder"
242
+ element "purchaseOrder"
243
243
  namespace PoNamespace
244
244
 
245
245
  map_element "shipTo", to: :ship_to
@@ -288,7 +288,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
288
288
  attribute :ship_to, UsAddress
289
289
 
290
290
  xml do
291
- root "purchaseOrder"
291
+ element "purchaseOrder"
292
292
  namespace PoNamespace
293
293
 
294
294
  map_element "shipTo", to: :ship_to
@@ -350,7 +350,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
350
350
  attribute :order_date, :string
351
351
 
352
352
  xml do
353
- root "purchaseOrder"
353
+ element "purchaseOrder"
354
354
  namespace PoNamespace
355
355
 
356
356
  map_attribute "orderDate", to: :order_date
@@ -418,7 +418,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
418
418
  attribute :comment, :string # This one will be unqualified
419
419
 
420
420
  xml do
421
- root "purchaseOrder"
421
+ element "purchaseOrder"
422
422
  namespace PoNamespace
423
423
 
424
424
  map_element "shipTo", to: :ship_to
@@ -489,7 +489,7 @@ class Document < Lutaml::Model::Serializable
489
489
  attribute :title, DcTitleType # Automatically uses DcNamespace
490
490
 
491
491
  xml do
492
- root "document"
492
+ element "document"
493
493
  map_element "title", to: :title
494
494
  end
495
495
  end
@@ -542,7 +542,7 @@ class Metadata < Lutaml::Model::Serializable
542
542
  attribute :created, DctermsCreatedType
543
543
 
544
544
  xml do
545
- root "metadata"
545
+ element "metadata"
546
546
  map_element "title", to: :title
547
547
  map_element "created", to: :created
548
548
  end
@@ -586,7 +586,7 @@ class Document < Lutaml::Model::Serializable
586
586
  attribute :title, DcTitleType
587
587
 
588
588
  xml do
589
- root "document"
589
+ element "document"
590
590
  namespace ModelNamespace # Model namespace
591
591
  map_element "title", to: :title # Uses Type namespace (DcNamespace)
592
592
  end
@@ -620,7 +620,7 @@ class Document < Lutaml::Model::Serializable
620
620
  attribute :title, DcTitleType
621
621
 
622
622
  xml do
623
- root "document"
623
+ element "document"
624
624
  map_element "title", to: :title, namespace: OverrideNamespace
625
625
  end
626
626
  end
@@ -659,7 +659,7 @@ class Document < Lutaml::Model::Serializable
659
659
  attribute :schema_type, XsiTypeType
660
660
 
661
661
  xml do
662
- root "document"
662
+ element "document"
663
663
  map_attribute "name", to: :name
664
664
  map_attribute "type", to: :schema_type
665
665
  end
@@ -701,7 +701,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
701
701
  attribute :ship_to, UsAddress
702
702
 
703
703
  xml do
704
- root "purchaseOrder"
704
+ element "purchaseOrder"
705
705
  namespace PoNamespace
706
706
  map_element "shipTo", to: :ship_to
707
707
  end
@@ -749,7 +749,7 @@ The `namespace_scope` directive consolidates multiple namespace declarations at
749
749
  ----
750
750
  class Document < Lutaml::Model::Serializable
751
751
  xml do
752
- root "document"
752
+ element "document"
753
753
  namespace RootNamespace
754
754
 
755
755
  # Hoist multiple namespaces to root
@@ -794,7 +794,7 @@ class Vcard < Lutaml::Model::Serializable
794
794
  attribute :title, DcTitleType
795
795
 
796
796
  xml do
797
- root "vCard"
797
+ element "vCard"
798
798
  namespace VcardNamespace
799
799
 
800
800
  # Hoist DcNamespace to root
@@ -882,7 +882,7 @@ class Address < Lutaml::Model::Serializable
882
882
  attribute :city, :string
883
883
 
884
884
  xml do
885
- root "Address"
885
+ element "Address"
886
886
  map_element "street", to: :street
887
887
  map_element "city", to: :city
888
888
  end
@@ -893,7 +893,7 @@ class Person < Lutaml::Model::Serializable
893
893
  attribute :address, Address
894
894
 
895
895
  xml do
896
- root "Person"
896
+ element "Person"
897
897
  map_element "name", to: :name
898
898
  map_element "address", to: :address
899
899
  end
@@ -934,7 +934,7 @@ class Person < Lutaml::Model::Serializable
934
934
  attribute :work_address, AddressType
935
935
 
936
936
  xml do
937
- root "Person"
937
+ element "Person"
938
938
  map_element "homeAddress", to: :home_address
939
939
  map_element "workAddress", to: :work_address
940
940
  end
@@ -975,7 +975,7 @@ class Item < Lutaml::Model::Serializable
975
975
  attribute :price, Price
976
976
 
977
977
  xml do
978
- root "Item"
978
+ element "Item"
979
979
  map_element "name", to: :name
980
980
  map_attribute "price", to: :price
981
981
  end
@@ -1017,7 +1017,7 @@ class Product < Lutaml::Model::Serializable
1017
1017
  attribute :release_date, :date
1018
1018
 
1019
1019
  xml do
1020
- root "Product"
1020
+ element "Product"
1021
1021
  map_element "name", to: :name
1022
1022
  map_element "price", to: :price
1023
1023
  map_element "quantity", to: :quantity
@@ -1055,7 +1055,7 @@ class Item < Lutaml::Model::Serializable
1055
1055
  attribute :price, UsPriceType
1056
1056
 
1057
1057
  xml do
1058
- root "Item"
1058
+ element "Item"
1059
1059
  map_element "USPrice", to: :price
1060
1060
  end
1061
1061
  end
@@ -1106,7 +1106,7 @@ class Address < Lutaml::Model::Serializable
1106
1106
  attribute :city, :string
1107
1107
 
1108
1108
  xml do
1109
- root "Address"
1109
+ element "Address"
1110
1110
  map_element "name", to: :name
1111
1111
  map_element "street", to: :street
1112
1112
  map_element "city", to: :city
@@ -1118,7 +1118,7 @@ class InternationalAddress < Address
1118
1118
  attribute :country, :string
1119
1119
 
1120
1120
  xml do
1121
- root "InternationalAddress"
1121
+ element "InternationalAddress"
1122
1122
  map_element *Address.mappings # Inherit mappings
1123
1123
  map_element "country", to: :country
1124
1124
  end
@@ -1140,7 +1140,7 @@ class Shipment < Lutaml::Model::Serializable
1140
1140
  attribute :address, Address
1141
1141
 
1142
1142
  xml do
1143
- root "Shipment"
1143
+ element "Shipment"
1144
1144
  namespace_scope [XsiNamespace]
1145
1145
  map_element "address", to: :address
1146
1146
  end
@@ -1231,7 +1231,7 @@ class UsAddress < Lutaml::Model::Serializable
1231
1231
  attribute :zip, :decimal
1232
1232
 
1233
1233
  xml do
1234
- root "USAddress"
1234
+ element "USAddress"
1235
1235
  map_element "name", to: :name
1236
1236
  map_element "street", to: :street
1237
1237
  map_element "city", to: :city
@@ -1247,7 +1247,7 @@ class Item < Lutaml::Model::Serializable
1247
1247
  attribute :comment, :string
1248
1248
 
1249
1249
  xml do
1250
- root "Item"
1250
+ element "Item"
1251
1251
  map_element "productName", to: :product_name
1252
1252
  map_element "quantity", to: :quantity
1253
1253
  map_element "USPrice", to: :us_price
@@ -1264,7 +1264,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
1264
1264
  attribute :created, DctermsCreatedType
1265
1265
 
1266
1266
  xml do
1267
- root "purchaseOrder"
1267
+ element "purchaseOrder"
1268
1268
  namespace PoNamespace
1269
1269
 
1270
1270
  namespace_scope [
@@ -69,7 +69,7 @@ class TermiumExtract < Lutaml::Model::Serializable
69
69
  attribute :extract_language, ExtractLanguage, collection: true
70
70
 
71
71
  xml do
72
- root "termium_extract"
72
+ element "termium_extract"
73
73
  namespace "http://termium.tpsgc-pwgsc.gc.ca/schemas/2012/06/Termium", "ns2"
74
74
 
75
75
  map_attribute "language", to: :language
data/docs/index.adoc CHANGED
@@ -56,7 +56,7 @@ class Person < Lutaml::Model::Serializable
56
56
  attribute :age, :integer
57
57
 
58
58
  xml do
59
- root "person"
59
+ element "person"
60
60
  map_element "name", to: :name
61
61
  map_element "age", to: :age
62
62
  end
@@ -110,10 +110,10 @@ IMPORTANT: `namespace_scope` grants **ELIGIBILITY** to hoist namespaces to the r
110
110
  ----
111
111
  xml do
112
112
  namespace RootNamespace
113
-
113
+
114
114
  # Simple list (all use :auto mode)
115
115
  namespace_scope [Namespace1, Namespace2, Namespace3]
116
-
116
+
117
117
  # Per-namespace control with hash format
118
118
  namespace_scope [
119
119
  { namespace: Namespace1, declare: :always },
@@ -169,7 +169,7 @@ class Vcard < Lutaml::Model::Serializable
169
169
  attribute :email, :string
170
170
 
171
171
  xml do
172
- root "vCard"
172
+ element "vCard"
173
173
  namespace VcardNamespace
174
174
 
175
175
  map_element "version", to: :version
@@ -244,7 +244,7 @@ class Contact < Lutaml::Model::Serializable
244
244
  attribute :note, DcTitleType
245
245
 
246
246
  xml do
247
- root "contact"
247
+ element "contact"
248
248
 
249
249
  map_element "title", to: :title
250
250
  map_element "note", to: :note
@@ -255,7 +255,7 @@ class Vcard < Lutaml::Model::Serializable
255
255
  attribute :contact, Contact
256
256
 
257
257
  xml do
258
- root "vCard"
258
+ element "vCard"
259
259
  namespace VcardNamespace
260
260
 
261
261
  map_element "contact", to: :contact
@@ -300,7 +300,7 @@ class Vcard < Lutaml::Model::Serializable
300
300
  attribute :contact, Contact
301
301
 
302
302
  xml do
303
- root "vCard"
303
+ element "vCard"
304
304
  namespace VcardNamespace
305
305
 
306
306
  # Hoist DcNamespace to root
@@ -395,7 +395,7 @@ class Metadata < Lutaml::Model::Serializable
395
395
  attribute :format, XsiTypeType
396
396
 
397
397
  xml do
398
- root "metadata"
398
+ element "metadata"
399
399
 
400
400
  map_element "title", to: :title
401
401
  map_element "creator", to: :creator
@@ -411,7 +411,7 @@ class Vcard < Lutaml::Model::Serializable
411
411
  attribute :metadata, Metadata
412
412
 
413
413
  xml do
414
- root "vCard"
414
+ element "vCard"
415
415
  namespace VcardNamespace
416
416
 
417
417
  # Consolidate all namespaces at root
@@ -483,7 +483,7 @@ class Vcard < Lutaml::Model::Serializable
483
483
  # No DcTitleType attributes used
484
484
 
485
485
  xml do
486
- root "vCard"
486
+ element "vCard"
487
487
  namespace VcardNamespace
488
488
 
489
489
  # Try to hoist unused DcNamespace
@@ -630,7 +630,7 @@ class Parent < Lutaml::Model::Serializable
630
630
  attribute :child_value, :string
631
631
 
632
632
  xml do
633
- root "parent"
633
+ element "parent"
634
634
  namespace ParentNamespace
635
635
 
636
636
  map_element "child", to: :child_value
@@ -826,7 +826,7 @@ class Document < Lutaml::Model::Serializable
826
826
  attribute :title, DcTitleType # Automatically uses DcNamespace
827
827
 
828
828
  xml do
829
- root "document"
829
+ element "document"
830
830
  namespace DocumentNamespace
831
831
 
832
832
  map_element "title", to: :title # Becomes <dc:title>
@@ -845,7 +845,7 @@ Simplest case—all elements in one namespace:
845
845
  ----
846
846
  class Document < Lutaml::Model::Serializable
847
847
  xml do
848
- root "document"
848
+ element "document"
849
849
  namespace DocumentNamespace
850
850
  # No namespace_scope needed
851
851
  end
@@ -863,7 +863,7 @@ class Document < Lutaml::Model::Serializable
863
863
  attribute :created, DctermsCreatedType # DctermsNamespace
864
864
 
865
865
  xml do
866
- root "document"
866
+ element "document"
867
867
  namespace DocumentNamespace
868
868
  # No namespace_scope - Type namespaces hoist locally
869
869
  end
@@ -881,7 +881,7 @@ class Document < Lutaml::Model::Serializable
881
881
  attribute :created, DctermsCreatedType
882
882
 
883
883
  xml do
884
- root "document"
884
+ element "document"
885
885
  namespace DocumentNamespace
886
886
 
887
887
  # Hoist all Type namespaces to root
@@ -21,20 +21,45 @@ module Lutaml
21
21
  @finalized
22
22
  end
23
23
 
24
+ # Set the wrapper key for key-value serialization (JSON, YAML, TOML).
25
+ #
26
+ # When set, serialized output wraps all instances under this key
27
+ # (e.g., `key "items"` produces `{"items": [...]}`).
28
+ # When not called (or called with nil), instances are serialized directly
29
+ # at the top level (e.g., `[...]`).
30
+ #
31
+ # @param name [String, nil] the wrapper key name
32
+ def key(name = nil)
33
+ @key = name
34
+ end
35
+
36
+ def key_name
37
+ @key
38
+ end
39
+
40
+ # @deprecated Use {#key} instead. In key-value formats, the wrapper is a key, not a root.
24
41
  def root(name = nil)
25
- @root = name
42
+ @key = name
26
43
  end
27
44
 
45
+ # @deprecated Omit key call instead. Not calling key means no wrapper key.
28
46
  def no_root
29
- @root = nil
47
+ @key = nil
48
+ end
49
+
50
+ # Returns true when no wrapper key is set (instances serialized at top level).
51
+ def no_key?
52
+ @key.nil?
30
53
  end
31
54
 
55
+ # @deprecated Use {#no_key?} instead.
32
56
  def no_root?
33
- @root.nil?
57
+ no_key?
34
58
  end
35
59
 
60
+ # @deprecated Use {#key_name} instead.
36
61
  def root_name
37
- @root
62
+ @key
38
63
  end
39
64
 
40
65
  def map(
@@ -104,7 +129,7 @@ module Lutaml
104
129
 
105
130
  def map_instances(to:, polymorphic: {})
106
131
  @instance = to
107
- map(root_name || to, to: to, polymorphic: polymorphic)
132
+ map(key_name || to, to: to, polymorphic: polymorphic)
108
133
  map_to_instance
109
134
  end
110
135
 
@@ -125,7 +150,7 @@ module Lutaml
125
150
  def map_to_instance
126
151
  return if !instance_mapping?
127
152
 
128
- mapping_name = name_for_mapping(nil, root_name || @instance)
153
+ mapping_name = name_for_mapping(nil, key_name || @instance)
129
154
  @mappings[mapping_name].child_mappings = @key_mapping.merge(@value_mapping)
130
155
  end
131
156
 
@@ -310,8 +310,8 @@ module Lutaml
310
310
  def to(format, instance, options = {})
311
311
  mappings = mappings_for(format)
312
312
 
313
- if mappings.no_root? && collection_no_root_to?(format)
314
- collection_no_root_to(format, mappings, instance, options)
313
+ if mappings.no_root? && collection_unwrapped_to?(format)
314
+ collection_unwrapped_to(format, mappings, instance, options)
315
315
  else
316
316
  super(format, instance, options.merge(collection: true))
317
317
  end
@@ -322,7 +322,7 @@ module Lutaml
322
322
  data = super
323
323
 
324
324
  if !collection_structured_format?(format) && mappings.no_root? && !mappings.root_mapping
325
- unwrap_no_root_data(data)
325
+ unwrap_unwrapped_data(data)
326
326
  else
327
327
  data
328
328
  end
@@ -332,7 +332,7 @@ module Lutaml
332
332
  mappings = mappings_for(format)
333
333
 
334
334
  if collection_structured_format?(format) && mappings.no_root?
335
- data = wrap_no_root_input(format, mappings, data)
335
+ data = wrap_unwrapped_input(format, mappings, data)
336
336
  end
337
337
 
338
338
  super(format, data, options.merge(from_collection: true))
@@ -355,21 +355,21 @@ module Lutaml
355
355
  false
356
356
  end
357
357
 
358
- # Hook: returns true if this format handles no_root serialization specially.
358
+ # Hook: returns true if this format handles unwrapped serialization specially.
359
359
  # XML overrides to return true for :xml format.
360
- def collection_no_root_to?(_format)
360
+ def collection_unwrapped_to?(_format)
361
361
  false
362
362
  end
363
363
 
364
- # Hook for structured-format no_root serialization (e.g., XML).
364
+ # Hook for unwrapped serialization (e.g., XML).
365
365
  # XML overrides to serialize each mapping separately.
366
- def collection_no_root_to(_format, _mappings, _instance, _options)
366
+ def collection_unwrapped_to(_format, _mappings, _instance, _options)
367
367
  raise NotImplementedError
368
368
  end
369
369
 
370
- # Hook for structured-format no_root input wrapping (e.g., XML).
370
+ # Hook for wrapping unwrapped input (e.g., XML).
371
371
  # XML overrides to wrap raw data in a fake root tag.
372
- def wrap_no_root_input(_format, _mappings, data)
372
+ def wrap_unwrapped_input(_format, _mappings, data)
373
373
  data
374
374
  end
375
375
 
@@ -379,7 +379,7 @@ module Lutaml
379
379
 
380
380
  private
381
381
 
382
- def unwrap_no_root_data(data)
382
+ def unwrap_unwrapped_data(data)
383
383
  # Convert KeyValueElement to Hash if needed
384
384
  hash = data.is_a?(Hash) ? data : data.to_hash
385
385
  # Handle "__root__" wrapper for key-value formats (created by transformation)
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "type_only_mapping_error"
4
+
1
5
  module Lutaml
2
6
  module Model
3
- class NoRootMappingError < Error
4
- def initialize(model)
5
- super("#{model} has `no_root`, it allowed only for reusable models")
6
- end
7
- end
7
+ # @deprecated Use {TypeOnlyMappingError} instead.
8
+ NoRootMappingError = TypeOnlyMappingError
8
9
  end
9
10
  end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "type_only_namespace_error"
4
+
1
5
  module Lutaml
2
6
  module Model
3
- class NoRootNamespaceError < Error
4
- def to_s
5
- "Cannot assign namespace to `no_root`"
6
- end
7
- end
7
+ # @deprecated Use {TypeOnlyNamespaceError} instead.
8
+ NoRootNamespaceError = TypeOnlyNamespaceError
8
9
  end
9
10
  end
@@ -0,0 +1,13 @@
1
+ module Lutaml
2
+ module Model
3
+ class TypeOnlyMappingError < Error
4
+ def initialize(model)
5
+ super("#{model} is a type-only model (no element declared), " \
6
+ "it can only be used as an embedded type through a parent model.")
7
+ end
8
+ end
9
+
10
+ # @deprecated Use {TypeOnlyMappingError} instead.
11
+ NoRootMappingError = TypeOnlyMappingError
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Lutaml
2
+ module Model
3
+ class TypeOnlyNamespaceError < Error
4
+ def to_s
5
+ "Cannot assign namespace to a type-only model (no element declared)."
6
+ end
7
+ end
8
+
9
+ # @deprecated Use {TypeOnlyNamespaceError} instead.
10
+ NoRootNamespaceError = TypeOnlyNamespaceError
11
+ end
12
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.12"
5
+ VERSION = "0.8.13"
6
6
  end
7
7
  end
data/lib/lutaml/model.rb CHANGED
@@ -149,6 +149,7 @@ module Lutaml
149
149
  "#{__dir__}/model/error/incorrect_sequence_error"
150
150
  autoload :ChoiceUpperBoundError,
151
151
  "#{__dir__}/model/error/choice_upper_bound_error"
152
+ autoload :TypeOnlyMappingError, "#{__dir__}/model/error/type_only_mapping_error"
152
153
  autoload :NoRootMappingError, "#{__dir__}/model/error/no_root_mapping_error"
153
154
  autoload :ImportModelWithRootError,
154
155
  "#{__dir__}/model/error/import_model_with_root_error"
@@ -160,6 +161,8 @@ module Lutaml
160
161
  "#{__dir__}/model/error/choice_lower_bound_error"
161
162
  autoload :NoMappingFoundError,
162
163
  "#{__dir__}/model/error/no_mapping_found_error"
164
+ autoload :TypeOnlyNamespaceError,
165
+ "#{__dir__}/model/error/type_only_namespace_error"
163
166
  autoload :NoRootNamespaceError,
164
167
  "#{__dir__}/model/error/no_root_namespace_error"
165
168
  autoload :PolymorphicError, "#{__dir__}/model/error/polymorphic_error"
@@ -1,14 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../document"
4
- require_relative "../declaration_handler"
5
- require_relative "../doctype_extractor"
6
- require_relative "../polymorphic_value_handler"
7
- require_relative "xml_parser"
8
- require_relative "xml_serializer"
9
- require_relative "plan_based_builder"
10
- require_relative "namespace_uri_collector"
11
-
12
3
  module Lutaml
13
4
  module Xml
14
5
  module Adapter
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "moxml"
4
4
  require "moxml/adapter/nokogiri"
5
- require_relative "base_adapter"
6
5
 
7
6
  module Lutaml
8
7
  module Xml
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "oga"
4
4
  require "moxml/adapter/oga"
5
- require_relative "base_adapter"
6
5
 
7
6
  module Lutaml
8
7
  module Xml
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "moxml/adapter/ox"
4
- require_relative "base_adapter"
5
4
 
6
5
  module Lutaml
7
6
  module Xml
@@ -3,7 +3,6 @@
3
3
  require "rexml/document"
4
4
  require "moxml"
5
5
  require "moxml/adapter/rexml"
6
- require_relative "base_adapter"
7
6
 
8
7
  module Lutaml
9
8
  module Xml