Class: Schemacop::V3::OneOfNode

Inherits:
CombinationNode show all
Defined in:
lib/schemacop/v3/one_of_node.rb

Instance Attribute Summary

Attributes inherited from Node

#as, #default, #description, #name, #options, #parent, #title

Instance Method Summary collapse

Methods inherited from CombinationNode

#add_child, #as_json, #cast, dsl_methods, #init

Methods inherited from Node

allowed_options, #allowed_types, #as_json, #cast, #children, create, #create, dsl_methods, #dsl_node, #dsl_scm, #init, #initialize, #required?, resolve_class, #schemas, supports_children, supports_children_options, #used_external_schemas, #validate

Constructor Details

This class inherits a constructor from Schemacop::V3::Node

Instance Method Details

#_validate(data, result:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/schemacop/v3/one_of_node.rb', line 8

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

#typeObject



4
5
6
# File 'lib/schemacop/v3/one_of_node.rb', line 4

def type
  :oneOf
end

#validate_selfObject



21
22
23
24
25
# File 'lib/schemacop/v3/one_of_node.rb', line 21

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