Class: Labkit::JsonSchema::RefResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/labkit/json_schema/ref_resolver.rb

Overview

This class resolves JSON schema references (e.g., “$ref”: “example.com/schema.json”) by fetching remote schemas over HTTP/HTTPS and caching them. It is used by JSONSchemer to resolve external schema definitions. We need it to validate JSON data against schemas that might be hosted remotely.

Instance Method Summary collapse

Constructor Details

#initialize(timeout_s: 2) ⇒ RefResolver

Returns a new instance of RefResolver.



17
18
19
# File 'lib/labkit/json_schema/ref_resolver.rb', line 17

def initialize(timeout_s: 2)
  @timeout_s = timeout_s
end

Instance Method Details

#call(uri) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/labkit/json_schema/ref_resolver.rb', line 21

def call(uri)
  uri_str = uri.to_s

  return cache[uri_str] if cache.key?(uri_str)

  cache[uri_str] = fetch_remote_schema(uri_str)
end