Class: JSON::Schema::ExtendsAttribute
- Defined in:
- lib/json-schema/attributes/extends.rb
Constant Summary
Constants inherited from Attribute
Attribute::TYPE_CLASS_MAPPINGS
Class Method Summary collapse
- .get_extended_uri_and_schema(s, current_schema, validator) ⇒ Object
- .validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
Methods inherited from Attribute
build_fragment, data_valid_for_type?, type_of_data, validation_error, validation_errors
Class Method Details
.get_extended_uri_and_schema(s, current_schema, validator) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/json-schema/attributes/extends.rb', line 24 def self.get_extended_uri_and_schema(s, current_schema, validator) uri,schema = nil,nil if s.is_a?(Hash) uri = current_schema.uri if s['$ref'] ref_uri,ref_schema = JSON::Schema::RefAttribute.get_referenced_uri_and_schema(s, current_schema, validator) if ref_schema if s.size == 1 # Check if anything else apart from $ref uri,schema = ref_uri,ref_schema else s = s.dup s.delete '$ref' s = ref_schema.schema.merge(s) end end end schema ||= JSON::Schema.new(s,uri,validator) end [uri,schema] end |
.validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/json-schema/attributes/extends.rb', line 7 def self.validate(current_schema, data, fragments, processor, validator, = {}) schemas = current_schema.schema['extends'] schemas = [schemas] if !schemas.is_a?(Array) schemas.each do |s| uri,schema = get_extended_uri_and_schema(s, current_schema, validator) if schema schema.validate(data, fragments, processor, ) elsif uri = "The extended schema '#{uri.to_s}' cannot be found" validation_error(processor, , fragments, current_schema, self, [:record_errors]) else = "The property '#{build_fragment(fragments)}' was not a valid schema" validation_error(processor, , fragments, current_schema, self, [:record_errors]) end end end |