Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/json_skooma/keywords/core/ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@ class Ref < Base
self.key = "$ref"

def resolve
add_remote_source if need_to_adding?
@ref_schema = parent_schema.resolve_ref(json)
end

def evaluate(instance, result)
@ref_schema.evaluate(instance, result)
result.ref_schema = @ref_schema
end

def add_remote_source
parent_schema.registry.add_source(
pathname.dirname.to_s + "/",
JSONSkooma::Sources::Remote.new(json)
)
end

def need_to_adding?
json.start_with?("http") &&
parent_schema.registry.instance_variable_get("@uri_sources").keys.none?{ |k| json.include?(k) }
end

def pathname
Pathname.new(json)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/json_skooma/sources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Remote < Base
def read(relative_path)
path = suffix ? relative_path + suffix : relative_path
url = URI.join(base, path)
URI.parse(url).open.read
url.open.read
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave only this fix

rescue OpenURI::HTTPError, SocketError
raise Error, "Could not fetch #{url}"
end
Expand Down