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
@@ -3,9 +3,19 @@
3
3
  module Lutaml
4
4
  module Model
5
5
  module Lml
6
+ autoload :ArtifactVerifier, "#{__dir__}/lml/artifact_verifier"
7
+ autoload :Bundle, "#{__dir__}/lml/bundle"
6
8
  autoload :Document, "#{__dir__}/lml/document"
9
+ autoload :DocumentValidator, "#{__dir__}/lml/document_validator"
7
10
  autoload :Exporter, "#{__dir__}/lml/exporter"
11
+ autoload :GraphExporter, "#{__dir__}/lml/graph_exporter"
12
+ autoload :Importer, "#{__dir__}/lml/importer"
13
+ autoload :MappingCompiler, "#{__dir__}/lml/mapping_compiler"
14
+ autoload :Materialization, "#{__dir__}/lml/materialization"
15
+ autoload :OrderedContent, "#{__dir__}/lml/ordered_content"
16
+ autoload :PortableJson, "#{__dir__}/lml/portable_json"
8
17
  autoload :RejectedError, "#{__dir__}/lml/rejected_error"
18
+ autoload :ValueDeclarations, "#{__dir__}/lml/value_declarations"
9
19
  autoload :RoundTrip, "#{__dir__}/lml/round_trip"
10
20
 
11
21
  module_function
@@ -35,6 +45,57 @@ module Lutaml
35
45
  def verify(document, register: nil)
36
46
  RoundTrip.verify(document, register: register)
37
47
  end
48
+
49
+ # Export the closed graph of models reachable from +roots+ as an
50
+ # immutable neutral Bundle of v2 documents keyed by "Model@register".
51
+ #
52
+ # @param roots [Class, Array<Class, Array(Class, String)>] classes,
53
+ # or [class, register] pairs
54
+ # @param register [Symbol, String, nil] default register for roots
55
+ # without one; nil resolves through the model's own default
56
+ # @param provenance [Hash, nil] recorded but excluded from the checksum
57
+ # @param value_declarations [ValueDeclarations, nil] trusted scalar declarations
58
+ # @return [Lml::Bundle]
59
+ def export_bundle(roots, register: nil, provenance: nil, value_declarations: nil)
60
+ GraphExporter.export(
61
+ roots,
62
+ projector: Exporter.graph_projector(value_declarations: value_declarations),
63
+ register: register, provenance: provenance, check_root_registers: true
64
+ )
65
+ end
66
+
67
+ # Write a model instance as `portable-exact-json-v1` text, the JSON
68
+ # profile the TS and Rust codecs read (integers, decimals and floats
69
+ # as strings). `to_json` keeps writing `ruby-native-v1`.
70
+ #
71
+ # @param instance [Lutaml::Model::Serializable]
72
+ # @param pretty [Boolean]
73
+ # @return [String]
74
+ # @raise [Lml::RejectedError] for a value or mapping with no portable
75
+ # spelling (NaN/Infinity, custom methods, unions, ...)
76
+ def portable_json(instance, pretty: false)
77
+ PortableJson.generate(instance, pretty: pretty)
78
+ end
79
+
80
+ # Build fresh Ruby classes (attributes and xml/json/yaml mappings)
81
+ # from a bundle, without the source constants.
82
+ #
83
+ # @param bundle [Lml::Bundle, Hash, String] bundle, Hash or JSON text
84
+ # @param namespace [Module, nil] named holder for generated
85
+ # constants (required when the bundle declares polymorphism)
86
+ # @param type_bindings [Hash{String=>Class}] trusted value types
87
+ # @return [Hash{String=>Class}] model id => generated class
88
+ def import_bundle(bundle, namespace: nil, type_bindings: {})
89
+ Importer.import(bundle, namespace: namespace, type_bindings: type_bindings)
90
+ end
91
+
92
+ # The reconstruction gate: import the bundle, export the generated
93
+ # classes and require identical declarations and checksum.
94
+ # @return [Lml::Bundle] the re-exported bundle
95
+ # @raise [Lml::RejectedError] :round_trip_mismatch on drift
96
+ def verify_materialization(bundle, namespace: nil, type_bindings: {})
97
+ RoundTrip.verify_materialization(bundle, namespace: namespace, type_bindings: type_bindings)
98
+ end
38
99
  end
39
100
  end
40
101
  end
@@ -8,12 +8,13 @@ module Lutaml
8
8
  class Attribute
9
9
  attr_accessor :name, :type, :xml_name, :kind, :collection,
10
10
  :default, :documentation, :initialize_empty,
11
- :render_default, :render_empty
11
+ :render_default, :render_empty, :required
12
12
 
13
13
  def initialize(name:, type:, xml_name:, kind:,
14
14
  collection: false, default: nil,
15
15
  documentation: nil, initialize_empty: false,
16
- render_default: false, render_empty: false)
16
+ render_default: false, render_empty: false,
17
+ required: false)
17
18
  @name = name
18
19
  @type = type
19
20
  @xml_name = xml_name
@@ -24,6 +25,7 @@ module Lutaml
24
25
  @initialize_empty = initialize_empty
25
26
  @render_default = render_default
26
27
  @render_empty = render_empty
28
+ @required = required
27
29
  end
28
30
  end
29
31
  end
@@ -75,7 +75,7 @@ module Lutaml
75
75
  # in their `namespace ...` mapping declarations).
76
76
  def autoload_declarations
77
77
  indent = " " * module_depth
78
- module_subdir = @module_namespace.split("::").last.downcase
78
+ module_subdir = @module_namespace.split("::").map(&:downcase).join("/")
79
79
  (@classes + @namespaces).map do |entry|
80
80
  class_name = Utils.camel_case(entry.name)
81
81
  file_name = Utils.snake_case(entry.name)
@@ -75,6 +75,7 @@ module Lutaml
75
75
  opts << collection_option(attr.collection) if attr.collection
76
76
  opts << "default: -> { #{attr.default.inspect} }" if attr.default
77
77
  opts << "initialize_empty: true" if attr.initialize_empty
78
+ opts << "required: true" if attr.required
78
79
  opts.empty? ? "" : ", #{opts.join(', ')}"
79
80
  end
80
81
 
@@ -31,6 +31,7 @@ module Lutaml
31
31
  xml_name: attr.name,
32
32
  kind: :attribute,
33
33
  default: attr.default,
34
+ required: attribute_required?(attr),
34
35
  )
35
36
  end
36
37
 
@@ -43,9 +44,17 @@ module Lutaml
43
44
  type: build_type_ref(type_str || "string"),
44
45
  xml_name: item.name.to_s,
45
46
  kind: kind,
47
+ required: attribute_required?(item),
46
48
  )
47
49
  end
48
50
 
51
+ # An attribute a document must supply: `use="required"`. The
52
+ # default is optional, so only the explicit requirement binds.
53
+ def attribute_required?(attr)
54
+ attr.is_a?(Lutaml::Xml::Schema::Xsd::Attribute) &&
55
+ attr.use == "required"
56
+ end
57
+
49
58
  # ----- Elements --------------------------------------------------
50
59
 
51
60
  def build_element(element)
@@ -138,6 +147,7 @@ module Lutaml
138
147
  xml_name: target.xml_name,
139
148
  kind: :attribute,
140
149
  default: target.default,
150
+ required: target.required || attribute_required?(attr),
141
151
  )
142
152
  end
143
153
 
@@ -162,10 +162,17 @@ choices, register = nil)
162
162
  end
163
163
  return eo_index + occurrences if occurrences&.positive?
164
164
  return eo_index + 1 if element_order[eo_index] == element
165
+ return eo_index if optional_absent?(element_order, element, klass_attr)
165
166
 
166
167
  raise_incorrect_sequence_error!(element, element_order[eo_index])
167
168
  end
168
169
 
170
+ def optional_absent?(element_order, element, klass_attr)
171
+ return false if klass_attr.collection? || klass_attr.options[:required]
172
+
173
+ !element_order.include?(element)
174
+ end
175
+
169
176
  def process_choice(element_order, eo_index, element, klass_attr, choices,
170
177
  register = nil)
171
178
  return eo_index if choices[klass_attr.choice] || element_order[eo_index] != element
@@ -45,6 +45,27 @@ module Lutaml
45
45
  def self.propagate(options)
46
46
  options.slice(*PROPAGATION_KEYS)
47
47
  end
48
+
49
+ # Memo key for the per-node propagated options (#1311). The
50
+ # propagable keys and the register are identical for every child
51
+ # value of one node, so deriving the child options hash per
52
+ # attribute built and discarded duplicate hashes — `Hash#merge`
53
+ # 7.5% plus `Hash#slice` 3.9% self on the KV walk profile. The
54
+ # key is deliberately not in PROPAGATION_KEYS, so a child never
55
+ # receives the parent's memo as context.
56
+ CHILD_OPTIONS_KEY = :__lutaml_child_options__
57
+
58
+ # The propagated child options for one node's cast-options hash.
59
+ # Reused across that node's attributes; recomputed when the
60
+ # register differs (an options hash can outlive one node).
61
+ def self.child_options(options, register)
62
+ cached = options[CHILD_OPTIONS_KEY]
63
+ return cached if cached && cached[:register] == register
64
+
65
+ propagated = propagate(options).merge(register: register)
66
+ options[CHILD_OPTIONS_KEY] = propagated unless options.frozen?
67
+ propagated
68
+ end
48
69
  end
49
70
  end
50
71
  end
@@ -518,17 +518,27 @@ module Lutaml
518
518
  def allocate_for_walk(register = nil)
519
519
  register_id = extract_register_id(register)
520
520
  ensure_imports!(register_id) if finalized? && deferred_imports_pending?(register_id)
521
- # Classes with their own initialize set up internal state the
522
- # compiled seed cannot know about (SchemaRepository's
523
- # @parsed_schemas/@namespace_registry/@type_index): construct
524
- # through the real constructor for them, exactly as the walk
525
- # did before the compiled seed existed, register included. The
526
- # seed stays the fast path for classes using the standard
527
- # initializer.
528
- return new(lutaml_register: register) if constructs_through_initialize?
529
-
530
521
  instance = allocate
531
522
  instance.init_walk_state(register_id)
523
+ return instance unless constructs_through_initialize?
524
+
525
+ # Classes with their own initialize set up internal state the
526
+ # compiled seed cannot know about (SchemaRepository's
527
+ # @parsed_schemas/@namespace_registry/@type_index): their
528
+ # constructor body still has to run. Run it against the
529
+ # compiled walk seed with the generic attribute walk stood
530
+ # down — the #1059 contract allocate_for_deserialization has
531
+ # used since the deserialization constructor landed: the walk
532
+ # only re-materializes state the seed already wrote, and on
533
+ # expression-model trees (75 classes, every node overriding
534
+ # initialize for parent wiring) that walk was half of the
535
+ # whole hydration cost (#1311). The register rides the call
536
+ # exactly as `new(lutaml_register:)` passed it: a constructor
537
+ # that tells a blank construction from a caller's by the
538
+ # keyword sees the same call either way.
539
+ instance.lutaml_constructor_seeded = true
540
+ instance.send(:initialize, lutaml_register: register_id)
541
+ instance.lutaml_constructor_seeded = nil
532
542
  instance
533
543
  end
534
544
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.202"
5
+ VERSION = "0.8.204"
6
6
  end
7
7
  end
@@ -221,6 +221,10 @@ module Lutaml
221
221
  gate_row_kind?(row, register)
222
222
  end
223
223
  return false if content_cdata?(plan)
224
+ # Element rows with cdata: true have no native text-op spelling
225
+ # (the engine walk emits plain text); the plan serializer mints
226
+ # the CDATA node for them.
227
+ return false if plan.dig(:tree, :flags)&.include?(:cdata)
224
228
 
225
229
  if plan[:ordered] && instance.is_a?(::Lutaml::Model::Serialize)
226
230
  return false if instance.element_order.nil?
@@ -312,13 +312,13 @@ module Lutaml
312
312
  add_leaf(element,
313
313
  ns_ctx ? ns_ctx.spell(row_name(rule, spelling), row_ns) : row_name(rule, spelling),
314
314
  attr.serialize(item, :xml, reg), doc,
315
- attrs: rule.when_attribute)
315
+ attrs: rule.when_attribute, cdata: rule.cdata)
316
316
  end
317
317
  else
318
318
  add_leaf(element,
319
319
  ns_ctx ? ns_ctx.spell(row_name(rule, spelling), row_ns) : row_name(rule, spelling),
320
320
  attr.serialize(value, :xml, reg), doc,
321
- attrs: rule.when_attribute)
321
+ attrs: rule.when_attribute, cdata: rule.cdata)
322
322
  end
323
323
  when :collection_native, :collection_cb
324
324
  row_ns = ns_index[rule.name.to_s] || inherited_ns
@@ -326,7 +326,7 @@ module Lutaml
326
326
  add_leaf(element,
327
327
  ns_ctx ? ns_ctx.spell(rule.name.to_s, row_ns) : rule.name.to_s,
328
328
  attr.serialize(item, :xml, reg), doc,
329
- attrs: rule.when_attribute)
329
+ attrs: rule.when_attribute, cdata: rule.cdata)
330
330
  end
331
331
  when :nested, :ordered_deferred
332
332
  Array(value).each do |item|
@@ -358,7 +358,9 @@ module Lutaml
358
358
  # deferred rows ride the fast lane untouched.
359
359
  return nil unless Array(value).empty?
360
360
  when :content, :content_deferred
361
- Array(value).each { |run| append_text(element, run.to_s, doc) }
361
+ Array(value).each do |run|
362
+ append_text(element, run.to_s, doc, cdata: rule.cdata)
363
+ end
362
364
  end
363
365
  end
364
366
  end
@@ -609,7 +611,8 @@ module Lutaml
609
611
  when :collection_native, :collection_cb, :scalar
610
612
  add_leaf(element,
611
613
  ns_ctx ? ns_ctx.spell(name, row_ns) : name,
612
- attr.serialize(item, :xml, reg), doc)
614
+ attr.serialize(item, :xml, reg), doc,
615
+ cdata: rule.cdata)
613
616
  when :nested, :ordered_deferred
614
617
  next if item.nil?
615
618
 
@@ -704,10 +707,12 @@ module Lutaml
704
707
  # Partition rows (#88) re-emit their discriminator: the wire
705
708
  # element carries the when_attribute pairs so the round trip
706
709
  # re-routes to the same attribute on reparse.
707
- def add_leaf(element, name, value, doc, attrs: nil)
710
+ def add_leaf(element, name, value, doc, attrs: nil, cdata: false)
708
711
  child = element.create_child(name)
709
712
  attrs&.each { |k, v| child[k.to_s] = v.to_s }
710
- append_text(child, value.to_s, doc) unless value.nil?
713
+ unless value.nil?
714
+ append_text(child, value.to_s, doc, cdata: cdata)
715
+ end
711
716
  child
712
717
  end
713
718
 
@@ -715,8 +720,8 @@ module Lutaml
715
720
  # passes raw node addresses — the pointer face mints an
716
721
  # FFI::Pointer wrapper per fresh node, the last per-row
717
722
  # Ruby-side allocation on the DOM build.
718
- def append_text(parent, text, doc)
719
- node = doc.create_text_node(text)
723
+ def append_text(parent, text, doc, cdata: false)
724
+ node = cdata ? doc.create_cdata(text) : doc.create_text_node(text)
720
725
  status = ::Leptris::XML::FFI.leptris_element_add_child_addr(
721
726
  parent.c_address, node.c_address
722
727
  )
@@ -0,0 +1,179 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/lutaml/lutaml-model/schema/lml/document.schema.json",
4
+ "title": "LML document, bundle and manifest (lutaml-model#1033)",
5
+ "description": "Structural schema for the agreed contract. Cross-reference rules (dangling references, duplicate IDs, discriminator targets, capability coverage, sorted arrays) are enforced by Lutaml::Model::Lml::DocumentValidator and reported with the named codes in $defs.errorCodes.",
6
+ "oneOf": [
7
+ {"$ref": "#/$defs/documentV1"},
8
+ {"$ref": "#/$defs/documentV2"},
9
+ {"$ref": "#/$defs/bundle"},
10
+ {"$ref": "#/$defs/manifest"}
11
+ ],
12
+ "$defs": {
13
+ "errorCodes": {
14
+ "enum": ["unsupported_version", "invalid_document", "duplicate_id", "dangling_reference", "unknown_type", "unsupported_type", "missing_type_binding", "unsupported_format", "unsupported_mapping", "non_serializable_default", "lambda_default", "custom_initialize", "imperative_element_order", "invalid_ordered_content", "reserved_member", "nonterminating_rational", "unknown_discriminator", "round_trip_mismatch", "checksum_mismatch", "capability_missing", "not_serializable"]
15
+ },
16
+ "sha256": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"},
17
+ "builtinType": {
18
+ "enum": ["string", "token", "uri", "email", "hostname", "ip", "boolean", "integer", "decimal", "float", "rational", "date", "time", "date_time", "time_without_date", "duration", "qname", "base64_binary", "hex_binary", "symbol", "hash", "email_address", "ip_v4_address", "ip_v6_address", "uuid", "reference", "uri_reference", "date_with_timezone", "date_time_with_timezone", "day_time_duration", "year_month_duration", "positive_integer", "non_negative_integer", "g_year", "g_year_month", "g_month", "g_month_day", "g_day", "idrefs", "nmtokens"]
19
+ },
20
+ "formats": {"enum": ["xml", "json", "yaml", "toml"]},
21
+ "documentV1": {
22
+ "type": "object",
23
+ "required": ["lml", "model"],
24
+ "properties": {
25
+ "lml": {"const": 1},
26
+ "model": {"type": "string", "minLength": 1},
27
+ "register": {"type": ["string", "null"]},
28
+ "attributes": {"type": "array", "items": {"type": "object"}},
29
+ "mappings": {"type": "object"}
30
+ }
31
+ },
32
+ "typeRef": {
33
+ "oneOf": [
34
+ {"type": "object", "required": ["kind", "name"], "additionalProperties": false,
35
+ "properties": {"kind": {"const": "builtin"}, "name": {"$ref": "#/$defs/builtinType"}}},
36
+ {"type": "object", "required": ["kind", "id"], "additionalProperties": false,
37
+ "properties": {"kind": {"enum": ["model", "value"]}, "id": {"type": "string", "minLength": 1}}}
38
+ ]
39
+ },
40
+ "namespace": {
41
+ "type": "object", "required": ["mode"],
42
+ "properties": {
43
+ "mode": {"enum": ["inherit", "unqualified", "uri"]},
44
+ "uri": {"type": "string", "minLength": 1},
45
+ "prefix": {"type": "string"}
46
+ },
47
+ "additionalProperties": false
48
+ },
49
+ "discriminator": {
50
+ "type": "object", "required": ["attribute", "cases"], "additionalProperties": false,
51
+ "properties": {
52
+ "attribute": {"type": "string", "minLength": 1},
53
+ "cases": {"type": "object", "minProperties": 1, "additionalProperties": {"type": "string", "minLength": 1}}
54
+ }
55
+ },
56
+ "attribute": {
57
+ "type": "object", "required": ["name", "type"], "additionalProperties": false,
58
+ "properties": {
59
+ "name": {"type": "string", "minLength": 1, "not": {"const": "__lml_content"}},
60
+ "type": {"$ref": "#/$defs/typeRef"},
61
+ "required": {"type": "boolean"},
62
+ "collection": {
63
+ "oneOf": [
64
+ {"const": false},
65
+ {"type": "object", "required": ["min", "max"], "additionalProperties": false,
66
+ "properties": {"min": {"type": "integer", "minimum": 0}, "max": {"type": ["integer", "null"]}, "class": {"type": "string", "minLength": 1}}}
67
+ ]
68
+ },
69
+ "default": {
70
+ "oneOf": [
71
+ {"type": "object", "required": ["present"], "additionalProperties": false, "properties": {"present": {"const": false}}},
72
+ {"type": "object", "required": ["present", "value"], "additionalProperties": false, "properties": {"present": {"const": true}, "value": {}}}
73
+ ]
74
+ },
75
+ "initialize_empty": {"type": "boolean"},
76
+ "values": {"type": "array"},
77
+ "discriminator": {"$ref": "#/$defs/discriminator"}
78
+ }
79
+ },
80
+ "rule": {
81
+ "type": "object", "additionalProperties": false,
82
+ "properties": {
83
+ "kind": {"enum": ["attribute", "element", "content", "any_attribute", "sequence", "choice"]},
84
+ "name": {"type": "array", "items": {"type": "string"}},
85
+ "key": {"type": "array", "items": {"type": "string"}},
86
+ "to": {"type": "string"},
87
+ "namespace": {"$ref": "#/$defs/namespace"},
88
+ "prefix": {"type": "string"},
89
+ "cdata": {"type": "boolean"},
90
+ "render": {"type": "object", "additionalProperties": false,
91
+ "properties": {"nil": {"type": ["string", "boolean"]}, "empty": {"type": ["string", "boolean"]}, "default": {"type": ["string", "boolean"]}}},
92
+ "discriminator": {"$ref": "#/$defs/discriminator"},
93
+ "members": {"type": "array"},
94
+ "min": {"type": "integer", "minimum": 0},
95
+ "max": {"type": ["integer", "null"]},
96
+ "child_mappings": {},
97
+ "root_mappings": {},
98
+ "polymorphic_map": {"type": "object", "additionalProperties": {"type": "string"}}
99
+ }
100
+ },
101
+ "compositor": {
102
+ "type": "object", "additionalProperties": false, "required": ["kind", "members"],
103
+ "properties": {
104
+ "kind": {"enum": ["sequence", "choice"]},
105
+ "min": {"type": "integer", "minimum": 0},
106
+ "max": {"type": ["integer", "null"]},
107
+ "members": {"type": "array", "items": {"oneOf": [{"$ref": "#/$defs/compositor"}, {"$ref": "#/$defs/rule"}]}}
108
+ }
109
+ },
110
+ "mapping": {
111
+ "type": "object", "additionalProperties": false,
112
+ "properties": {
113
+ "root": {},
114
+ "namespace": {"$ref": "#/$defs/namespace"},
115
+ "rules": {"type": "array", "items": {"$ref": "#/$defs/rule"}},
116
+ "ordered": {"type": "boolean"},
117
+ "mixed_content": {"type": "boolean"},
118
+ "sequence": {"type": "array", "items": {"$ref": "#/$defs/compositor"}},
119
+ "root_mappings": {},
120
+ "child_mappings": {}
121
+ }
122
+ },
123
+ "documentV2": {
124
+ "type": "object", "additionalProperties": false,
125
+ "required": ["lml", "model", "register", "attributes"],
126
+ "properties": {
127
+ "lml": {"const": 2},
128
+ "model": {"type": "string", "minLength": 1},
129
+ "register": {"type": "string", "pattern": "^[A-Za-z0-9_.:-]+$"},
130
+ "attributes": {"type": "array", "items": {"$ref": "#/$defs/attribute"}},
131
+ "mappings": {"type": "object", "propertyNames": {"$ref": "#/$defs/formats"}, "additionalProperties": {"$ref": "#/$defs/mapping"}},
132
+ "ordered_content": {
133
+ "type": "object", "required": ["member", "version"], "additionalProperties": false,
134
+ "properties": {"member": {"const": "__lml_content"}, "version": {"const": 1}}
135
+ }
136
+ }
137
+ },
138
+ "bundle": {
139
+ "type": "object", "additionalProperties": false,
140
+ "required": ["lml_bundle", "roots", "models", "value_types", "capabilities"],
141
+ "properties": {
142
+ "lml_bundle": {"const": 1},
143
+ "roots": {"type": "array", "uniqueItems": true, "items": {"type": "string"}},
144
+ "models": {"type": "object", "additionalProperties": {"$ref": "#/$defs/documentV2"}},
145
+ "value_types": {
146
+ "type": "object",
147
+ "additionalProperties": {
148
+ "type": "object", "required": ["base", "facets"], "additionalProperties": false,
149
+ "properties": {"base": {"$ref": "#/$defs/builtinType"}, "facets": {"type": "object"}}
150
+ }
151
+ },
152
+ "capabilities": {"type": "array", "uniqueItems": true, "items": {"type": "string"}},
153
+ "provenance": {"type": "object"}
154
+ }
155
+ },
156
+ "pinned": {
157
+ "type": "object", "required": ["sha256"],
158
+ "properties": {"sha256": {"$ref": "#/$defs/sha256"}}
159
+ },
160
+ "manifest": {
161
+ "type": "object", "additionalProperties": false,
162
+ "required": ["manifest", "lml_checksum", "schema_version", "generator_version", "target", "capabilities", "corpora", "files", "dependencies"],
163
+ "properties": {
164
+ "manifest": {"const": 1},
165
+ "lml_checksum": {"$ref": "#/$defs/sha256"},
166
+ "schema_version": {"const": 2},
167
+ "generator_version": {"type": "string", "minLength": 1},
168
+ "target": {"enum": ["ruby", "ts", "rust", "wasm"]},
169
+ "capabilities": {"type": "array", "uniqueItems": true, "items": {"type": "string"}},
170
+ "corpora": {"type": "array", "items": {"type": "object", "required": ["generation", "sha256"], "additionalProperties": false,
171
+ "properties": {"generation": {}, "sha256": {"$ref": "#/$defs/sha256"}}}},
172
+ "files": {"type": "array", "items": {"type": "object", "required": ["path", "sha256"], "additionalProperties": false,
173
+ "properties": {"path": {"type": "string", "pattern": "^(?!/)(?!.*(^|/)\\.\\.?(/|$)).+"}, "sha256": {"$ref": "#/$defs/sha256"}}}},
174
+ "dependencies": {"type": "array", "items": {"type": "object", "required": ["name", "revision", "sha256"], "additionalProperties": false,
175
+ "properties": {"name": {"type": "string"}, "revision": {"type": "string"}, "sha256": {"$ref": "#/$defs/sha256"}}}}
176
+ }
177
+ }
178
+ }
179
+ }
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ruby -Ilib scripts/lml/export_choices.rb OUTPUT [Plain Nested ...]
4
+ # Omitting names exports every source fixture, including eager field failures.
5
+ require "json"
6
+ require "digest"
7
+ require_relative "../../spec/support/lml_model_choices_fixtures"
8
+
9
+ Lutaml::Model::Config.xml_adapter_type = :nokogiri
10
+ output = ARGV.shift || abort("usage: export_choices.rb OUTPUT [fixture names]")
11
+ selected = ARGV.empty? ? LmlModelChoicesFixtures::CASES.keys : ARGV
12
+ sources = selected.to_h do |name|
13
+ [name, LmlModelChoicesFixtures.const_get(name, false)]
14
+ end
15
+ codes = lambda do |value|
16
+ value.validate.map do |error|
17
+ case error
18
+ when Lutaml::Model::ChoiceLowerBoundError then "choice_lower_bound"
19
+ when Lutaml::Model::ChoiceUpperBoundError then "choice_upper_bound"
20
+ else error.class.name
21
+ end
22
+ end
23
+ end
24
+ phase = lambda do |&block|
25
+ codes.call(block.call)
26
+ rescue Lutaml::Model::CollectionCountOutOfRangeError
27
+ ["eager_collection_count_out_of_range"]
28
+ end
29
+ rows = sources.flat_map do |name, klass|
30
+ LmlModelChoicesFixtures::CASES.fetch(name).each_with_index.map do |input, index|
31
+ value = klass.new(input)
32
+ json = value.to_json
33
+ xml = value.to_xml
34
+ {
35
+ id: "#{name}-#{index}", model_id: "#{klass.name}@default", input: input,
36
+ expected: {
37
+ construct: codes.call(value),
38
+ json_input: phase.call { klass.from_json(JSON.generate(input)) },
39
+ json_wire: JSON.parse(json),
40
+ json_roundtrip: phase.call { klass.from_json(json) },
41
+ xml_wire: xml,
42
+ xml_roundtrip: phase.call { klass.from_xml(xml) },
43
+ }
44
+ }
45
+ end
46
+ end
47
+ root = File.expand_path("../..", __dir__)
48
+ producer_files = %w[lib/lutaml/model/choice.rb lib/lutaml/model/validation.rb
49
+ spec/support/lml_model_choices_fixtures.rb]
50
+ producer = producer_files.to_h { |file| [file, Digest::SHA256.file(File.join(root, file)).hexdigest] }
51
+ report = {
52
+ source_semantics: "native Choice/Validation and format-specific I/O; group validation unchanged",
53
+ ruby: RUBY_VERSION, producer: producer,
54
+ bundle: Lutaml::Model::Lml.export_bundle(sources.values).to_h, cases: rows
55
+ }
56
+ File.write(output, "#{JSON.pretty_generate(report)}\n")
57
+ puts JSON.generate(models: report[:bundle].fetch("models").length, cases: rows.length)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "fileutils"
5
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __dir__))
6
+ require_relative "../../spec/support/lml_conformance"
7
+
8
+ options = { check: false, package: File.expand_path("../../spec/fixtures/lml_conformance/core", __dir__) }
9
+ OptionParser.new do |parser|
10
+ parser.banner = "Usage: ruby scripts/lml/export_conformance.rb [--check] [--package DIRECTORY]"
11
+ parser.on("--check", "Check pinned files without rewriting") { options[:check] = true }
12
+ parser.on("--package DIRECTORY", "Explicit core package directory") { |path| options[:package] = path }
13
+ end.parse!
14
+
15
+ unless options[:check]
16
+ FileUtils.mkdir_p(options[:package])
17
+ LmlConformance.files.each do |path, bytes|
18
+ File.binwrite(File.join(options[:package], path), bytes)
19
+ end
20
+ end
21
+ report = LmlConformance.check(options[:package])
22
+ puts LmlConformance.json(report)
23
+ exit(report.fetch("errors").empty? ? 0 : 1)