lutaml-model 0.8.17 → 0.8.18
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/.github/workflows/downstream-performance.yml +27 -1
- data/.github/workflows/js-pr-check.yml +102 -0
- data/.github/workflows/js-sync.yml +51 -0
- data/.github/workflows/opal.yml +26 -6
- data/.github/workflows/performance.yml +32 -7
- data/.github/workflows/rake.yml +78 -32
- data/.gitmodules +6 -0
- data/.rubocop_todo.yml +8 -0
- data/Gemfile +16 -1
- data/README.adoc +267 -0
- data/Rakefile +166 -4
- data/docs/_guides/schema-import.adoc +42 -0
- data/docs/_guides/xml-mapping.adoc +21 -0
- data/docs/_pages/validation.adoc +65 -0
- data/lib/compat/opal/generate_boot.rb +123 -0
- data/lib/compat/opal/js_bundle_entry.rb +42 -0
- data/lib/compat/opal/lutaml_model_boot.rb +497 -0
- data/lib/compat/opal/moxml_boot.rb +68 -0
- data/lib/compat/opal/yaml_compat.rb +32 -0
- data/lib/lutaml/json.rb +1 -1
- data/lib/lutaml/key_value/transform.rb +3 -8
- data/lib/lutaml/key_value/transformation/value_serializer.rb +14 -1
- data/lib/lutaml/key_value/transformation.rb +17 -5
- data/lib/lutaml/model/adapter_resolver.rb +2 -2
- data/lib/lutaml/model/attribute.rb +88 -11
- data/lib/lutaml/model/cached_type_resolver.rb +1 -1
- data/lib/lutaml/model/error/union_schema_unsupported_error.rb +11 -0
- data/lib/lutaml/model/global_context.rb +11 -8
- data/lib/lutaml/model/instrumentation.rb +2 -2
- data/lib/lutaml/model/mapping/mapping_rule.rb +0 -6
- data/lib/lutaml/model/register.rb +2 -2
- data/lib/lutaml/model/runtime_compatibility.rb +50 -0
- data/lib/lutaml/model/schema/class_loader.rb +58 -0
- data/lib/lutaml/model/schema/compiled_output.rb +83 -0
- data/lib/lutaml/model/schema/definitions/attribute.rb +32 -0
- data/lib/lutaml/model/schema/definitions/choice.rb +20 -0
- data/lib/lutaml/model/schema/definitions/facet.rb +40 -0
- data/lib/lutaml/model/schema/definitions/group_import.rb +22 -0
- data/lib/lutaml/model/schema/definitions/member_walk.rb +33 -0
- data/lib/lutaml/model/schema/definitions/model.rb +40 -0
- data/lib/lutaml/model/schema/definitions/namespace.rb +23 -0
- data/lib/lutaml/model/schema/definitions/restricted_type.rb +30 -0
- data/lib/lutaml/model/schema/definitions/sequence.rb +19 -0
- data/lib/lutaml/model/schema/definitions/simple_content.rb +22 -0
- data/lib/lutaml/model/schema/definitions/transform_facet.rb +21 -0
- data/lib/lutaml/model/schema/definitions/type_ref.rb +20 -0
- data/lib/lutaml/model/schema/definitions/union_type.rb +28 -0
- data/lib/lutaml/model/schema/definitions/xml_root.rb +20 -0
- data/lib/lutaml/model/schema/definitions.rb +24 -0
- data/lib/lutaml/model/schema/file_writer.rb +70 -0
- data/lib/lutaml/model/schema/generator/definitions_collection.rb +16 -2
- data/lib/lutaml/model/schema/generator/property.rb +21 -4
- data/lib/lutaml/model/schema/module_nesting.rb +31 -0
- data/lib/lutaml/model/schema/namespace_naming.rb +46 -0
- data/lib/lutaml/model/schema/registry_generator.rb +115 -0
- data/lib/lutaml/model/schema/renderers/base.rb +40 -0
- data/lib/lutaml/model/schema/renderers/mappings.rb +72 -0
- data/lib/lutaml/model/schema/renderers/member_decls.rb +115 -0
- data/lib/lutaml/model/schema/renderers/model.rb +121 -0
- data/lib/lutaml/model/schema/renderers/namespace.rb +30 -0
- data/lib/lutaml/model/schema/renderers/registration.rb +64 -0
- data/lib/lutaml/model/schema/renderers/required_files_calculator.rb +93 -0
- data/lib/lutaml/model/schema/renderers/restricted_type.rb +88 -0
- data/lib/lutaml/model/schema/renderers/union.rb +83 -0
- data/lib/lutaml/model/schema/renderers.rb +19 -0
- data/lib/lutaml/model/schema/rnc_compiler/source_resolver.rb +47 -0
- data/lib/lutaml/model/schema/rnc_compiler.rb +62 -0
- data/lib/lutaml/model/schema/rng_compiler/define_classifier.rb +91 -0
- data/lib/lutaml/model/schema/rng_compiler/element_visitor.rb +392 -0
- data/lib/lutaml/model/schema/rng_compiler/member_collector.rb +30 -0
- data/lib/lutaml/model/schema/rng_compiler/rng_helpers.rb +152 -0
- data/lib/lutaml/model/schema/rng_compiler/value_type_resolver.rb +125 -0
- data/lib/lutaml/model/schema/rng_compiler.rb +220 -0
- data/lib/lutaml/model/schema/templates.rb +162 -0
- data/lib/lutaml/model/schema/xml_compiler/element_order.rb +41 -0
- data/lib/lutaml/model/schema/xml_compiler/registry_generator.rb +31 -107
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/complex_types.rb +191 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +216 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +153 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder.rb +167 -0
- data/lib/lutaml/model/schema/xml_compiler/supported_data_types.rb +87 -0
- data/lib/lutaml/model/schema/xml_compiler.rb +38 -517
- data/lib/lutaml/model/schema.rb +19 -0
- data/lib/lutaml/model/serialize/attribute_definition.rb +14 -2
- data/lib/lutaml/model/serialize/builder.rb +15 -2
- data/lib/lutaml/model/serialize/value_mapping.rb +9 -57
- data/lib/lutaml/model/serialize.rb +6 -9
- data/lib/lutaml/model/services/rule_value_extractor.rb +2 -3
- data/lib/lutaml/model/services.rb +0 -2
- data/lib/lutaml/model/store.rb +2 -1
- data/lib/lutaml/model/toml.rb +1 -1
- data/lib/lutaml/model/transform.rb +17 -39
- data/lib/lutaml/model/transformation_registry.rb +1 -1
- data/lib/lutaml/model/type.rb +1 -0
- data/lib/lutaml/model/union.rb +320 -0
- data/lib/lutaml/model/utils.rb +6 -0
- data/lib/lutaml/model/validation.rb +1 -4
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model.rb +18 -0
- data/lib/lutaml/toml.rb +1 -1
- data/lib/lutaml/xml/adapter.rb +1 -1
- data/lib/lutaml/xml/adapter_loader.rb +1 -1
- data/lib/lutaml/xml/builder/base.rb +1 -1
- data/lib/lutaml/xml/builder.rb +1 -1
- data/lib/lutaml/xml/error/schema_validation_error.rb +25 -0
- data/lib/lutaml/xml/model_transform.rb +5 -1
- data/lib/lutaml/xml/schema/relaxng_schema.rb +5 -0
- data/lib/lutaml/xml/schema/xsd_schema.rb +4 -0
- data/lib/lutaml/xml/serialization/format_conversion.rb +48 -0
- data/lib/lutaml/xml/serialization/instance_methods.rb +13 -0
- data/lib/lutaml/xml/transformation/element_builder.rb +21 -8
- data/lib/lutaml/xml/transformation/ordered_applier.rb +6 -0
- data/lib/lutaml/xml/xsd_validator.rb +66 -0
- data/lib/lutaml/xml.rb +53 -12
- data/lutaml-model.gemspec +4 -2
- data/spec/fixtures/xml/schema/rnc/address_book.rnc +15 -0
- data/spec/fixtures/xml/schema/rnc/book_features.rnc +18 -0
- data/spec/fixtures/xml/schema/rnc/includes/book.rnc +6 -0
- data/spec/fixtures/xml/schema/rnc/includes/circular_a.rnc +8 -0
- data/spec/fixtures/xml/schema/rnc/includes/circular_b.rnc +8 -0
- data/spec/fixtures/xml/schema/rnc/includes/library.rnc +8 -0
- data/spec/fixtures/xml/schema/rng/address_book.rng +16 -0
- data/spec/fixtures/xml/schema/rng/book.rng +27 -0
- data/spec/fixtures/xml/schema/rng/fixed_value.rng +11 -0
- data/spec/fixtures/xml/schema/rng/fragment_in_choice.rng +30 -0
- data/spec/fixtures/xml/schema/rng/full_name.rng +39 -0
- data/spec/fixtures/xml/schema/rng/integer_range.rng +32 -0
- data/spec/fixtures/xml/schema/rng/list_type.rng +12 -0
- data/spec/fixtures/xml/schema/rng/namespaced.rng +9 -0
- data/spec/fixtures/xml/schema/rng/paragraph.rng +13 -0
- data/spec/fixtures/xml/schema/rng/person.rng +23 -0
- data/spec/fixtures/xml/schema/rng/union.rng +14 -0
- data/spec/fixtures/xml/validate_xml_with_address.xsd +13 -0
- data/spec/fixtures/xml/validate_xml_with_contact.xsd +11 -0
- data/spec/fixtures/xml/validate_xml_with_person.xsd +11 -0
- data/spec/fixtures/xml/validate_xml_with_person_strict.xsd +17 -0
- data/spec/fixtures/xml/validate_xml_with_product.xsd +37 -0
- data/spec/lutaml/model/attribute_apply_value_map_spec.rb +134 -0
- data/spec/lutaml/model/attribute_spec.rb +169 -12
- data/spec/lutaml/model/boot_manifest_spec.rb +30 -0
- data/spec/lutaml/model/collection_spec.rb +18 -0
- data/spec/lutaml/model/mixed_content_spec.rb +171 -0
- data/spec/lutaml/model/opal_smoke_spec.rb +67 -2
- data/spec/lutaml/model/ordered_content_spec.rb +30 -0
- data/spec/lutaml/model/raw_element_spec.rb +125 -0
- data/spec/lutaml/model/rule_value_extractor_spec.rb +7 -14
- data/spec/lutaml/model/runtime_compatibility_spec.rb +25 -0
- data/spec/lutaml/model/schema/renderers/model_spec.rb +149 -0
- data/spec/lutaml/model/schema/renderers/namespace_spec.rb +36 -0
- data/spec/lutaml/model/schema/renderers/restricted_type_spec.rb +75 -0
- data/spec/lutaml/model/schema/renderers/union_spec.rb +58 -0
- data/spec/lutaml/model/transform_apply_value_map_spec.rb +64 -0
- data/spec/lutaml/model/union_attribute_spec.rb +658 -0
- data/spec/lutaml/model/union_spec.rb +257 -0
- data/spec/lutaml/model/utils_spec.rb +14 -0
- data/spec/lutaml/xml/opal_xml_spec.rb +22 -20
- data/spec/lutaml/xml/schema/compiler_spec.rb +21 -4
- data/spec/lutaml/xml/schema/rnc_compiler_spec.rb +404 -0
- data/spec/lutaml/xml/schema/rng_compiler_spec.rb +893 -0
- data/spec/lutaml/xml/validate_xml_with_constructs_spec.rb +222 -0
- data/spec/lutaml/xml/validate_xml_with_spec.rb +186 -0
- data/spec/spec_helper.rb +28 -11
- data/spec/support/opal.rb +5 -2
- metadata +97 -31
- data/lib/lutaml/model/schema/xml_compiler/attribute.rb +0 -106
- data/lib/lutaml/model/schema/xml_compiler/attribute_group.rb +0 -47
- data/lib/lutaml/model/schema/xml_compiler/choice.rb +0 -67
- data/lib/lutaml/model/schema/xml_compiler/complex_content.rb +0 -27
- data/lib/lutaml/model/schema/xml_compiler/complex_content_restriction.rb +0 -34
- data/lib/lutaml/model/schema/xml_compiler/complex_type.rb +0 -173
- data/lib/lutaml/model/schema/xml_compiler/element.rb +0 -121
- data/lib/lutaml/model/schema/xml_compiler/group.rb +0 -113
- data/lib/lutaml/model/schema/xml_compiler/restriction.rb +0 -104
- data/lib/lutaml/model/schema/xml_compiler/sequence.rb +0 -52
- data/lib/lutaml/model/schema/xml_compiler/simple_content.rb +0 -40
- data/lib/lutaml/model/schema/xml_compiler/simple_type.rb +0 -265
- data/lib/lutaml/model/schema/xml_compiler/xml_namespace_class.rb +0 -110
- data/lib/lutaml/model/services/default_value_resolver.rb +0 -60
- data/spec/lutaml/model/services/default_value_resolver_spec.rb +0 -162
- data/spec/lutaml/xml/schema/compiler/attribute_group_spec.rb +0 -71
- data/spec/lutaml/xml/schema/compiler/attribute_spec.rb +0 -67
- data/spec/lutaml/xml/schema/compiler/choice_spec.rb +0 -74
- data/spec/lutaml/xml/schema/compiler/complex_content_restriction_spec.rb +0 -60
- data/spec/lutaml/xml/schema/compiler/complex_content_spec.rb +0 -41
- data/spec/lutaml/xml/schema/compiler/complex_type_spec.rb +0 -202
- data/spec/lutaml/xml/schema/compiler/element_spec.rb +0 -68
- data/spec/lutaml/xml/schema/compiler/group_spec.rb +0 -90
- data/spec/lutaml/xml/schema/compiler/restriction_spec.rb +0 -77
- data/spec/lutaml/xml/schema/compiler/sequence_spec.rb +0 -65
- data/spec/lutaml/xml/schema/compiler/simple_content_spec.rb +0 -61
- data/spec/lutaml/xml/schema/compiler/simple_type_spec.rb +0 -184
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "support/xml/schema_helper"
|
|
3
|
-
|
|
4
|
-
RSpec.describe Lutaml::Model::Schema::XmlCompiler::Sequence do
|
|
5
|
-
let(:sequence) { described_class.new }
|
|
6
|
-
let(:dummy_class) do
|
|
7
|
-
Class.new do
|
|
8
|
-
def to_attributes(indent); end
|
|
9
|
-
def to_xml_mapping(indent); end
|
|
10
|
-
def required_files; end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "#initialize" do
|
|
15
|
-
it "starts with empty instances" do
|
|
16
|
-
expect(sequence.instances).to eq([])
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "#<<" do
|
|
21
|
-
it "adds instances to the list" do
|
|
22
|
-
instance = instance_double(dummy_class,
|
|
23
|
-
to_attributes: " attribute :foo, :string\n", to_xml_mapping: " map_element :foo, to: :foo\n", required_files: "require 'foo'")
|
|
24
|
-
expect { sequence << instance }.to change {
|
|
25
|
-
sequence.instances.size
|
|
26
|
-
}.by(1)
|
|
27
|
-
expect(sequence.instances).to include(instance)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "ignores nil instances" do
|
|
31
|
-
expect { sequence << nil }.not_to(change { sequence.instances.size })
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "#to_attributes" do
|
|
36
|
-
it "returns joined attributes from instances" do
|
|
37
|
-
instance = instance_double(dummy_class,
|
|
38
|
-
to_attributes: " attribute :foo, :string\n")
|
|
39
|
-
sequence << instance
|
|
40
|
-
expect(sequence.to_attributes(" ")).to include("attribute :foo, :string")
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe "#to_xml_mapping" do
|
|
45
|
-
it "returns empty string if no content" do
|
|
46
|
-
expect(sequence.to_xml_mapping(" ")).to eq("")
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "returns xml mapping block if content exists" do
|
|
50
|
-
instance = instance_double(dummy_class,
|
|
51
|
-
to_xml_mapping: " map_element :foo, to: :foo\n")
|
|
52
|
-
sequence << instance
|
|
53
|
-
expect(sequence.to_xml_mapping(" ")).to include("sequence do")
|
|
54
|
-
expect(sequence.to_xml_mapping(" ")).to include("map_element :foo, to: :foo")
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe "#required_files" do
|
|
59
|
-
it "collects required_files from all instances" do
|
|
60
|
-
instance = instance_double(dummy_class, required_files: "require 'foo'")
|
|
61
|
-
sequence << instance
|
|
62
|
-
expect(sequence.required_files).to include("require 'foo'")
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "support/xml/schema_helper"
|
|
3
|
-
|
|
4
|
-
RSpec.describe Lutaml::Model::Schema::XmlCompiler::SimpleContent do
|
|
5
|
-
let(:simple_content) { described_class.new }
|
|
6
|
-
let(:dummy_class) do
|
|
7
|
-
Class.new do
|
|
8
|
-
def to_attributes(indent); end
|
|
9
|
-
def to_xml_mapping(indent); end
|
|
10
|
-
def required_files; end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "#initialize" do
|
|
15
|
-
it "starts with empty instances and nil base_class" do
|
|
16
|
-
expect(simple_content.instances).to eq([])
|
|
17
|
-
expect(simple_content.base_class).to be_nil
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "#<<" do
|
|
22
|
-
it "adds instances to the list" do
|
|
23
|
-
instance = instance_double(dummy_class, to_attributes: "attr",
|
|
24
|
-
to_xml_mapping: "xml", required_files: "files")
|
|
25
|
-
expect { simple_content << instance }.to change {
|
|
26
|
-
simple_content.instances.size
|
|
27
|
-
}.by(1)
|
|
28
|
-
expect(simple_content.instances).to include(instance)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "ignores nil instances" do
|
|
32
|
-
expect { simple_content << nil }.not_to(change do
|
|
33
|
-
simple_content.instances.size
|
|
34
|
-
end)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "#to_attributes" do
|
|
39
|
-
it "returns joined attributes from instances" do
|
|
40
|
-
instance = instance_double(dummy_class, to_attributes: "attr")
|
|
41
|
-
simple_content << instance
|
|
42
|
-
expect(simple_content.to_attributes(" ")).to include("attr")
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe "#to_xml_mapping" do
|
|
47
|
-
it "returns joined xml mappings from instances" do
|
|
48
|
-
instance = instance_double(dummy_class, to_xml_mapping: "xml")
|
|
49
|
-
simple_content << instance
|
|
50
|
-
expect(simple_content.to_xml_mapping(" ")).to include("xml")
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "#required_files" do
|
|
55
|
-
it "collects required_files from all instances" do
|
|
56
|
-
instance = instance_double(dummy_class, required_files: "files")
|
|
57
|
-
simple_content << instance
|
|
58
|
-
expect(simple_content.required_files).to include("files")
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "support/xml/schema_helper"
|
|
3
|
-
|
|
4
|
-
RSpec.describe Lutaml::Model::Schema::XmlCompiler::SimpleType do
|
|
5
|
-
let(:class_name) { "TestType" }
|
|
6
|
-
let(:base_class) { "string" }
|
|
7
|
-
let(:unions) { [] }
|
|
8
|
-
let(:simple_type) { described_class.new(class_name, unions) }
|
|
9
|
-
|
|
10
|
-
describe "#initialize" do
|
|
11
|
-
it "sets class_name and unions" do
|
|
12
|
-
expect(simple_type.class_name).to eq(class_name)
|
|
13
|
-
expect(simple_type.unions).to eq([])
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "allows unions to be set" do
|
|
17
|
-
st = described_class.new("UnionType", ["foo", "bar"])
|
|
18
|
-
expect(st.unions).to eq(["foo", "bar"])
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "attribute accessors" do
|
|
23
|
-
it "allows reading and writing base_class and instance" do
|
|
24
|
-
simple_type.base_class = "integer"
|
|
25
|
-
expect(simple_type.base_class).to eq("integer")
|
|
26
|
-
simple_type.instance = :foo
|
|
27
|
-
expect(simple_type.instance).to eq(:foo)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#to_class" do
|
|
32
|
-
before do
|
|
33
|
-
simple_type.base_class = base_class
|
|
34
|
-
simple_type.instance = Lutaml::Model::Schema::XmlCompiler::Restriction.new
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "renders the instance model template when no unions" do
|
|
38
|
-
result = simple_type.to_class
|
|
39
|
-
expect(result).to include("class TestType")
|
|
40
|
-
expect(result).to include("def self.cast")
|
|
41
|
-
expect(result).to include("register_class_with_id")
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "renders the union model template when unions are present" do
|
|
45
|
-
st = described_class.new("UnionType", ["foo", "bar"])
|
|
46
|
-
st.base_class = base_class
|
|
47
|
-
st.instance = Lutaml::Model::Schema::XmlCompiler::Restriction.new
|
|
48
|
-
result = st.to_class
|
|
49
|
-
expect(result).to include("class UnionType < Lutaml::Model::Type::Value")
|
|
50
|
-
expect(result).to include("def self.cast")
|
|
51
|
-
expect(result).to include("register_class_with_id")
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "respects the :indent option" do
|
|
55
|
-
result = simple_type.to_class(options: { indent: 4 })
|
|
56
|
-
expect(result).to include(" def self.cast") # 4 spaces
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe "#required_files" do
|
|
61
|
-
it "returns nil if instance is nil" do
|
|
62
|
-
expect(simple_type.required_files).to be_empty
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "returns required files from instance and parent class when not using module namespace" do
|
|
66
|
-
restriction = Lutaml::Model::Schema::XmlCompiler::Restriction.new
|
|
67
|
-
allow(restriction).to receive(:required_files).and_return(["require 'foo'"])
|
|
68
|
-
simple_type.instance = restriction
|
|
69
|
-
allow(simple_type).to receive_messages(require_parent?: true,
|
|
70
|
-
parent_class: "ParentClass")
|
|
71
|
-
expect(simple_type.required_files).to include("require 'foo'")
|
|
72
|
-
# When not using module_namespace, require_relative is added for parent
|
|
73
|
-
expect(simple_type.required_files).to include("require_relative \"parent_class\"")
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
describe "private methods" do
|
|
78
|
-
it "klass_name returns camel case" do
|
|
79
|
-
expect(simple_type.send(:klass_name)).to eq("TestType")
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "parent_class returns correct class for skippable and non-skippable" do
|
|
83
|
-
simple_type.base_class = "string"
|
|
84
|
-
expect(simple_type.send(:parent_class)).to eq("Lutaml::Model::Type::String")
|
|
85
|
-
simple_type.base_class = "nonNegativeInteger"
|
|
86
|
-
expect(simple_type.send(:parent_class)).to eq("NonNegativeInteger")
|
|
87
|
-
simple_type.base_class = nil
|
|
88
|
-
expect(simple_type.send(:parent_class)).to eq("Lutaml::Model::Type::Value")
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "require_parent? returns correct boolean" do
|
|
92
|
-
simple_type.base_class = "string"
|
|
93
|
-
expect(simple_type.send(:require_parent?)).to be false
|
|
94
|
-
simple_type.base_class = "unknownType"
|
|
95
|
-
expect(simple_type.send(:require_parent?)).to be true
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "union_class_method_body returns correct code" do
|
|
99
|
-
st = described_class.new("UnionType", ["foo:Bar", "baz:Qux"])
|
|
100
|
-
expect(st.send(:union_class_method_body)).to include("Lutaml::Model::GlobalContext.resolve_type(:bar, @register).cast(value, options)")
|
|
101
|
-
expect(st.send(:union_class_method_body)).to include("Lutaml::Model::GlobalContext.resolve_type(:qux, @register).cast(value, options)")
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it "union_required_files returns require_relative for non-skippable union type" do
|
|
105
|
-
st = described_class.new("UnionType", ["foo:Bar", "baz:string"])
|
|
106
|
-
expect(st.send(:union_required_files)).to include("require_relative \"bar\"")
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
describe ".setup_supported_types" do
|
|
111
|
-
it "returns a hash of supported types with correct instances" do
|
|
112
|
-
types = described_class.setup_supported_types
|
|
113
|
-
expect(types).to be_a(Hash)
|
|
114
|
-
expect(types.keys).to include("nonNegativeInteger")
|
|
115
|
-
expect(types["nonNegativeInteger"]).to be_a(described_class)
|
|
116
|
-
expect(types["nonNegativeInteger"].base_class).to eq("string")
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe ".setup_restriction" do
|
|
121
|
-
it "returns nil if validations is nil" do
|
|
122
|
-
expect(described_class.setup_restriction("string", nil)).to be_nil
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it "returns a Restriction with correct values" do
|
|
126
|
-
validations = { min_inclusive: 1, max_inclusive: 10, pattern: /foo/,
|
|
127
|
-
transform: "bar" }
|
|
128
|
-
restriction = described_class.setup_restriction("string", validations)
|
|
129
|
-
expect(restriction).to be_a(Lutaml::Model::Schema::XmlCompiler::Restriction)
|
|
130
|
-
expect(restriction.base_class).to eq("string")
|
|
131
|
-
expect(restriction.min_inclusive).to eq(1)
|
|
132
|
-
expect(restriction.max_inclusive).to eq(10)
|
|
133
|
-
expect(restriction.pattern).to eq(/foo/)
|
|
134
|
-
expect(restriction.transform).to eq("bar")
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
describe ".skippable?" do
|
|
139
|
-
it "returns true for skippable types" do
|
|
140
|
-
expect(described_class.skippable?("string")).to be true
|
|
141
|
-
expect(described_class.skippable?("int")).to be true
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
it "returns false for non-skippable types" do
|
|
145
|
-
expect(described_class.skippable?("nonNegativeInteger")).to be false
|
|
146
|
-
expect(described_class.skippable?("id")).to be false
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
describe "edge cases" do
|
|
151
|
-
it "handles unknown base_class gracefully" do
|
|
152
|
-
simple_type.base_class = nil
|
|
153
|
-
expect { simple_type.send(:parent_class) }.not_to raise_error
|
|
154
|
-
expect(simple_type.send(:parent_class)).to eq("Lutaml::Model::Type::Value")
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "handles unions with skippable and non-skippable types" do
|
|
158
|
-
st = described_class.new("UnionType", ["foo:string", "bar:CustomType"])
|
|
159
|
-
expect(st.send(:union_required_files)).to include("require_relative \"custom_type\"")
|
|
160
|
-
expect(st.send(:union_required_files)).not_to include("string")
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
describe "integration" do
|
|
165
|
-
it "generates valid Ruby code for a simple type" do
|
|
166
|
-
simple_type.base_class = "string"
|
|
167
|
-
simple_type.instance = Lutaml::Model::Schema::XmlCompiler::Restriction.new
|
|
168
|
-
code = simple_type.to_class
|
|
169
|
-
expect(code).to include("class TestType")
|
|
170
|
-
expect(code).to include("def self.cast")
|
|
171
|
-
expect(code).to include("register_class_with_id")
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
it "generates valid Ruby code for a union type" do
|
|
175
|
-
st = described_class.new("UnionType", ["foo:Bar", "baz:Qux"])
|
|
176
|
-
st.base_class = "string"
|
|
177
|
-
st.instance = Lutaml::Model::Schema::XmlCompiler::Restriction.new
|
|
178
|
-
code = st.to_class
|
|
179
|
-
expect(code).to include("class UnionType < Lutaml::Model::Type::Value")
|
|
180
|
-
expect(code).to include("def self.cast")
|
|
181
|
-
expect(code).to include("register_class_with_id")
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
end
|