Class: IfMissingAttribute
- Inherits:
-
JSON::Schema::PropertiesAttribute
- Object
- JSON::Schema::PropertiesAttribute
- IfMissingAttribute
- Defined in:
- common/archivesspace_json_schema.rb
Overview
Add a new ‘ifmissing’ attribute which emits either an error or warning depending on its value.
Class Method Summary collapse
Class Method Details
.validate(current_schema, data, fragments, validator, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'common/archivesspace_json_schema.rb', line 7 def self.validate(current_schema, data, fragments, validator, = {}) super if data.is_a?(Hash) current_schema.schema['properties'].each do |property, property_schema| if (property_schema['ifmissing'] && !data.has_key?(property)) = nil if property_schema['ifmissing'] == 'error' = "ERROR: The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'" elsif property_schema['ifmissing'] == 'warn' = "WARNING: The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'" end if validation_error(, fragments, current_schema, self, [:record_errors]) end end end end end |