lutaml-model 0.8.202 → 0.8.204

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 (123) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +5 -0
  3. data/.github/workflows/dependent-tests.yml +59 -2
  4. data/.github/workflows/lml-conformance.yml +71 -0
  5. data/.gitignore +7 -0
  6. data/README.adoc +1 -0
  7. data/docs/_guides/lml-cross-language.adoc +128 -0
  8. data/docs/_references/lml-conformance.adoc +78 -0
  9. data/docs/_references/lml-contract.adoc +290 -0
  10. data/docs/_references/plan-schema-spec.adoc +45 -18
  11. data/lib/lutaml/key_value/transform.rb +140 -21
  12. data/lib/lutaml/model/attribute.rb +11 -6
  13. data/lib/lutaml/model/lml/artifact_verifier.rb +205 -0
  14. data/lib/lutaml/model/lml/bundle.rb +171 -0
  15. data/lib/lutaml/model/lml/document.rb +46 -10
  16. data/lib/lutaml/model/lml/document_validator.rb +840 -0
  17. data/lib/lutaml/model/lml/exporter/v1_projector.rb +102 -0
  18. data/lib/lutaml/model/lml/exporter/v2_projector.rb +401 -0
  19. data/lib/lutaml/model/lml/exporter.rb +223 -87
  20. data/lib/lutaml/model/lml/graph_exporter.rb +248 -0
  21. data/lib/lutaml/model/lml/importer.rb +180 -0
  22. data/lib/lutaml/model/lml/mapping_compiler.rb +401 -0
  23. data/lib/lutaml/model/lml/materialization.rb +257 -0
  24. data/lib/lutaml/model/lml/ordered_content.rb +577 -0
  25. data/lib/lutaml/model/lml/portable_json.rb +385 -0
  26. data/lib/lutaml/model/lml/rejected_error.rb +64 -15
  27. data/lib/lutaml/model/lml/round_trip.rb +86 -0
  28. data/lib/lutaml/model/lml/value_declarations.rb +84 -0
  29. data/lib/lutaml/model/lml.rb +61 -0
  30. data/lib/lutaml/model/schema/definitions/attribute.rb +4 -2
  31. data/lib/lutaml/model/schema/registry_generator.rb +1 -1
  32. data/lib/lutaml/model/schema/renderers/member_decls.rb +1 -0
  33. data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +10 -0
  34. data/lib/lutaml/model/sequence.rb +7 -0
  35. data/lib/lutaml/model/serialize/deserialization_context.rb +21 -0
  36. data/lib/lutaml/model/serialize/initialization.rb +19 -9
  37. data/lib/lutaml/model/version.rb +1 -1
  38. data/lib/lutaml/xml/leptris/native_emission.rb +4 -0
  39. data/lib/lutaml/xml/leptris/plan_serializer.rb +14 -9
  40. data/schema/lml/document.schema.json +179 -0
  41. data/scripts/lml/export_choices.rb +57 -0
  42. data/scripts/lml/export_conformance.rb +23 -0
  43. data/scripts/lml/export_mml.rb +253 -0
  44. data/scripts/lml/export_preservation.rb +421 -0
  45. data/scripts/lml/verify_artifacts.rb +31 -0
  46. data/spec/address_person_spec.rb +8 -0
  47. data/spec/address_spec.rb +4 -0
  48. data/spec/fixtures/lml_artifacts/model.json +1 -0
  49. data/spec/fixtures/lml_artifacts/valid.json +1 -0
  50. data/spec/fixtures/lml_artifacts/valid.sha256 +1 -0
  51. data/spec/fixtures/lml_conformance/core/index.json +1 -0
  52. data/spec/fixtures/lml_conformance/core/manifest.json +1 -0
  53. data/spec/fixtures/lml_conformance/core/schema.json +1 -0
  54. data/spec/fixtures/lml_conformance/core/schema.yaml +79 -0
  55. data/spec/fixtures/lml_conformance/float_vectors.generator.rb +60 -0
  56. data/spec/fixtures/lml_conformance/float_vectors.json +21550 -0
  57. data/spec/fixtures/lml_conformance/preservation/index.json +1 -0
  58. data/spec/fixtures/lml_conformance/preservation/manifest.json +1 -0
  59. data/spec/fixtures/lml_conformance/preservation/schema.json +1 -0
  60. data/spec/fixtures/lml_conformance/preservation/schema.yaml +319 -0
  61. data/spec/fixtures/lml_conformance/r2_refusals.generator.rb +153 -0
  62. data/spec/fixtures/lml_conformance/r2_refusals.json +1662 -0
  63. data/spec/fixtures/lml_conformance/ruby_portable_interop.generator.rb +40 -0
  64. data/spec/fixtures/lml_conformance/ruby_portable_interop.json +1 -0
  65. data/spec/fixtures/lml_contract/bundle.json +81 -0
  66. data/spec/fixtures/lml_contract/manifest.json +30 -0
  67. data/spec/fixtures/lml_contract/v1_unit.canonical.json +1 -0
  68. data/spec/fixtures/lml_contract/v1_unit.json +1 -0
  69. data/spec/fixtures/lml_contract/v2_node.canonical.json +1 -0
  70. data/spec/fixtures/lml_contract/v2_node.json +32 -0
  71. data/spec/fixtures/lml_mml/inventory.json +1 -0
  72. data/spec/fixtures/lml_mml/manifest.json +1 -0
  73. data/spec/fixtures/lml_mml/oracle.json +1 -0
  74. data/spec/fixtures/lml_mml/v3-mi-mixed.json +1 -0
  75. data/spec/fixtures/lml_mml/v3-mi-mixed.yaml +970 -0
  76. data/spec/fixtures/lml_mml/v4-mi-mixed.json +1 -0
  77. data/spec/fixtures/lml_mml/v4-mi-mixed.yaml +1516 -0
  78. data/spec/fixtures/lml_mml_materialization/replay.rb +37 -0
  79. data/spec/lutaml/key_value/group_instantiate_spec.rb +204 -1
  80. data/spec/lutaml/model/lml_any_attribute_spec.rb +91 -0
  81. data/spec/lutaml/model/lml_artifact_verifier_spec.rb +86 -0
  82. data/spec/lutaml/model/lml_builtin_types_spec.rb +49 -0
  83. data/spec/lutaml/model/lml_conformance_spec.rb +178 -0
  84. data/spec/lutaml/model/lml_document_spec.rb +279 -0
  85. data/spec/lutaml/model/lml_export_validation_spec.rb +96 -0
  86. data/spec/lutaml/model/lml_exporter_spec.rb +127 -5
  87. data/spec/lutaml/model/lml_graph_exporter_spec.rb +205 -0
  88. data/spec/lutaml/model/lml_importer_spec.rb +290 -0
  89. data/spec/lutaml/model/lml_input_hardening_spec.rb +156 -0
  90. data/spec/lutaml/model/lml_mapping_compiler_spec.rb +256 -0
  91. data/spec/lutaml/model/lml_materialization_spec.rb +138 -0
  92. data/spec/lutaml/model/lml_mml_materialization_spec.rb +54 -0
  93. data/spec/lutaml/model/lml_mml_pilot_spec.rb +150 -0
  94. data/spec/lutaml/model/lml_model_choices_spec.rb +88 -0
  95. data/spec/lutaml/model/lml_ordered_content_spec.rb +243 -0
  96. data/spec/lutaml/model/lml_portable_json_spec.rb +310 -0
  97. data/spec/lutaml/model/lml_preservation_spec.rb +211 -0
  98. data/spec/lutaml/model/lml_review_export_spec.rb +247 -0
  99. data/spec/lutaml/model/lml_review_import_spec.rb +390 -0
  100. data/spec/lutaml/model/lml_review_misc_spec.rb +152 -0
  101. data/spec/lutaml/model/lml_review_round4_spec.rb +200 -0
  102. data/spec/lutaml/model/lml_review_round5_spec.rb +194 -0
  103. data/spec/lutaml/model/lml_ruby_interop_fixture_spec.rb +37 -0
  104. data/spec/lutaml/model/lml_shared_corpus_spec.rb +132 -0
  105. data/spec/lutaml/model/lml_value_declarations_spec.rb +128 -0
  106. data/spec/lutaml/model/schema/class_loader_spec.rb +51 -0
  107. data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +20 -0
  108. data/spec/lutaml/model/sequence_spec.rb +48 -0
  109. data/spec/lutaml/model/serialize/deserialization_context_spec.rb +68 -0
  110. data/spec/lutaml/xml/cdata_emission_spec.rb +68 -0
  111. data/spec/spec_helper.rb +4 -5
  112. data/spec/support/lml_any_attribute_fixtures.rb +26 -0
  113. data/spec/support/lml_conformance.rb +292 -0
  114. data/spec/support/lml_corpus.rb +75 -0
  115. data/spec/support/lml_export_fixtures.rb +190 -0
  116. data/spec/support/lml_graph_fixtures.rb +108 -0
  117. data/spec/support/lml_import_fixtures.rb +52 -0
  118. data/spec/support/lml_mapping_fixtures.rb +170 -0
  119. data/spec/support/lml_materialization_fixtures.rb +53 -0
  120. data/spec/support/lml_model_choices_fixtures.rb +150 -0
  121. data/spec/support/lml_order_fixtures.rb +151 -0
  122. metadata +93 -2
  123. data/lib/lutaml/model/schema/schema_builder/nokogiri.rb +0 -41
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+ require_relative "lml_mapping_fixtures"
5
+
6
+ # Named source models for the LML import/export round-trip specs
7
+ # (lutaml-model#1033 card 03c). The graph mixes namespaces, nested and
8
+ # collection models, ordered/mixed content and discriminator-based
9
+ # polymorphism in all three wire formats.
10
+ module LmlImportFixtures
11
+ class Animal < Lutaml::Model::Serializable
12
+ attribute :kind, :string, polymorphic_class: true
13
+ attribute :name, :string
14
+
15
+ xml do
16
+ element "animal"
17
+ map_attribute "kind", to: :kind
18
+ map_element "name", to: :name
19
+ end
20
+ json do
21
+ map "kind", to: :kind
22
+ map "name", to: :name
23
+ end
24
+ end
25
+
26
+ class Dog < Animal
27
+ end
28
+
29
+ class Kennel < Lutaml::Model::Serializable
30
+ attribute :animals, Animal, collection: true
31
+ attribute :owner, :string
32
+
33
+ xml do
34
+ element "kennel"
35
+ map_element "animal", to: :animals, polymorphic: {
36
+ attribute: "kind", class_map: { "dog" => "LmlImportFixtures::Dog", "animal" => "LmlImportFixtures::Animal" }
37
+ }
38
+ map_element "owner", to: :owner
39
+ end
40
+ json do
41
+ map "animals", to: :animals, polymorphic: {
42
+ attribute: "kind", class_map: { "dog" => "LmlImportFixtures::Dog", "animal" => "LmlImportFixtures::Animal" }
43
+ }
44
+ map "owner", to: :owner
45
+ end
46
+ end
47
+
48
+ GRAPH_ROOTS = [
49
+ LmlMappingFixtures::Doc, LmlMappingFixtures::Shape,
50
+ LmlOrderFixtures::Para, LmlOrderFixtures::Transport, Kennel
51
+ ].freeze
52
+ end
@@ -0,0 +1,170 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+ require "lutaml/model/lml/exporter"
5
+ require "lutaml/model/lml/document_validator"
6
+ require_relative "lml_order_fixtures"
7
+
8
+ # Named source models and a fresh-graph helper for the LML
9
+ # MappingCompiler specs (lutaml-model#1033 card 03b). The helper
10
+ # declares attributes the way Materialization (03a) does, so these
11
+ # specs do not depend on 03a being merged.
12
+ module LmlMappingFixtures
13
+ class Ns < Lutaml::Xml::Namespace
14
+ uri "urn:lml-map:a"
15
+ prefix_default "m"
16
+ end
17
+
18
+ class Entry < Lutaml::Model::Serializable
19
+ attribute :name, :string
20
+ attribute :value, :string
21
+
22
+ xml do
23
+ element "entry"
24
+ map_attribute "name", to: :name
25
+ map_content to: :value
26
+ end
27
+ json do
28
+ map "name", to: :name
29
+ map "value", to: :value
30
+ end
31
+ end
32
+
33
+ class Item < Lutaml::Model::Serializable
34
+ attribute :id, :string
35
+ attribute :label, :string
36
+
37
+ xml do
38
+ element "item"
39
+ namespace Ns
40
+ map_attribute "id", to: :id
41
+ map_content to: :label, cdata: true
42
+ end
43
+ json do
44
+ map "id", to: :id
45
+ map "label", to: :label
46
+ end
47
+ end
48
+
49
+ class Doc < Lutaml::Model::Serializable
50
+ attribute :kind, :string, values: %w[a b], default: "a"
51
+ attribute :title, :string
52
+ attribute :note, :string
53
+ attribute :count, :integer, required: true
54
+ attribute :items, Item, collection: true
55
+ attribute :entries, Entry, collection: 0..5
56
+
57
+ xml do
58
+ element "doc"
59
+ namespace Ns
60
+ map_attribute "kind", to: :kind, render_nil: true
61
+ map_element "title", to: :title, render_nil: :as_blank
62
+ map_element "note", to: :note, render_empty: :as_blank, render_default: true,
63
+ namespace: nil
64
+ map_element "count", to: :count
65
+ map_element "item", to: :items
66
+ map_element "entry", to: :entries
67
+ end
68
+ json do
69
+ map "kind", to: :kind
70
+ map "title", to: :title, render_nil: :as_empty
71
+ map "count", to: :count, render_default: true
72
+ map "items", to: :items
73
+ map "entries", to: :entries
74
+ end
75
+ yaml do
76
+ map "title", to: :title
77
+ map "items", to: :items
78
+ end
79
+ end
80
+
81
+ class Circle < Lutaml::Model::Serializable
82
+ attribute :kind, :string
83
+ attribute :radius, :integer
84
+ xml do
85
+ element "circle"
86
+ map_attribute "kind", to: :kind
87
+ map_element "radius", to: :radius
88
+ end
89
+ json do
90
+ map "kind", to: :kind
91
+ map "radius", to: :radius
92
+ end
93
+ end
94
+
95
+ class Shape < Lutaml::Model::Serializable
96
+ attribute :child, Circle
97
+ xml do
98
+ element "shape"
99
+ map_element "circle", to: :child
100
+ end
101
+ json do
102
+ map "child", to: :child
103
+ end
104
+ end
105
+
106
+ SOURCES = [Doc, Item, Entry, Circle, Shape, LmlOrderFixtures::Para,
107
+ LmlOrderFixtures::Emphasis, LmlOrderFixtures::Transport].freeze
108
+
109
+ module_function
110
+
111
+ # Neutral bundle (string keys) of the given source classes.
112
+ def bundle_for(*classes)
113
+ models = classes.to_h do |klass|
114
+ doc = Lutaml::Model::Lml::Exporter.project(klass)
115
+ ["#{doc['model']}@#{doc['register']}", doc]
116
+ end.sort.to_h
117
+ { "lml_bundle" => 1, "roots" => models.keys.sort, "models" => models, "value_types" => {},
118
+ "capabilities" => %w[json xml yaml] }
119
+ end
120
+
121
+ # The exporter does not project rule-level discriminators or
122
+ # child_mappings yet (see the card report), so specs author them.
123
+ def with_discriminator(bundle, id: "LmlMappingFixtures::Shape@default",
124
+ target: "LmlMappingFixtures::Circle@default")
125
+ copy = Marshal.load(Marshal.dump(bundle))
126
+ disc = { "attribute" => "kind", "cases" => { "circle" => target } }
127
+ mappings = copy["models"][id]["mappings"]
128
+ mappings["xml"]["rules"][0]["discriminator"] = disc
129
+ mappings["json"]["rules"][0]["discriminator"] = disc
130
+ copy
131
+ end
132
+
133
+ def with_child_mappings(bundle, id: "LmlMappingFixtures::Doc@default")
134
+ copy = Marshal.load(Marshal.dump(bundle))
135
+ rule = copy["models"][id]["mappings"]["json"]["rules"].find { |r| r["to"] == "entries" }
136
+ rule["child_mappings"] = { "name" => "key", "value" => "value" }
137
+ copy
138
+ end
139
+
140
+ # Fresh classes (attributes only) installed under +holder+, keyed by
141
+ # model id. +prefix+ lets the same bundle be built into two holders.
142
+ def fresh_classes(bundle, holder)
143
+ classes = bundle["models"].to_h do |id, doc|
144
+ klass = Class.new(Lutaml::Model::Serializable)
145
+ holder.const_set(doc["model"].split("::").last, klass)
146
+ [id, klass]
147
+ end
148
+ bundle["models"].each { |id, doc| declare_attributes(classes[id], doc, classes) }
149
+ classes
150
+ end
151
+
152
+ def declare_attributes(klass, doc, classes)
153
+ doc["attributes"].each do |attr|
154
+ type = attr["type"]
155
+ type = type["kind"] == "model" ? classes.fetch(type["id"]) : type["name"].to_sym
156
+ options = {}
157
+ options[:required] = true if attr["required"]
158
+ options[:values] = attr["values"] if attr["values"]
159
+ options[:default] = attr["default"]["value"] if attr.dig("default", "present")
160
+ options[:collection] = collection(attr["collection"]) if attr["collection"]
161
+ klass.attribute(attr["name"].to_sym, type, **options)
162
+ end
163
+ end
164
+
165
+ def collection(spec)
166
+ return true if spec == true
167
+
168
+ spec["min"]..(spec["max"] || Float::INFINITY)
169
+ end
170
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Hand-authored contract (01) bundles for Materialization specs. String
4
+ # keys, as DocumentValidator emits them. No Ruby model constants exist
5
+ # for these ids: materialization must work from the data alone.
6
+ module LmlMaterializationFixtures
7
+ module_function
8
+
9
+ def string_type
10
+ { "kind" => "builtin", "name" => "string" }
11
+ end
12
+
13
+ def model_type(id)
14
+ { "kind" => "model", "id" => id }
15
+ end
16
+
17
+ def model(name, attributes, register: "default")
18
+ { "lml" => 2, "model" => name, "register" => register, "attributes" => attributes }
19
+ end
20
+
21
+ def bundle(models)
22
+ { "lml_bundle" => 1, "roots" => models.keys.sort, "models" => models,
23
+ "value_types" => {}, "capabilities" => [] }
24
+ end
25
+
26
+ # Order -> Line (collection) -> Order (cycle), Order has a self-tree.
27
+ def cyclic
28
+ order = "Shop::Order@default"
29
+ line = "Shop::Line@default"
30
+ bundle(
31
+ order => model("Shop::Order", [
32
+ { "name" => "id", "type" => string_type, "required" => true },
33
+ { "name" => "status", "type" => string_type, "values" => %w[open closed],
34
+ "default" => { "present" => true, "value" => "open" } },
35
+ { "name" => "lines", "type" => model_type(line),
36
+ "collection" => { "min" => 0, "max" => nil } },
37
+ { "name" => "parent", "type" => model_type(order) },
38
+ ]),
39
+ line => model("Shop::Line", [
40
+ { "name" => "sku", "type" => string_type },
41
+ { "name" => "order", "type" => model_type(order) },
42
+ { "name" => "qty", "type" => string_type,
43
+ "collection" => { "min" => 1, "max" => 3 } },
44
+ ]),
45
+ )
46
+ end
47
+
48
+ def with_value_type
49
+ bundle("Shop::Item@default" => model("Shop::Item", [
50
+ { "name" => "code", "type" => { "kind" => "value", "id" => "Shop::Sku" } },
51
+ ]))
52
+ end
53
+ end
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+ require "lutaml/model/lml"
5
+
6
+ module LmlModelChoicesFixtures
7
+ class Plain < Lutaml::Model::Serializable
8
+ choice(min: 1, max: 1) do
9
+ attribute :a, :string
10
+ attribute :b, :string
11
+ end
12
+ json do
13
+ map "a", to: :a
14
+ map "b", to: :b
15
+ end
16
+ xml do
17
+ root "choice"
18
+ map_element "a", to: :a
19
+ map_element "b", to: :b
20
+ end
21
+ end
22
+
23
+ class Nested < Lutaml::Model::Serializable
24
+ choice(min: 1, max: 1) do
25
+ choice(min: 1, max: 1) do
26
+ attribute :a, :string
27
+ attribute :b, :string
28
+ end
29
+ attribute :c, :string
30
+ end
31
+ json do
32
+ map "a", to: :a
33
+ map "b", to: :b
34
+ map "c", to: :c
35
+ end
36
+ xml do
37
+ root "choice"
38
+ map_element "a", to: :a
39
+ map_element "b", to: :b
40
+ map_element "c", to: :c
41
+ end
42
+ end
43
+
44
+ class OptionalCollection < Lutaml::Model::Serializable
45
+ choice(min: 1, max: 1) do
46
+ attribute :a, :string, collection: 0..2
47
+ attribute :b, :string
48
+ end
49
+ json do
50
+ map "a", to: :a
51
+ map "b", to: :b
52
+ end
53
+ xml do
54
+ root "choice"
55
+ map_element "a", to: :a
56
+ map_element "b", to: :b
57
+ end
58
+ end
59
+
60
+ class BooleanMember < Lutaml::Model::Serializable
61
+ choice(min: 1, max: 1) do
62
+ attribute :a, :boolean
63
+ attribute :b, :string
64
+ end
65
+ json do
66
+ map "a", to: :a
67
+ map "b", to: :b
68
+ end
69
+ xml do
70
+ root "choice"
71
+ map_element "a", to: :a
72
+ map_element "b", to: :b
73
+ end
74
+ end
75
+ end
76
+
77
+ module LmlModelChoicesFixtures
78
+ class Renderable < Lutaml::Model::Serializable
79
+ choice(min: 1, max: 1) do
80
+ attribute :a, :string
81
+ attribute :b, :string
82
+ end
83
+ json do
84
+ map "a", to: :a
85
+ map "b", to: :b
86
+ end
87
+ xml do
88
+ root "choice"
89
+ map_element "a", to: :a, render_empty: true
90
+ map_element "b", to: :b, render_empty: true
91
+ end
92
+ end
93
+
94
+ class Unbounded < Lutaml::Model::Serializable
95
+ choice(min: 1, max: Float::INFINITY) do
96
+ attribute :a, :string, collection: 1..2
97
+ attribute :b, :string
98
+ end
99
+ json do
100
+ map "a", to: :a
101
+ map "b", to: :b
102
+ end
103
+ xml do
104
+ root "choice"
105
+ map_element "a", to: :a
106
+ map_element "b", to: :b
107
+ end
108
+ end
109
+
110
+ class NestedOptional < Lutaml::Model::Serializable
111
+ choice(min: 1, max: 1) do
112
+ choice(min: 0, max: 1) do
113
+ attribute :a, :string
114
+ attribute :b, :string
115
+ end
116
+ attribute :c, :string
117
+ end
118
+ json do
119
+ map "a", to: :a
120
+ map "b", to: :b
121
+ map "c", to: :c
122
+ end
123
+ xml do
124
+ root "choice"
125
+ map_element "a", to: :a
126
+ map_element "b", to: :b
127
+ map_element "c", to: :c
128
+ end
129
+ end
130
+
131
+ class Parent < Lutaml::Model::Serializable
132
+ attribute :child, Plain
133
+ json { map "child", to: :child }
134
+ xml do
135
+ root "parent"
136
+ map_element "child", to: :child
137
+ end
138
+ end
139
+ CASES = {
140
+ "Plain" => [{}, { a: nil }, { a: "" }, { a: " " }, { a: "x" }, { b: "y" }, { a: "x", b: "y" }],
141
+ "Nested" => [{}, { a: "x" }, { b: "y" }, { c: "z" }, { a: "x", b: "y" }, { a: "x", c: "z" }],
142
+ "OptionalCollection" => [{}, { a: [] }, { a: ["x"] }, { a: ["x", "y"] }, { a: ["x", "y", "z"] }, { b: "y" }, { a: ["x"], b: "y" }],
143
+ "BooleanMember" => [{}, { a: false }, { a: true }, { a: false, b: "y" }],
144
+ }.merge(
145
+ "Renderable" => [{}, { a: "" }, { a: "", b: "" }],
146
+ "Unbounded" => [{}, { a: [] }, { a: ["x"] }, { a: ["x", "y", "z"] }, { a: ["x"], b: "y" }],
147
+ "NestedOptional" => [{}, { a: "x" }, { c: "z" }, { a: "x", b: "y" }, { a: "x", c: "z" }],
148
+ "Parent" => [{}, { child: {} }, { child: { a: "x" } }, { child: { a: "x", b: "y" } }],
149
+ ).freeze
150
+ end
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ # Named fixtures for LML ordered-content capture/apply specs. The LML
6
+ # document addresses models by class path, so they must be nameable.
7
+ module LmlOrderFixtures
8
+ class NsA < Lutaml::Xml::Namespace
9
+ uri "urn:lml-order:a"
10
+ prefix_default "a"
11
+ end
12
+
13
+ class NsB < Lutaml::Xml::Namespace
14
+ uri "urn:lml-order:b"
15
+ prefix_default "b"
16
+ end
17
+
18
+ class Emphasis < Lutaml::Model::Serializable
19
+ attribute :value, :string
20
+
21
+ xml do
22
+ element "em"
23
+ map_content to: :value
24
+ end
25
+ end
26
+
27
+ # Mixed content: repeated interleaved elements, text and CDATA.
28
+ class Para < Lutaml::Model::Serializable
29
+ attribute :em, Emphasis, collection: true
30
+ attribute :bold, :string, collection: true
31
+ attribute :note, :string
32
+ attribute :text, :string, collection: true
33
+
34
+ xml do
35
+ element "p"
36
+ mixed_content
37
+ map_element "em", to: :em
38
+ map_element "b", to: :bold
39
+ map_element "note", to: :note
40
+ map_content to: :text
41
+ end
42
+ end
43
+
44
+ # Element-only `ordered` model with repeated interleaved elements.
45
+ class Transport < Lutaml::Model::Serializable
46
+ attribute :car, :string, collection: true
47
+ attribute :boat, :string, collection: true
48
+
49
+ xml do
50
+ element "transportation"
51
+ ordered
52
+ map_element "car", to: :car
53
+ map_element "boat", to: :boat
54
+ end
55
+ end
56
+
57
+ class ItemA < Lutaml::Model::Serializable
58
+ attribute :value, :string
59
+
60
+ xml do
61
+ element "item"
62
+ namespace NsA
63
+ map_content to: :value
64
+ end
65
+ end
66
+
67
+ class ItemB < Lutaml::Model::Serializable
68
+ attribute :value, :string
69
+
70
+ xml do
71
+ element "item"
72
+ namespace NsB
73
+ map_content to: :value
74
+ end
75
+ end
76
+
77
+ # Two same-named elements told apart only by namespace.
78
+ class Namespaced < Lutaml::Model::Serializable
79
+ attribute :a_items, ItemA, collection: true
80
+ attribute :b_items, ItemB, collection: true
81
+
82
+ xml do
83
+ element "root"
84
+ namespace NsA
85
+ ordered
86
+ map_element "item", to: :a_items
87
+ map_element "item", to: :b_items
88
+ end
89
+ end
90
+
91
+ # An element member whose output is produced by a custom method.
92
+ class ImperativeRule < Lutaml::Model::Serializable
93
+ attribute :car, :string, collection: true
94
+
95
+ xml do
96
+ element "imperative"
97
+ ordered
98
+ map_element "car", to: :car, with: { to: :car_to_xml, from: :car_from_xml }
99
+ end
100
+
101
+ def car_to_xml(_model, _parent, _doc); end
102
+
103
+ def car_from_xml(model, value)
104
+ model.car = Array(value)
105
+ end
106
+ end
107
+
108
+ # A class that generates its own element order.
109
+ class ImperativeOrder < Lutaml::Model::Serializable
110
+ attribute :car, :string, collection: true
111
+
112
+ xml do
113
+ element "imperative"
114
+ ordered
115
+ map_element "car", to: :car
116
+ end
117
+
118
+ def element_order
119
+ Array(car).map { |_| Lutaml::Xml::Element.new("Element", "car") }
120
+ end
121
+ end
122
+
123
+ class ReservedMember < Lutaml::Model::Serializable
124
+ attribute :__lml_content, :string, collection: true
125
+ attribute :car, :string
126
+
127
+ xml do
128
+ element "reserved"
129
+ ordered
130
+ map_element "car", to: :car
131
+ end
132
+ end
133
+
134
+ # No per-instance order at all.
135
+ class Plain < Lutaml::Model::Serializable
136
+ attribute :car, :string
137
+
138
+ xml do
139
+ element "plain"
140
+ map_element "car", to: :car
141
+ end
142
+ end
143
+
144
+ PARA_XML = "<p>hi <em>a</em> mid <![CDATA[cd]]> <b>x</b><em>b</em> " \
145
+ "<note>n</note> tail</p>"
146
+ TRANSPORT_XML = "<transportation><car>1</car><boat>2</boat><car>3</car>" \
147
+ "<boat>4</boat><car>5</car></transportation>"
148
+ NAMESPACED_XML = '<a:root xmlns:a="urn:lml-order:a" xmlns:b="urn:lml-order:b">' \
149
+ "<a:item>1</a:item><b:item>2</b:item><a:item>3</a:item>" \
150
+ "<b:item>4</b:item></a:root>"
151
+ end