lib/json-schema/attributes/ref.rb in json-schema-3.0.0 vs lib/json-schema/attributes/ref.rb in json-schema-4.0.0

- old
+ new

@@ -4,11 +4,11 @@ module JSON class Schema class RefAttribute < Attribute def self.validate(current_schema, data, fragments, processor, validator, options = {}) - uri,schema = get_referenced_uri_and_schema(current_schema.schema, current_schema, validator) + uri, schema = get_referenced_uri_and_schema(current_schema.schema, current_schema, validator) if schema schema.validate(data, fragments, processor, options) elsif uri message = "The referenced schema '#{uri.to_s}' cannot be found" @@ -18,23 +18,23 @@ validation_error(processor, message, fragments, current_schema, self, options[:record_errors]) end end def self.get_referenced_uri_and_schema(s, current_schema, validator) - uri,schema = nil,nil + uri, schema = nil, nil temp_uri = JSON::Util::URI.normalize_ref(s['$ref'], current_schema.uri) # Grab the parent schema from the schema list - schema_key = temp_uri.to_s.split("#")[0] + "#" + schema_key = temp_uri.to_s.split('#')[0] + '#' ref_schema = JSON::Validator.schema_for_uri(schema_key) if ref_schema # Perform fragment resolution to retrieve the appropriate level for the schema target_schema = ref_schema.schema - fragments = JSON::Util::URI.parse(JSON::Util::URI.unescape_uri(temp_uri)).fragment.split("/") + fragments = JSON::Util::URI.parse(JSON::Util::URI.unescape_uri(temp_uri)).fragment.split('/') fragment_path = '' fragments.each do |fragment| if fragment && fragment != '' fragment = fragment.gsub('~0', '~').gsub('~1', '/') if target_schema.is_a?(Array) @@ -42,20 +42,20 @@ else target_schema = target_schema[fragment] end fragment_path = fragment_path + "/#{fragment}" if target_schema.nil? - raise SchemaError.new("The fragment '#{fragment_path}' does not exist on schema #{ref_schema.uri.to_s}") + raise SchemaError, "The fragment '#{fragment_path}' does not exist on schema #{ref_schema.uri.to_s}" end end end # We have the schema finally, build it and validate! uri = temp_uri - schema = JSON::Schema.new(target_schema,temp_uri,validator) + schema = JSON::Schema.new(target_schema, temp_uri, validator) end - [uri,schema] + [uri, schema] end end end end