Sha256: c09d4e64fd1e49f178eefa3e5b52aaba4f7f9c77fedd7f1cc2489a796a4297fb

Contents?: true

Size: 622 Bytes

Versions: 17

Compression:

Stored size: 622 Bytes

Contents

module Schemacop
  module V3
    class OneOfNode < CombinationNode
      def type
        :oneOf
      end

      def _validate(data, result:)
        super_data = super
        return if super_data.nil?

        matches = matches(super_data)

        if matches.size == 1
          matches.first._validate(super_data, result: result)
        else
          result.error "Matches #{matches.size} definitions but should match exactly 1."
        end
      end

      def validate_self
        if @items.size < 2
          fail 'Node "one_of" makes only sense with at least 2 items.'
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
schemacop-3.0.10 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.9 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.8 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.7 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.6 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.5 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.4 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.3 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.2 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.1 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.0 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.0.rc5 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.0.rc4 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.0.rc3 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.0.rc2 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.0.rc1 lib/schemacop/v3/one_of_node.rb
schemacop-3.0.0.rc0 lib/schemacop/v3/one_of_node.rb