Class: JSON::Schema::OneOfAttribute
- Defined in:
- lib/json-schema/attributes/oneof.rb
Class Method Summary collapse
Methods inherited from Attribute
build_fragment, validation_error, validation_errors
Class Method Details
.validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/json-schema/attributes/oneof.rb', line 4 def self.validate(current_schema, data, fragments, processor, validator, = {}) 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,) if matched valid = false else matched = true valid = true end rescue ValidationError end end if !valid if matched = "The property '#{build_fragment(fragments)}' of type #{data.class} matched more than one of the required schemas" else = "The property '#{build_fragment(fragments)}' of type #{data.class} did not match any of the required schemas" end validation_error(processor, , fragments, current_schema, self, [:record_errors]) end end |