Sha256: 07e98cfc8aa6155a485784bd7accd1bd26ad7993c07b7b7e3c6ef328766ed5f9

Contents?: true

Size: 1.93 KB

Versions: 4

Compression:

Stored size: 1.93 KB

Contents

require "spec_helper"
require "lutaml/model/schema"

RSpec.describe Lutaml::Model::Schema::RelaxngSchema do
  module SchemaGeneration
    class Glaze < Lutaml::Model::Serializable
      attribute :color, Lutaml::Model::Type::String
      attribute :finish, Lutaml::Model::Type::String
    end

    class Vase < Lutaml::Model::Serializable
      attribute :height, Lutaml::Model::Type::Float
      attribute :diameter, Lutaml::Model::Type::Float
      attribute :glaze, Glaze
      attribute :materials, Lutaml::Model::Type::String, collection: true
    end
  end

  describe ".generate" do
    it "generates a RELAX NG schema for nested Serialize objects" do
      schema = described_class.generate(SchemaGeneration::Vase, pretty: true)

      expected_schema = <<~RELAXNG
        <?xml version="1.0" encoding="UTF-8"?>
        <grammar xmlns="http://relaxng.org/ns/structure/1.0">
          <start>
            <ref name="SchemaGeneration::Vase"/>
          </start>
          <define name="SchemaGeneration::Vase">
            <element name="SchemaGeneration::Vase">
              <element name="height">
                <data type="float"/>
              </element>
              <element name="diameter">
                <data type="float"/>
              </element>
              <ref name="SchemaGeneration::Glaze"/>
              <zeroOrMore>
                <element name="materials">
                  <data type="string"/>
                </element>
              </zeroOrMore>
            </element>
          </define>
          <define name="SchemaGeneration::Glaze">
            <element name="SchemaGeneration::Glaze">
              <element name="color">
                <data type="string"/>
              </element>
              <element name="finish">
                <data type="string"/>
              </element>
            </element>
          </define>
        </grammar>
      RELAXNG
      expect(schema).to eq(expected_schema)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lutaml-model-0.3.28 spec/lutaml/model/schema/relaxng_schema_spec.rb
lutaml-model-0.3.27 spec/lutaml/model/schema/relaxng_schema_spec.rb
lutaml-model-0.3.26 spec/lutaml/model/schema/relaxng_schema_spec.rb
lutaml-model-0.3.25 spec/lutaml/model/schema/relaxng_schema_spec.rb