Sha256: d3b2b5599f5684dacbb029ac6232d30ae6ac9b4ffeab3a1952fbe23f263afc57

Contents?: true

Size: 782 Bytes

Versions: 3

Compression:

Stored size: 782 Bytes

Contents

module AvroPatches
  module DefaultValidation
    module FieldPatch
      def initialize(type, name, default=:no_default, order=nil, names=nil, namespace=nil)
        super

        validate_default! if default?
      end

      private

      def validate_default!
        type_for_default = if type.type_sym == :union
                             type.schemas.first
                           else
                             type
                           end

        Avro::SchemaValidator.validate!(type_for_default, default)
      rescue Avro::SchemaValidator::ValidationError => e
        raise Avro::SchemaParseError, "Error validating default for #{name}: #{e.message}"
      end
    end
  end
end

Avro::Schema::Field.prepend(AvroPatches::DefaultValidation::FieldPatch)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
avro-patches-1.0.0.pre0 lib/avro-patches/default_validation/schema.rb
avro-patches-0.4.1 lib/avro-patches/default_validation/schema.rb
avro-patches-0.4.0 lib/avro-patches/default_validation/schema.rb