Class: OpenAPIParser::SchemaValidator::OneOfValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/openapi_parser/schema_validator/one_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
20
21
22
23
# File 'lib/openapi_parser/schema_validator/one_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

  # if multiple schemas are satisfied, it's not valid
  result = schema.one_of.one? do |s|
    _coerced, err = validatable.validate_schema(value, s)
    err.nil?
  end
  if result
    [value, nil]
  else
    [nil, OpenAPIParser::NotOneOf.new(value, schema.object_reference)]
  end
end