Sha256: 0e041d7c0d9d07eafbba1265b318d463a15512c589b173e67a683b2a749abe19

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module JSON
  class Schema
    class OneOfAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        matched = false
        valid = false

        current_schema.schema['oneOf'].each do |element|
          schema = JSON::Schema.new(element,current_schema.uri,validator)

          begin
            schema.validate(data,fragments,processor,options)
            if matched
              valid = false
            else
              matched = true
              valid = true
            end
          rescue ValidationError
          end

        end

        if !valid
          if matched
            message = "The property '#{build_fragment(fragments)}' of type #{data.class} matched more than one of the required schemas"
          else
            message = "The property '#{build_fragment(fragments)}' of type #{data.class} did not match any of the required schemas"
          end
          validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
json-schema-2.1.3 lib/json-schema/attributes/oneof.rb
json-schema-2.1.2 lib/json-schema/attributes/oneof.rb
json-schema-2.1.1 lib/json-schema/attributes/oneof.rb
json-schema-2.1.0 lib/json-schema/attributes/oneof.rb
json-schema-2.0.5 lib/json-schema/attributes/oneof.rb
json-schema-2.0.4 lib/json-schema/attributes/oneof.rb
json-schema-2.0.3 lib/json-schema/attributes/oneof.rb
json-schema-2.0.2 lib/json-schema/attributes/oneof.rb
json-schema-2.0.1 lib/json-schema/attributes/oneof.rb
json-schema-2.0.0 lib/json-schema/attributes/oneof.rb