Sha256: 156f3362acd9d85d78a64f91b15257e390191963054f0663687382db6bebb8c8

Contents?: true

Size: 897 Bytes

Versions: 3

Compression:

Stored size: 897 Bytes

Contents

require 'json-schema/attribute'

module JSON
  class Schema
    class EnumAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        if !current_schema.schema['enum'].include?(data)
          message = "The property '#{build_fragment(fragments)}' value #{data.inspect} did not match one of the following values:"
          current_schema.schema['enum'].each {|val|
            if val.is_a?(NilClass)
              message += " null,"
            elsif val.is_a?(Array)
              message += " (array),"
            elsif val.is_a?(Hash)
              message += " (object),"
            else
              message += " #{val.to_s},"
            end
          }
          message.chop!
          validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json-schema-2.4.1 lib/json-schema/attributes/enum.rb
json-schema-2.4.0 lib/json-schema/attributes/enum.rb
json-schema-2.3.0 lib/json-schema/attributes/enum.rb