Sha256: d582ce6e07d5f649a51a1c57cec7993a0f0141e32455200b2a810eaecbcb3fe0

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

module Finitio
  module JsonSchema
    describe "UnionType" do

      let(:string_type) {
        BuiltinType.new(String)
      }

      let(:int_type) {
        BuiltinType.new(Integer)
      }

      let(:true_type) {
        BuiltinType.new(TrueClass)
      }

      let(:false_type) {
        BuiltinType.new(FalseClass)
      }

      let(:nil_type) {
        BuiltinType.new(NilClass)
      }

      context 'when used with a single type' do
        let(:union_type) {
          UnionType.new([string_type])
        }

        it 'works as expected' do
          expect(union_type.to_json_schema).to eql({
            :type => "string"
          })
        end
      end

      context 'when used with two types' do
        let(:union_type) {
          UnionType.new([string_type, int_type])
        }

        it 'works as expected' do
          expect(union_type.to_json_schema).to eql({
            anyOf: [{:type => "string"}, {:type => "integer"}]
          })
        end
      end

      context 'when used with a |Nil' do
        let(:union_type) {
          UnionType.new([string_type, int_type, nil_type])
        }

        it 'works as expected' do
          expect(union_type.to_json_schema).to eql({
            anyOf: [{:type => "string"}, {:type => "integer"}]
          })
        end
      end

      context 'when used with a TrueClass|FalseClass' do
        let(:union_type) {
          UnionType.new([true_type, false_type])
        }

        it 'works as expected' do
          expect(union_type.to_json_schema).to eql({
            :type => "boolean"
          })
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
finitio-0.12.0 spec/json_schema/test_union_type.rb
finitio-0.11.4 spec/json_schema/test_union_type.rb
finitio-0.11.3 spec/json_schema/test_union_type.rb
finitio-0.11.2 spec/json_schema/test_union_type.rb
finitio-0.11.1 spec/json_schema/test_union_type.rb