Class: OpenAPIParser::SchemaValidator::AnyOfValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/openapi_parser/schema_validator/any_of_validator.rb

Instance Attribute Summary

Attributes inherited from Base

#validatable

Instance Method Summary collapse

Methods inherited from Base

#initialize, #validate_discriminator_schema

Constructor Details

This class inherits a constructor from OpenAPIParser::SchemaValidator::Base

Instance Method Details

#coerce_and_validate(value, schema, **_keyword_args) ⇒ Object

Parameters:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/openapi_parser/schema_validator/any_of_validator.rb', line 5

def coerce_and_validate(value, schema, **_keyword_args)
  if value.nil? && schema.nullable
    return [value, nil]
  end
  if schema.discriminator
    return validate_discriminator_schema(schema.discriminator, value)
  end

  # in all schema return error (=true) not any of data
  schema.any_of.each do |s|
    coerced, err = validatable.validate_schema(value, s)
    return [coerced, nil] if err.nil?
  end
  [nil, OpenAPIParser::NotAnyOf.new(value, schema.object_reference)]
end