Class: Avro::SchemaValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/avro/schema_validator.rb

Defined Under Namespace

Classes: Result, ValidationError

Constant Summary collapse

ROOT_IDENTIFIER =
'.'
PATH_SEPARATOR =
'.'
INT_RANGE =
(Schema::INT_MIN_VALUE..Schema::INT_MAX_VALUE).freeze
LONG_RANGE =
(Schema::LONG_MIN_VALUE..Schema::LONG_MAX_VALUE).freeze
COMPLEX_TYPES =
[:array, :error, :map, :record, :request].freeze
BOOLEAN_VALUES =
[true, false].freeze
DEFAULT_VALIDATION_OPTIONS =
{ recursive: true, encoded: false, fail_on_extra_fields: false }.freeze
RECURSIVE_SIMPLE_VALIDATION_OPTIONS =
{ encoded: true }.freeze
RUBY_CLASS_TO_AVRO_TYPE =
{
  NilClass => 'null',
  String => 'string',
  Float => 'float',
  Hash => 'record'
}.freeze
TypeMismatchError =
Class.new(ValidationError)

Class Method Summary collapse

Class Method Details

.validate!(expected_schema, logical_datum, options = DEFAULT_VALIDATION_OPTIONS) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/avro/schema_validator.rb', line 74

def validate!(expected_schema, logical_datum, options = DEFAULT_VALIDATION_OPTIONS)
  result = Result.new
  if options.fetch(:recursive, true)
    validate_recursive(expected_schema, logical_datum, ROOT_IDENTIFIER, result, options)
  else
    validate_simple(expected_schema, logical_datum, ROOT_IDENTIFIER, result, options)
  end
  fail ValidationError, result if result.failure?
  result
end