lib/avro/schema.rb in avro-1.11.1 vs lib/avro/schema.rb in avro-1.11.2

- old
+ new

@@ -124,10 +124,11 @@ end def initialize(type, logical_type=nil) @type_sym = type.is_a?(Symbol) ? type : type.to_sym @logical_type = logical_type + @type_adapter = nil end attr_reader :type_sym attr_reader :logical_type @@ -569,10 +570,11 @@ @name = name @default = default @order = order @doc = doc @aliases = aliases + @type_adapter = nil validate_aliases! if aliases validate_default! if default? && !Avro.disable_field_default_validation end def default? @@ -597,11 +599,19 @@ type_for_default = if type.type_sym == :union type.schemas.first else type end - - Avro::SchemaValidator.validate!(type_for_default, default) + case type_for_default.logical_type + when DECIMAL_LOGICAL_TYPE + # https://avro.apache.org/docs/1.11.1/specification/#schema-record + # Default values for bytes and fixed fields are JSON strings, where Unicode code points 0-255 are mapped to unsigned 8-bit byte values 0-255 + options = SchemaValidator::DEFAULT_VALIDATION_OPTIONS.dup + options[:encoded] = true + Avro::SchemaValidator.validate!(type_for_default, default, options) + else + Avro::SchemaValidator.validate!(type_for_default, default) + end rescue Avro::SchemaValidator::ValidationError => e raise Avro::SchemaParseError, "Error validating default for #{name}: #{e.message}" end end end