Method: JSON::Validator#validate
- Defined in:
- lib/json-schema/validator.rb
#validate(data) ⇒ Object
Run a simple true/false validation of data against a schema
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/json-schema/validator.rb', line 137 def validate(data) original_data = data data = initialize_data(data) error_recorder = with_errors @base_schema.validate(data, [], error_recorder, @validation_options) if @options[:record_errors] if @options[:errors_as_objects] error_recorder.validation_errors.map { |e| e.to_hash } else error_recorder.validation_errors.map { |e| e.to_string } end else true end ensure if @validation_options[:clear_cache] == true self.class.clear_cache end if @validation_options[:insert_defaults] self.class.merge_missing_values(data, original_data) end end |