lutaml-model 0.8.30 → 0.8.32

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +25 -23
  3. data/docs/_pages/breaking-changes.adoc +58 -0
  4. data/docs/_pages/collections.adoc +25 -24
  5. data/docs/_pages/validation.adoc +48 -1
  6. data/lib/compat/opal/lutaml_model_boot.rb +1 -0
  7. data/lib/lutaml/json/adapter/document.rb +2 -0
  8. data/lib/lutaml/json/adapter/standard_adapter.rb +1 -0
  9. data/lib/lutaml/key_value/transform.rb +7 -1
  10. data/lib/lutaml/model/attribute.rb +67 -24
  11. data/lib/lutaml/model/collection.rb +5 -2
  12. data/lib/lutaml/model/collection_handler.rb +45 -2
  13. data/lib/lutaml/model/serialize/enum_handling.rb +5 -1
  14. data/lib/lutaml/model/validation.rb +49 -4
  15. data/lib/lutaml/model/version.rb +1 -1
  16. data/lib/lutaml/xml/format.rb +25 -1
  17. data/lib/lutaml/xml/mapping_rule.rb +8 -1
  18. data/lib/lutaml/xml/model_transform.rb +68 -12
  19. data/lib/lutaml/xml/nested_collection_attribute.rb +95 -0
  20. data/lib/lutaml/xml/schema/xsd_schema.rb +396 -128
  21. data/lib/lutaml/xml/serialization/instance_methods.rb +2 -2
  22. data/lib/lutaml/xml/transformation/element_builder.rb +72 -9
  23. data/lib/lutaml/yaml/adapter/document.rb +2 -0
  24. data/lib/lutaml/yaml/adapter/standard_adapter.rb +2 -0
  25. data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +7 -3
  26. data/spec/lutaml/model/attribute_collection_spec.rb +156 -0
  27. data/spec/lutaml/model/attribute_spec.rb +1 -1
  28. data/spec/lutaml/model/cardinality_strict_spec.rb +614 -0
  29. data/spec/lutaml/model/cdata_spec.rb +1 -1
  30. data/spec/lutaml/model/collection_register_spec.rb +119 -0
  31. data/spec/lutaml/model/collection_single_value_coercion_spec.rb +222 -0
  32. data/spec/lutaml/model/raw_adapter_require_spec.rb +22 -0
  33. data/spec/lutaml/model/root_mappings_spec.rb +10 -7
  34. data/spec/lutaml/model/schema/xsd_schema_spec.rb +785 -25
  35. data/spec/lutaml/model/serializable_validation_spec.rb +293 -0
  36. data/spec/lutaml/model/value_policy_spec.rb +6 -3
  37. data/spec/lutaml/model/xsd_form_default_patterns_spec.rb +12 -12
  38. data/spec/lutaml/model/xsd_patterns_spec.rb +29 -29
  39. data/spec/lutaml/model/xsd_type_validation_spec.rb +1 -1
  40. data/spec/lutaml/turtle/transform_spec.rb +2 -2
  41. data/spec/lutaml/xml/cross_class_dispatch_spec.rb +79 -0
  42. data/spec/lutaml/xml/plain_model_accessors_spec.rb +50 -0
  43. data/spec/lutaml/xml/type_qualified_attribute_leniency_spec.rb +66 -0
  44. metadata +9 -1
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "lutaml/model"
5
+
6
+ # Regression spec for the XML accessor wiring of plain (non-Serialize)
7
+ # model classes declared via `model PlainClass`.
8
+ #
9
+ # The accessors are installed by
10
+ # FormatConversion#add_format_specific_model_methods, which must override
11
+ # the no-op base through Serialize::ClassMethods' prepend chain. Engines
12
+ # that do not propagate a prepend into an already-extended module to prior
13
+ # extenders' singleton chains (TruffleRuby —
14
+ # https://github.com/truffleruby/truffleruby/issues/4452) silently lose the
15
+ # override; this spec fails there without the format.rb re-prepend.
16
+ RSpec.describe "Plain model class XML accessors" do
17
+ let(:plain_class) { Class.new }
18
+
19
+ let(:wrapper_class) do
20
+ pc = plain_class
21
+ Class.new(Lutaml::Model::Serializable) do
22
+ model pc
23
+
24
+ xml do
25
+ element "thing"
26
+ end
27
+
28
+ def self.name
29
+ "PlainModelWrapper"
30
+ end
31
+ end
32
+ end
33
+
34
+ it "installs the XML accessors on the plain model class" do
35
+ wrapper_class # force the `model` declaration
36
+
37
+ %i[encoding encoding= doctype= element_order= ordered= mixed=
38
+ xml_declaration= raw_schema_location=].each do |m|
39
+ expect(plain_class.method_defined?(m)).to(be(true),
40
+ "expected #{plain_class} to define ##{m}")
41
+ end
42
+ end
43
+
44
+ it "parses XML into the plain model instance" do
45
+ instance = wrapper_class.from_xml("<thing/>")
46
+
47
+ expect(instance).to be_a(plain_class)
48
+ expect(instance.element_order).not_to be_nil
49
+ end
50
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # An attribute rule with no namespace of its own whose VALUE TYPE is
6
+ # namespace-qualified (Lutaml::Xml::Type::Configurable) must keep
7
+ # binding unprefixed source attributes — per W3C Namespaces an
8
+ # unprefixed attribute carries no namespace, and 0.8.19 matched it
9
+ # leniently. The #758 strict prefixed-only match applies to rule- and
10
+ # schema-level qualification, not to the value type's (lutaml-model#786).
11
+ module TypeQualifiedAttributeLeniencySpec
12
+ class W14Ns < Lutaml::Xml::Namespace
13
+ uri "http://schemas.microsoft.com/office/word/2010/wordml"
14
+ prefix_default "w14"
15
+ element_form_default :qualified
16
+ attribute_form_default :qualified
17
+ end
18
+
19
+ class W14String < Lutaml::Model::Type::String
20
+ include Lutaml::Xml::Type::Configurable
21
+
22
+ xml do
23
+ namespace W14Ns
24
+ end
25
+ end
26
+
27
+ class WNs < Lutaml::Xml::Namespace
28
+ uri "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
29
+ prefix_default "w"
30
+ element_form_default :qualified
31
+ end
32
+
33
+ W_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
34
+ W14_NS = "http://schemas.microsoft.com/office/word/2010/wordml"
35
+
36
+ class Bookmark < Lutaml::Model::Serializable
37
+ attribute :id, :string
38
+ attribute :v, W14String
39
+
40
+ xml do
41
+ element "bookmarkStart"
42
+ namespace WNs
43
+ map_attribute "id", to: :id
44
+ map_attribute "displacedByCustomXml", to: :v
45
+ end
46
+ end
47
+ end
48
+
49
+ RSpec.describe "type-qualified attribute rules" do
50
+ it "bind unprefixed source attributes (W3C: unprefixed = no namespace)" do
51
+ xml = %(<w:bookmarkStart xmlns:w="#{TypeQualifiedAttributeLeniencySpec::W_NS}" displacedByCustomXml="next" id="0"/>)
52
+ doc = TypeQualifiedAttributeLeniencySpec::Bookmark.from_xml(xml)
53
+
54
+ expect(doc.v).to eq("next")
55
+ expect(doc.id).to eq("0")
56
+ expect(doc.to_xml).to include(%(w14:displacedByCustomXml="next"))
57
+ end
58
+
59
+ it "keep binding prefixed source attributes in the type namespace" do
60
+ xml = %(<w:bookmarkStart xmlns:w="#{TypeQualifiedAttributeLeniencySpec::W_NS}" xmlns:w14="#{TypeQualifiedAttributeLeniencySpec::W14_NS}" w14:displacedByCustomXml="next" id="0"/>)
61
+ doc = TypeQualifiedAttributeLeniencySpec::Bookmark.from_xml(xml)
62
+
63
+ expect(doc.v).to eq("next")
64
+ expect(doc.to_xml).to include(%(w14:displacedByCustomXml="next"))
65
+ end
66
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.30
4
+ version: 0.8.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -780,6 +780,7 @@ files:
780
780
  - lib/lutaml/xml/namespace_scope_config.rb
781
781
  - lib/lutaml/xml/namespace_type_resolver.rb
782
782
  - lib/lutaml/xml/namespace_usage.rb
783
+ - lib/lutaml/xml/nested_collection_attribute.rb
783
784
  - lib/lutaml/xml/nokogiri.rb
784
785
  - lib/lutaml/xml/nokogiri/element.rb
785
786
  - lib/lutaml/xml/oga.rb
@@ -1673,12 +1674,15 @@ files:
1673
1674
  - spec/lutaml/model/attribute_spec.rb
1674
1675
  - spec/lutaml/model/boot_manifest_spec.rb
1675
1676
  - spec/lutaml/model/cached_type_resolver_spec.rb
1677
+ - spec/lutaml/model/cardinality_strict_spec.rb
1676
1678
  - spec/lutaml/model/cdata_spec.rb
1677
1679
  - spec/lutaml/model/choice_restrict_spec.rb
1678
1680
  - spec/lutaml/model/choice_spec.rb
1679
1681
  - spec/lutaml/model/cli_spec.rb
1680
1682
  - spec/lutaml/model/collection_index_spec.rb
1681
1683
  - spec/lutaml/model/collection_mutation_spec.rb
1684
+ - spec/lutaml/model/collection_register_spec.rb
1685
+ - spec/lutaml/model/collection_single_value_coercion_spec.rb
1682
1686
  - spec/lutaml/model/collection_spec.rb
1683
1687
  - spec/lutaml/model/collection_state_nesting_spec.rb
1684
1688
  - spec/lutaml/model/collection_validation_spec.rb
@@ -1734,6 +1738,7 @@ files:
1734
1738
  - spec/lutaml/model/ordered_content_spec.rb
1735
1739
  - spec/lutaml/model/polymorphic_spec.rb
1736
1740
  - spec/lutaml/model/processing_instruction_spec.rb
1741
+ - spec/lutaml/model/raw_adapter_require_spec.rb
1737
1742
  - spec/lutaml/model/raw_element_spec.rb
1738
1743
  - spec/lutaml/model/register_key_value_spec.rb
1739
1744
  - spec/lutaml/model/register_methods_spec.rb
@@ -1859,6 +1864,7 @@ files:
1859
1864
  - spec/lutaml/xml/conformance/xml_namespaces_spec.rb
1860
1865
  - spec/lutaml/xml/conformance/xml_schema_instance_spec.rb
1861
1866
  - spec/lutaml/xml/content_model_validation_spec.rb
1867
+ - spec/lutaml/xml/cross_class_dispatch_spec.rb
1862
1868
  - spec/lutaml/xml/data_model_spec.rb
1863
1869
  - spec/lutaml/xml/decisions/decision_engine_spec.rb
1864
1870
  - spec/lutaml/xml/decisions/decision_spec.rb
@@ -1914,6 +1920,7 @@ files:
1914
1920
  - spec/lutaml/xml/ordered_method_spec.rb
1915
1921
  - spec/lutaml/xml/out_of_namespace_parsing_spec.rb
1916
1922
  - spec/lutaml/xml/pipeline_integration_spec.rb
1923
+ - spec/lutaml/xml/plain_model_accessors_spec.rb
1917
1924
  - spec/lutaml/xml/plan_fast_path_spec.rb
1918
1925
  - spec/lutaml/xml/plan_walk_spec.rb
1919
1926
  - spec/lutaml/xml/prefix_control_spec.rb
@@ -1954,6 +1961,7 @@ files:
1954
1961
  - spec/lutaml/xml/type_namespace_prefix_spec.rb
1955
1962
  - spec/lutaml/xml/type_namespace_resolver_spec.rb
1956
1963
  - spec/lutaml/xml/type_namespace_roundtrip_spec.rb
1964
+ - spec/lutaml/xml/type_qualified_attribute_leniency_spec.rb
1957
1965
  - spec/lutaml/xml/validate_xml_with_constructs_spec.rb
1958
1966
  - spec/lutaml/xml/validate_xml_with_spec.rb
1959
1967
  - spec/lutaml/xml/w3c_types_spec.rb