lutaml-model 0.5.4 → 0.6.1
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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +58 -21
- data/Gemfile +1 -0
- data/README.adoc +1112 -264
- data/lib/lutaml/model/attribute.rb +37 -15
- data/lib/lutaml/model/choice.rb +56 -0
- data/lib/lutaml/model/config.rb +1 -0
- data/lib/lutaml/model/error/choice_lower_bound_error.rb +9 -0
- data/lib/lutaml/model/error/choice_upper_bound_error.rb +9 -0
- data/lib/lutaml/model/error/import_model_with_root_error.rb +9 -0
- data/lib/lutaml/model/error/incorrect_sequence_error.rb +9 -0
- data/lib/lutaml/model/error/invalid_choice_range_error.rb +20 -0
- data/lib/lutaml/model/error/no_root_mapping_error.rb +9 -0
- data/lib/lutaml/model/error/no_root_namespace_error.rb +9 -0
- data/lib/lutaml/model/error/unknown_sequence_mapping_error.rb +9 -0
- data/lib/lutaml/model/error.rb +8 -0
- data/lib/lutaml/model/json_adapter/standard_json_adapter.rb +6 -1
- data/lib/lutaml/model/key_value_mapping.rb +3 -1
- data/lib/lutaml/model/key_value_mapping_rule.rb +4 -2
- data/lib/lutaml/model/liquefiable.rb +59 -0
- data/lib/lutaml/model/mapping_hash.rb +1 -1
- data/lib/lutaml/model/mapping_rule.rb +15 -2
- data/lib/lutaml/model/schema/xml_compiler.rb +68 -26
- data/lib/lutaml/model/schema_location.rb +7 -0
- data/lib/lutaml/model/sequence.rb +71 -0
- data/lib/lutaml/model/serialize.rb +126 -38
- data/lib/lutaml/model/type/decimal.rb +0 -4
- data/lib/lutaml/model/type/time.rb +3 -3
- data/lib/lutaml/model/utils.rb +19 -15
- data/lib/lutaml/model/validation.rb +12 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/builder/oga.rb +10 -7
- data/lib/lutaml/model/xml_adapter/builder/ox.rb +20 -13
- data/lib/lutaml/model/xml_adapter/element.rb +32 -0
- data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +8 -8
- data/lib/lutaml/model/xml_adapter/oga/element.rb +14 -13
- data/lib/lutaml/model/xml_adapter/oga_adapter.rb +86 -19
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +19 -15
- data/lib/lutaml/model/xml_adapter/xml_document.rb +74 -13
- data/lib/lutaml/model/xml_adapter/xml_element.rb +57 -3
- data/lib/lutaml/model/xml_mapping.rb +49 -7
- data/lib/lutaml/model/xml_mapping_rule.rb +8 -3
- data/lib/lutaml/model.rb +1 -0
- data/lutaml-model.gemspec +5 -0
- data/spec/benchmarks/xml_parsing_benchmark_spec.rb +75 -0
- data/spec/ceramic_spec.rb +39 -0
- data/spec/fixtures/ceramic.rb +23 -0
- data/spec/fixtures/xml/address_example_260.xsd +9 -0
- data/spec/fixtures/xml/user.xsd +10 -0
- data/spec/lutaml/model/cdata_spec.rb +4 -5
- data/spec/lutaml/model/choice_spec.rb +168 -0
- data/spec/lutaml/model/collection_spec.rb +1 -1
- data/spec/lutaml/model/custom_model_spec.rb +55 -8
- data/spec/lutaml/model/custom_serialization_spec.rb +74 -2
- data/spec/lutaml/model/defaults_spec.rb +3 -1
- data/spec/lutaml/model/delegation_spec.rb +7 -5
- data/spec/lutaml/model/enum_spec.rb +35 -0
- data/spec/lutaml/model/group_spec.rb +160 -0
- data/spec/lutaml/model/inheritance_spec.rb +25 -0
- data/spec/lutaml/model/liquefiable_spec.rb +121 -0
- data/spec/lutaml/model/mixed_content_spec.rb +80 -41
- data/spec/lutaml/model/multiple_mapping_spec.rb +22 -10
- data/spec/lutaml/model/schema/xml_compiler_spec.rb +218 -25
- data/spec/lutaml/model/sequence_spec.rb +216 -0
- data/spec/lutaml/model/transformation_spec.rb +230 -0
- data/spec/lutaml/model/type_spec.rb +138 -31
- data/spec/lutaml/model/utils_spec.rb +32 -0
- data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +11 -7
- data/spec/lutaml/model/xml_mapping_rule_spec.rb +51 -0
- data/spec/lutaml/model/xml_mapping_spec.rb +167 -112
- metadata +67 -2
@@ -57,6 +57,7 @@ module XmlMapping
|
|
57
57
|
class Address < Lutaml::Model::Serializable
|
58
58
|
attribute :street, ::Lutaml::Model::Type::String, raw: true
|
59
59
|
attribute :city, :string, raw: true
|
60
|
+
attribute :text, :string
|
60
61
|
attribute :address, Address
|
61
62
|
|
62
63
|
xml do
|
@@ -64,6 +65,7 @@ module XmlMapping
|
|
64
65
|
|
65
66
|
map_element "street", to: :street
|
66
67
|
map_element "city", to: :city
|
68
|
+
map_element "text", to: :text
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -226,7 +228,8 @@ module XmlMapping
|
|
226
228
|
xml do
|
227
229
|
root "MapAllWithCustomMethod"
|
228
230
|
|
229
|
-
map_all_content to: :all_content,
|
231
|
+
map_all_content to: :all_content,
|
232
|
+
with: { to: :content_to_xml, from: :content_from_xml }
|
230
233
|
end
|
231
234
|
|
232
235
|
def content_to_xml(model, parent, doc)
|
@@ -344,6 +347,7 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
344
347
|
|
345
348
|
it "checks the attribute with and without namespace" do
|
346
349
|
parsed = XmlMapping::AttributeNamespace.from_xml(input_xml)
|
350
|
+
|
347
351
|
expect(parsed.alpha).to eq("hello")
|
348
352
|
expect(parsed.beta).to eq("bye")
|
349
353
|
expect(parsed.to_xml).to be_equivalent_to(input_xml)
|
@@ -382,12 +386,12 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
382
386
|
end
|
383
387
|
|
384
388
|
let(:oga_expected_xml) do
|
385
|
-
"<OverrideDefaultNamespacePrefix xmlns:abc=\"http://www.omg.org/spec/XMI/20131001\">"
|
386
|
-
"<abc:SameElementName App=\"hello\" xmlns:GML=\"http://www.sparxsystems.com/profiles/GML/1.0\" xmlns:CityGML=\"http://www.sparxsystems.com/profiles/CityGML/1.0\">"
|
387
|
-
"<GML:ApplicationSchema>GML App</GML:ApplicationSchema>"
|
388
|
-
"<CityGML:ApplicationSchema>CityGML App</CityGML:ApplicationSchema>"
|
389
|
-
"<abc:ApplicationSchema>App</abc:ApplicationSchema>"
|
390
|
-
"</abc:SameElementName>"
|
389
|
+
"<OverrideDefaultNamespacePrefix xmlns:abc=\"http://www.omg.org/spec/XMI/20131001\">" \
|
390
|
+
"<abc:SameElementName App=\"hello\" xmlns:GML=\"http://www.sparxsystems.com/profiles/GML/1.0\" xmlns:CityGML=\"http://www.sparxsystems.com/profiles/CityGML/1.0\">" \
|
391
|
+
"<GML:ApplicationSchema>GML App</GML:ApplicationSchema>" \
|
392
|
+
"<CityGML:ApplicationSchema>CityGML App</CityGML:ApplicationSchema>" \
|
393
|
+
"<abc:ApplicationSchema>App</abc:ApplicationSchema>" \
|
394
|
+
"</abc:SameElementName>" \
|
391
395
|
"</OverrideDefaultNamespacePrefix>"
|
392
396
|
end
|
393
397
|
|
@@ -477,34 +481,38 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
477
481
|
end
|
478
482
|
|
479
483
|
let(:expected_order) do
|
484
|
+
nokogiri_pattern = create_pattern_mapping([
|
485
|
+
["Text", "text"],
|
486
|
+
["Element", "ApplicationSchema"],
|
487
|
+
["Text", "text"],
|
488
|
+
["Element", "ApplicationSchema"],
|
489
|
+
["Text", "text"],
|
490
|
+
["Element", "ApplicationSchema"],
|
491
|
+
["Text", "text"],
|
492
|
+
])
|
493
|
+
|
494
|
+
oga_ox_pattern = create_pattern_mapping([
|
495
|
+
["Element", "ApplicationSchema"],
|
496
|
+
["Element", "ApplicationSchema"],
|
497
|
+
["Element", "ApplicationSchema"],
|
498
|
+
])
|
499
|
+
|
480
500
|
{
|
481
|
-
Lutaml::Model::XmlAdapter::NokogiriAdapter =>
|
482
|
-
|
483
|
-
|
484
|
-
"text",
|
485
|
-
"ApplicationSchema",
|
486
|
-
"text",
|
487
|
-
"ApplicationSchema",
|
488
|
-
"text",
|
489
|
-
],
|
490
|
-
Lutaml::Model::XmlAdapter::OxAdapter => [
|
491
|
-
"ApplicationSchema",
|
492
|
-
"ApplicationSchema",
|
493
|
-
"ApplicationSchema",
|
494
|
-
],
|
495
|
-
Lutaml::Model::XmlAdapter::OgaAdapter => [
|
496
|
-
"text",
|
497
|
-
"ApplicationSchema",
|
498
|
-
"text",
|
499
|
-
"ApplicationSchema",
|
500
|
-
"text",
|
501
|
-
"ApplicationSchema",
|
502
|
-
"text",
|
503
|
-
],
|
501
|
+
Lutaml::Model::XmlAdapter::NokogiriAdapter => nokogiri_pattern,
|
502
|
+
Lutaml::Model::XmlAdapter::OxAdapter => oga_ox_pattern,
|
503
|
+
Lutaml::Model::XmlAdapter::OgaAdapter => oga_ox_pattern,
|
504
504
|
}
|
505
505
|
end
|
506
506
|
|
507
|
-
let(:parsed)
|
507
|
+
let(:parsed) do
|
508
|
+
XmlMapping::SameNameDifferentNamespace.from_xml(input_xml)
|
509
|
+
end
|
510
|
+
|
511
|
+
def create_pattern_mapping(array)
|
512
|
+
array.map do |type, text|
|
513
|
+
Lutaml::Model::XmlAdapter::Element.new(type, text)
|
514
|
+
end
|
515
|
+
end
|
508
516
|
|
509
517
|
it "citygml_application_schema should be correct" do
|
510
518
|
expect(parsed.citygml_application_schema).to eq("CityGML App")
|
@@ -652,7 +660,8 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
652
660
|
|
653
661
|
it "sets the namespace for individual elements" do
|
654
662
|
expect(mapping.elements.size).to eq(3)
|
655
|
-
expect(mapping.elements[0].namespace)
|
663
|
+
expect(mapping.elements[0].namespace)
|
664
|
+
.to eq("https://example.com/ceramic/1.2")
|
656
665
|
expect(mapping.elements[0].prefix).to eq("cera")
|
657
666
|
expect(mapping.elements[1].delegate).to eq(:glaze)
|
658
667
|
end
|
@@ -674,7 +683,8 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
674
683
|
|
675
684
|
it "sets the namespace for individual attributes" do
|
676
685
|
expect(mapping.attributes.size).to eq(1)
|
677
|
-
expect(mapping.attributes[0].namespace)
|
686
|
+
expect(mapping.attributes[0].namespace)
|
687
|
+
.to eq("https://example.com/ceramic/1.2")
|
678
688
|
expect(mapping.attributes[0].prefix).to eq("cera")
|
679
689
|
end
|
680
690
|
end
|
@@ -727,7 +737,7 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
727
737
|
error_regex = /\[Lutaml::Model\] WARN: `schemaLocation` is handled by default\. No need to explecitly define at `xml_mapping_spec.rb:\d+`/
|
728
738
|
|
729
739
|
expect do
|
730
|
-
|
740
|
+
mapping.map_attribute("schemaLocation", to: :schema_location)
|
731
741
|
end.to output(error_regex).to_stderr
|
732
742
|
end
|
733
743
|
end
|
@@ -745,13 +755,32 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
745
755
|
XML
|
746
756
|
end
|
747
757
|
|
758
|
+
let(:generated_xml) do
|
759
|
+
XmlMapping::SchemaLocationOrdered.from_xml(xml).to_xml
|
760
|
+
end
|
761
|
+
|
748
762
|
it "contain schemaLocation attributes" do
|
749
|
-
expect(
|
763
|
+
expect(generated_xml).to be_equivalent_to(xml)
|
750
764
|
end
|
751
765
|
end
|
752
766
|
end
|
753
767
|
|
754
768
|
context "with multiple schemaLocations" do
|
769
|
+
let(:nested_schema_location) do
|
770
|
+
Lutaml::Model::SchemaLocation.new(
|
771
|
+
schema_location: "http://www.opengis.net/gml/3.7 http://schemas.opengis.net/gml/3.7.1/gml.xsd http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd",
|
772
|
+
prefix: "xsi",
|
773
|
+
namespace: "http://another-instance",
|
774
|
+
)
|
775
|
+
end
|
776
|
+
|
777
|
+
let(:schema_location) do
|
778
|
+
Lutaml::Model::SchemaLocation.new(
|
779
|
+
schema_location: "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd http://www.w3.org/1999/xlink http://www.w3.org/1999/xlink.xsd",
|
780
|
+
prefix: "xsi",
|
781
|
+
)
|
782
|
+
end
|
783
|
+
|
755
784
|
let(:xml) do
|
756
785
|
<<~XML
|
757
786
|
<p xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
@@ -764,60 +793,39 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
764
793
|
XML
|
765
794
|
end
|
766
795
|
|
767
|
-
|
768
|
-
parsed
|
769
|
-
expect(parsed.schema_location.size).to eq(2)
|
770
|
-
expect(parsed.schema_location[0].namespace).to eq("http://www.opengis.net/gml/3.2")
|
771
|
-
expect(parsed.schema_location[0].location).to eq("http://schemas.opengis.net/gml/3.2.1/gml.xsd")
|
772
|
-
expect(parsed.schema_location[1].namespace).to eq("http://www.w3.org/1999/xlink")
|
773
|
-
expect(parsed.schema_location[1].location).to eq("http://www.w3.org/1999/xlink.xsd")
|
796
|
+
context "when deserializing" do
|
797
|
+
let(:parsed) { Paragraph.from_xml(xml) }
|
774
798
|
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
799
|
+
it "parses correctly" do
|
800
|
+
expect(parsed.schema_location.size).to eq(2)
|
801
|
+
expect(parsed.schema_location[0]).to eq(schema_location[0])
|
802
|
+
expect(parsed.schema_location[1]).to eq(schema_location[1])
|
803
|
+
end
|
780
804
|
|
781
|
-
|
782
|
-
|
783
|
-
nested_p = parsed.paragraph
|
805
|
+
it "parses nested correctly" do
|
806
|
+
nested_p = parsed.paragraph
|
784
807
|
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
expect(nested_p.schema_location[1].location).to eq("http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd")
|
808
|
+
expect(nested_p.schema_location.size).to eq(2)
|
809
|
+
expect(nested_p.schema_location[0]).to eq(nested_schema_location[0])
|
810
|
+
expect(nested_p.schema_location[1]).to eq(nested_schema_location[1])
|
811
|
+
end
|
812
|
+
end
|
791
813
|
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
schema_location: Lutaml::Model::SchemaLocation.new(
|
800
|
-
schema_location: {
|
801
|
-
"http://www.opengis.net/gml/3.2" => "http://schemas.opengis.net/gml/3.2.1/gml.xsd",
|
802
|
-
"http://www.w3.org/1999/xlink" => "http://www.w3.org/1999/xlink.xsd",
|
803
|
-
},
|
804
|
-
prefix: "xsi",
|
805
|
-
),
|
806
|
-
paragraph: Paragraph.new(
|
807
|
-
schema_location: Lutaml::Model::SchemaLocation.new(
|
808
|
-
schema_location: {
|
809
|
-
"http://www.opengis.net/gml/3.7" => "http://schemas.opengis.net/gml/3.7.1/gml.xsd",
|
810
|
-
"http://www.isotc211.org/2005/gmd" => "http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd",
|
811
|
-
},
|
812
|
-
prefix: "xsi",
|
813
|
-
namespace: "http://another-instance",
|
814
|
+
context "when serializing" do
|
815
|
+
let(:paragraph) do
|
816
|
+
Paragraph.new(
|
817
|
+
schema_location: schema_location,
|
818
|
+
paragraph: Paragraph.new(
|
819
|
+
schema_location: nested_schema_location,
|
820
|
+
text: ["Some text inside paragraph"],
|
814
821
|
),
|
815
|
-
|
816
|
-
|
817
|
-
)
|
822
|
+
)
|
823
|
+
end
|
818
824
|
|
819
|
-
|
820
|
-
|
825
|
+
it "creates XML with multiple schemaLocations" do
|
826
|
+
serialized = paragraph.to_xml
|
827
|
+
expect(serialized).to be_equivalent_to(xml)
|
828
|
+
end
|
821
829
|
end
|
822
830
|
end
|
823
831
|
|
@@ -832,16 +840,17 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
832
840
|
<p>adf</p>
|
833
841
|
</street>
|
834
842
|
<city><a>M</a></city>
|
843
|
+
<text>Building near ABC</text>
|
835
844
|
</address>
|
836
845
|
</person>
|
837
846
|
XML
|
838
847
|
end
|
839
848
|
|
840
849
|
let(:expected_street) do
|
841
|
-
if Lutaml::Model::Config.xml_adapter == Lutaml::Model::XmlAdapter::
|
842
|
-
"<a>N</a>\n<p>adf</p>\n"
|
843
|
-
else
|
850
|
+
if Lutaml::Model::Config.xml_adapter == Lutaml::Model::XmlAdapter::NokogiriAdapter
|
844
851
|
"\n <a>N</a>\n <p>adf</p>\n "
|
852
|
+
else
|
853
|
+
"<a>N</a><p>adf</p>"
|
845
854
|
end
|
846
855
|
end
|
847
856
|
|
@@ -853,6 +862,27 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
853
862
|
end
|
854
863
|
end
|
855
864
|
|
865
|
+
context "with element named `text`" do
|
866
|
+
let(:input_xml) do
|
867
|
+
<<~XML
|
868
|
+
<address>
|
869
|
+
<street>
|
870
|
+
<a>N</a>
|
871
|
+
<p>adf</p>
|
872
|
+
</street>
|
873
|
+
<city><a>M</a></city>
|
874
|
+
<text>Building near ABC</text>
|
875
|
+
</address>
|
876
|
+
XML
|
877
|
+
end
|
878
|
+
|
879
|
+
let(:model) { XmlMapping::Address.from_xml(input_xml) }
|
880
|
+
|
881
|
+
it "expect to contain raw xml" do
|
882
|
+
expect(model.text).to eq("Building near ABC")
|
883
|
+
end
|
884
|
+
end
|
885
|
+
|
856
886
|
context "with content mapping" do
|
857
887
|
let(:xml_data) { "<i>my text <b>bold</b> is in italics</i>" }
|
858
888
|
let(:italic) { Italic.from_xml(xml_data) }
|
@@ -891,6 +921,16 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
891
921
|
orig_mappings.deep_dup
|
892
922
|
end
|
893
923
|
|
924
|
+
XmlMapping::WithMapAll.mappings_for(:xml).instance_variables.each do |var|
|
925
|
+
it "duplicates #{var} correctly" do
|
926
|
+
orig_mapping = XmlMapping::WithMapAll.mappings_for(:xml)
|
927
|
+
dup_mappings = orig_mapping.deep_dup
|
928
|
+
|
929
|
+
expect(orig_mapping.instance_variable_get(var))
|
930
|
+
.to eq(dup_mappings.instance_variable_get(var))
|
931
|
+
end
|
932
|
+
end
|
933
|
+
|
894
934
|
it "duplicates root_element" do
|
895
935
|
orig_root = orig_mappings.root_element
|
896
936
|
dup_root = dup_mappings.root_element
|
@@ -904,7 +944,8 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
904
944
|
dup_namespace_uri = dup_mappings.namespace_uri
|
905
945
|
|
906
946
|
expect(orig_namespace_uri).to eq(dup_namespace_uri)
|
907
|
-
expect(orig_namespace_uri.object_id)
|
947
|
+
expect(orig_namespace_uri.object_id)
|
948
|
+
.not_to eq(dup_namespace_uri.object_id)
|
908
949
|
end
|
909
950
|
|
910
951
|
it "duplicates namespace_prefix" do
|
@@ -912,7 +953,8 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
912
953
|
dup_namespace_prefix = dup_mappings.namespace_prefix
|
913
954
|
|
914
955
|
expect(orig_namespace_prefix).to eq(dup_namespace_prefix)
|
915
|
-
expect(orig_namespace_prefix.object_id)
|
956
|
+
expect(orig_namespace_prefix.object_id)
|
957
|
+
.not_to eq(dup_namespace_prefix.object_id)
|
916
958
|
end
|
917
959
|
|
918
960
|
context "when duplicating mapping" do
|
@@ -924,7 +966,8 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
924
966
|
dup_custom_methods = dup_mapping.custom_methods
|
925
967
|
|
926
968
|
expect(orig_custom_methods).to eq(dup_custom_methods)
|
927
|
-
expect(orig_custom_methods.object_id)
|
969
|
+
expect(orig_custom_methods.object_id)
|
970
|
+
.not_to eq(dup_custom_methods.object_id)
|
928
971
|
end
|
929
972
|
|
930
973
|
it "duplicates default_namespace" do
|
@@ -932,7 +975,8 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
932
975
|
dup_default_namespace = dup_mapping.default_namespace
|
933
976
|
|
934
977
|
expect(orig_default_namespace).to eq(dup_default_namespace)
|
935
|
-
expect(orig_default_namespace.object_id)
|
978
|
+
expect(orig_default_namespace.object_id)
|
979
|
+
.not_to eq(dup_default_namespace.object_id)
|
936
980
|
end
|
937
981
|
|
938
982
|
it "duplicates delegate" do
|
@@ -1064,7 +1108,11 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
1064
1108
|
end
|
1065
1109
|
|
1066
1110
|
it "maps all the content including tags" do
|
1067
|
-
inner_xml = "
|
1111
|
+
inner_xml = if adapter_class.type == "ox"
|
1112
|
+
"Str<sub>2</sub> text<sup>1</sup> 123"
|
1113
|
+
else
|
1114
|
+
"Str<sub>2</sub>text<sup>1</sup>123"
|
1115
|
+
end
|
1068
1116
|
xml = "<WithMapAll>#{inner_xml}</WithMapAll>"
|
1069
1117
|
|
1070
1118
|
parsed = XmlMapping::WithMapAll.from_xml(xml)
|
@@ -1085,12 +1133,6 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
1085
1133
|
DESCRIPTION
|
1086
1134
|
end
|
1087
1135
|
|
1088
|
-
let(:expected_description) do
|
1089
|
-
<<~DESCRIPTION
|
1090
|
-
I'm a <b>web developer</b> with <strong>years</strong> of <i>experience</i> in many programing languages.
|
1091
|
-
DESCRIPTION
|
1092
|
-
end
|
1093
|
-
|
1094
1136
|
let(:xml) do
|
1095
1137
|
<<~XML
|
1096
1138
|
<WithNestedMapAll age="23">
|
@@ -1102,17 +1144,6 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
1102
1144
|
XML
|
1103
1145
|
end
|
1104
1146
|
|
1105
|
-
let(:expected_xml) do
|
1106
|
-
<<~XML
|
1107
|
-
<WithNestedMapAll age="23">
|
1108
|
-
<name>John Doe</name>
|
1109
|
-
<description>
|
1110
|
-
#{expected_description}
|
1111
|
-
</description>
|
1112
|
-
</WithNestedMapAll>
|
1113
|
-
XML
|
1114
|
-
end
|
1115
|
-
|
1116
1147
|
let(:parsed) do
|
1117
1148
|
XmlMapping::WithNestedMapAll.from_xml(xml)
|
1118
1149
|
end
|
@@ -1130,7 +1161,7 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
1130
1161
|
end
|
1131
1162
|
|
1132
1163
|
it "round-trips xml" do
|
1133
|
-
expect(parsed.to_xml).to be_equivalent_to(
|
1164
|
+
expect(parsed.to_xml).to be_equivalent_to(xml)
|
1134
1165
|
end
|
1135
1166
|
end
|
1136
1167
|
|
@@ -1157,6 +1188,16 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
1157
1188
|
XML
|
1158
1189
|
end
|
1159
1190
|
|
1191
|
+
let(:expected_oga_xml) do
|
1192
|
+
<<~XML.strip
|
1193
|
+
<SpecialCharContentWithMapAll>
|
1194
|
+
B <p>R&C</p>
|
1195
|
+
C <p>J—C</p>
|
1196
|
+
O <p>A & B </p>
|
1197
|
+
F <p>Z © </p></SpecialCharContentWithMapAll>
|
1198
|
+
XML
|
1199
|
+
end
|
1200
|
+
|
1160
1201
|
let(:expected_ox_xml) do
|
1161
1202
|
"<SpecialCharContentWithMapAll> " \
|
1162
1203
|
"B <p>R&C</p> " \
|
@@ -1166,9 +1207,19 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
1166
1207
|
"</SpecialCharContentWithMapAll>\n"
|
1167
1208
|
end
|
1168
1209
|
|
1210
|
+
let(:expected_xml) do
|
1211
|
+
if adapter_class.type == "ox"
|
1212
|
+
expected_ox_xml
|
1213
|
+
elsif adapter_class.type == "oga"
|
1214
|
+
expected_oga_xml
|
1215
|
+
else
|
1216
|
+
expected_nokogiri_xml
|
1217
|
+
end
|
1218
|
+
end
|
1219
|
+
|
1169
1220
|
it "round-trips xml" do
|
1170
|
-
|
1171
|
-
expect(
|
1221
|
+
parsed = XmlMapping::SpecialCharContentWithMapAll.from_xml(xml)
|
1222
|
+
expect(parsed.to_xml).to eq(expected_xml)
|
1172
1223
|
end
|
1173
1224
|
end
|
1174
1225
|
|
@@ -1181,8 +1232,12 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
1181
1232
|
XML
|
1182
1233
|
end
|
1183
1234
|
|
1235
|
+
let(:generated_xml) do
|
1236
|
+
XmlMapping::Schema.from_xml(xml).to_xml
|
1237
|
+
end
|
1238
|
+
|
1184
1239
|
it "round-trips xml" do
|
1185
|
-
expect(
|
1240
|
+
expect(generated_xml).to be_equivalent_to(xml)
|
1186
1241
|
end
|
1187
1242
|
end
|
1188
1243
|
end
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lutaml-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: base64
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: liquid
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: moxml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.2
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: thor
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +94,7 @@ files:
|
|
52
94
|
- exe/lutaml-model
|
53
95
|
- lib/lutaml/model.rb
|
54
96
|
- lib/lutaml/model/attribute.rb
|
97
|
+
- lib/lutaml/model/choice.rb
|
55
98
|
- lib/lutaml/model/cli.rb
|
56
99
|
- lib/lutaml/model/comparable_model.rb
|
57
100
|
- lib/lutaml/model/comparable_nil.rb
|
@@ -59,16 +102,24 @@ files:
|
|
59
102
|
- lib/lutaml/model/config.rb
|
60
103
|
- lib/lutaml/model/constants.rb
|
61
104
|
- lib/lutaml/model/error.rb
|
105
|
+
- lib/lutaml/model/error/choice_lower_bound_error.rb
|
106
|
+
- lib/lutaml/model/error/choice_upper_bound_error.rb
|
62
107
|
- lib/lutaml/model/error/collection_count_out_of_range_error.rb
|
63
108
|
- lib/lutaml/model/error/collection_true_missing_error.rb
|
109
|
+
- lib/lutaml/model/error/import_model_with_root_error.rb
|
64
110
|
- lib/lutaml/model/error/incorrect_mapping_argument_error.rb
|
111
|
+
- lib/lutaml/model/error/incorrect_sequence_error.rb
|
112
|
+
- lib/lutaml/model/error/invalid_choice_range_error.rb
|
65
113
|
- lib/lutaml/model/error/invalid_value_error.rb
|
66
114
|
- lib/lutaml/model/error/multiple_mappings_error.rb
|
115
|
+
- lib/lutaml/model/error/no_root_mapping_error.rb
|
116
|
+
- lib/lutaml/model/error/no_root_namespace_error.rb
|
67
117
|
- lib/lutaml/model/error/pattern_not_matched_error.rb
|
68
118
|
- lib/lutaml/model/error/type/invalid_value_error.rb
|
69
119
|
- lib/lutaml/model/error/type_error.rb
|
70
120
|
- lib/lutaml/model/error/type_not_enabled_error.rb
|
71
121
|
- lib/lutaml/model/error/unknown_adapter_type_error.rb
|
122
|
+
- lib/lutaml/model/error/unknown_sequence_mapping_error.rb
|
72
123
|
- lib/lutaml/model/error/unknown_type_error.rb
|
73
124
|
- lib/lutaml/model/error/validation_error.rb
|
74
125
|
- lib/lutaml/model/json_adapter.rb
|
@@ -78,6 +129,7 @@ files:
|
|
78
129
|
- lib/lutaml/model/json_adapter/standard_json_adapter.rb
|
79
130
|
- lib/lutaml/model/key_value_mapping.rb
|
80
131
|
- lib/lutaml/model/key_value_mapping_rule.rb
|
132
|
+
- lib/lutaml/model/liquefiable.rb
|
81
133
|
- lib/lutaml/model/loggable.rb
|
82
134
|
- lib/lutaml/model/mapping_hash.rb
|
83
135
|
- lib/lutaml/model/mapping_rule.rb
|
@@ -90,6 +142,7 @@ files:
|
|
90
142
|
- lib/lutaml/model/schema/xsd_schema.rb
|
91
143
|
- lib/lutaml/model/schema/yaml_schema.rb
|
92
144
|
- lib/lutaml/model/schema_location.rb
|
145
|
+
- lib/lutaml/model/sequence.rb
|
93
146
|
- lib/lutaml/model/serializable.rb
|
94
147
|
- lib/lutaml/model/serialize.rb
|
95
148
|
- lib/lutaml/model/toml_adapter.rb
|
@@ -116,6 +169,7 @@ files:
|
|
116
169
|
- lib/lutaml/model/xml_adapter/builder/nokogiri.rb
|
117
170
|
- lib/lutaml/model/xml_adapter/builder/oga.rb
|
118
171
|
- lib/lutaml/model/xml_adapter/builder/ox.rb
|
172
|
+
- lib/lutaml/model/xml_adapter/element.rb
|
119
173
|
- lib/lutaml/model/xml_adapter/nokogiri_adapter.rb
|
120
174
|
- lib/lutaml/model/xml_adapter/oga/document.rb
|
121
175
|
- lib/lutaml/model/xml_adapter/oga/element.rb
|
@@ -134,19 +188,25 @@ files:
|
|
134
188
|
- lutaml-model.gemspec
|
135
189
|
- sig/lutaml/model.rbs
|
136
190
|
- spec/address_spec.rb
|
191
|
+
- spec/benchmarks/xml_parsing_benchmark_spec.rb
|
192
|
+
- spec/ceramic_spec.rb
|
137
193
|
- spec/fixtures/address.rb
|
194
|
+
- spec/fixtures/ceramic.rb
|
138
195
|
- spec/fixtures/person.rb
|
139
196
|
- spec/fixtures/sample_model.rb
|
140
197
|
- spec/fixtures/vase.rb
|
198
|
+
- spec/fixtures/xml/address_example_260.xsd
|
141
199
|
- spec/fixtures/xml/invalid_math_document.xml
|
142
200
|
- spec/fixtures/xml/latin_encoding.xml
|
143
201
|
- spec/fixtures/xml/math_document_schema.xsd
|
144
202
|
- spec/fixtures/xml/shift_jis.xml
|
145
203
|
- spec/fixtures/xml/special_char.xml
|
146
204
|
- spec/fixtures/xml/test_schema.xsd
|
205
|
+
- spec/fixtures/xml/user.xsd
|
147
206
|
- spec/fixtures/xml/valid_math_document.xml
|
148
207
|
- spec/lutaml/model/attribute_spec.rb
|
149
208
|
- spec/lutaml/model/cdata_spec.rb
|
209
|
+
- spec/lutaml/model/choice_spec.rb
|
150
210
|
- spec/lutaml/model/collection_spec.rb
|
151
211
|
- spec/lutaml/model/comparable_model_spec.rb
|
152
212
|
- spec/lutaml/model/custom_model_spec.rb
|
@@ -154,10 +214,12 @@ files:
|
|
154
214
|
- spec/lutaml/model/defaults_spec.rb
|
155
215
|
- spec/lutaml/model/delegation_spec.rb
|
156
216
|
- spec/lutaml/model/enum_spec.rb
|
217
|
+
- spec/lutaml/model/group_spec.rb
|
157
218
|
- spec/lutaml/model/included_spec.rb
|
158
219
|
- spec/lutaml/model/inheritance_spec.rb
|
159
220
|
- spec/lutaml/model/json_adapter_spec.rb
|
160
221
|
- spec/lutaml/model/key_value_mapping_spec.rb
|
222
|
+
- spec/lutaml/model/liquefiable_spec.rb
|
161
223
|
- spec/lutaml/model/map_all_spec.rb
|
162
224
|
- spec/lutaml/model/map_content_spec.rb
|
163
225
|
- spec/lutaml/model/mixed_content_spec.rb
|
@@ -171,10 +233,12 @@ files:
|
|
171
233
|
- spec/lutaml/model/schema/xml_compiler_spec.rb
|
172
234
|
- spec/lutaml/model/schema/xsd_schema_spec.rb
|
173
235
|
- spec/lutaml/model/schema/yaml_schema_spec.rb
|
236
|
+
- spec/lutaml/model/sequence_spec.rb
|
174
237
|
- spec/lutaml/model/serializable_spec.rb
|
175
238
|
- spec/lutaml/model/serializable_validation_spec.rb
|
176
239
|
- spec/lutaml/model/simple_model_spec.rb
|
177
240
|
- spec/lutaml/model/toml_adapter_spec.rb
|
241
|
+
- spec/lutaml/model/transformation_spec.rb
|
178
242
|
- spec/lutaml/model/type/boolean_spec.rb
|
179
243
|
- spec/lutaml/model/type/date_spec.rb
|
180
244
|
- spec/lutaml/model/type/date_time_spec.rb
|
@@ -194,6 +258,7 @@ files:
|
|
194
258
|
- spec/lutaml/model/xml_adapter/ox_adapter_spec.rb
|
195
259
|
- spec/lutaml/model/xml_adapter/xml_namespace_spec.rb
|
196
260
|
- spec/lutaml/model/xml_adapter_spec.rb
|
261
|
+
- spec/lutaml/model/xml_mapping_rule_spec.rb
|
197
262
|
- spec/lutaml/model/xml_mapping_spec.rb
|
198
263
|
- spec/lutaml/model/yaml_adapter_spec.rb
|
199
264
|
- spec/lutaml/model_spec.rb
|