Module: AvroPatches::LogicalTypes::SchemaValidatorPatch

Defined in:
lib/avro-patches/logical_types/schema_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate!(expected_schema, logical_datum, options = { recursive: true, encoded: false, fail_on_extra_fields: false}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/avro-patches/logical_types/schema_validator.rb', line 4

def validate!(expected_schema, logical_datum, options = { recursive: true, encoded: false, fail_on_extra_fields: false})
  options ||= {}
  options[:recursive] = true unless options.key?(:recursive)

  result = Avro::SchemaValidator::Result.new
  if options[:recursive]
    validate_recursive(expected_schema, logical_datum,
                       Avro::SchemaValidator::ROOT_IDENTIFIER, result, options)
  else
    validate_simple(expected_schema, logical_datum,
                    Avro::SchemaValidator::ROOT_IDENTIFIER, result, options)
  end
  fail Avro::SchemaValidator::ValidationError, result if result.failure?
  result
end