Sha256: e0bc3bc1e3e1d8806d213fd383755bbbc544d6a50af1905898f4b16ed818ea58

Contents?: true

Size: 558 Bytes

Versions: 5

Compression:

Stored size: 558 Bytes

Contents

module Finitio
  class UnionType

    NIL_TYPE = BuiltinType.new(NilClass)

    FALSE_TYPE = BuiltinType.new(TrueClass)

    TRUE_TYPE = BuiltinType.new(FalseClass)

    BOOLEAN_TYPE = UnionType.new([TRUE_TYPE, FALSE_TYPE])

    def to_json_schema(*args, &bl)
      cs = candidates.reject{|c| c == NIL_TYPE }
      return { type: 'boolean'} if self == BOOLEAN_TYPE
      return cs.first.to_json_schema(*args, &bl) if cs.size == 1

      {
        anyOf: cs.map{|c| c.to_json_schema(*args, &bl) }
      }
    end

  end # class UnionType
end # module Finitio

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
finitio-0.12.0 lib/finitio/json_schema/union_type.rb
finitio-0.11.4 lib/finitio/json_schema/union_type.rb
finitio-0.11.3 lib/finitio/json_schema/union_type.rb
finitio-0.11.2 lib/finitio/json_schema/union_type.rb
finitio-0.11.1 lib/finitio/json_schema/union_type.rb