Sha256: eac37cf509dbdd578a725842b575edeaa0deec4f1b53c96c707286cec6a21c85

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

module Avromatic
  module Patches
    module SchemaValidatorPatch
      # This method replaces validate_recursive in AvroPatches::LogicalTypes::SchemaValidatorPatch
      # to enable validating datums that contain an encoding provider.
      def validate_recursive(expected_schema, logical_datum, path, result, encoded = false)
        datum = resolve_datum(expected_schema, logical_datum, encoded)
        case expected_schema.type_sym
        when :record, :error, :request
          if datum.is_a?(Hash) && datum.key?(Avromatic::IO::ENCODING_PROVIDER)
            return if expected_schema.sha256_resolution_fingerprint ==
              datum[Avromatic::IO::ENCODING_PROVIDER].value_avro_schema.sha256_resolution_fingerprint
            raise Avro::SchemaValidator::ValidationError
          end
        end
        super(expected_schema, logical_datum, path, result, encoded)
      end
    end

    module SchemaValidatorPatchV040
      # This method replaces validate_recursive in AvroPatches::LogicalTypes::SchemaValidatorPatch
      # to enable validating datums that contain an encoding provider.
      def validate_recursive(expected_schema, logical_datum, path, result, options = {})
        datum = resolve_datum(expected_schema, logical_datum, options[:encoded])
        case expected_schema.type_sym
        when :record, :error, :request
          if datum.is_a?(Hash) && datum.key?(Avromatic::IO::ENCODING_PROVIDER)
            return if expected_schema.sha256_resolution_fingerprint ==
              datum[Avromatic::IO::ENCODING_PROVIDER].value_avro_schema.sha256_resolution_fingerprint
            raise Avro::SchemaValidator::ValidationError
          end
        end
        super(expected_schema, logical_datum, path, result, options)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
avromatic-1.0.0 lib/avromatic/patches/schema_validator_patch.rb
avromatic-0.33.0 lib/avromatic/patches/schema_validator_patch.rb