Class: OpenAPI::Loader::Ref
- Inherits:
-
String
- Object
- String
- OpenAPI::Loader::Ref
- Defined in:
- lib/open_api/loader/ref.rb
Overview
Describes json pointer used in “$ref”-erences
Class Method Summary collapse
-
.[](*path) ⇒ OpenAPI::Ref
Builds the pointer from a path.
Instance Method Summary collapse
-
#fetch_from(data) ⇒ Object
Extracs referred value from given source by local path (after #).
-
#path ⇒ Array<String>
The local pointer to the json.
-
#uri ⇒ URI?
The URI to the remote document.
Class Method Details
.[](*path) ⇒ OpenAPI::Ref
Builds the pointer from a path
15 16 17 18 19 |
# File 'lib/open_api/loader/ref.rb', line 15 def self.[](*path) path.flatten.compact.each_with_object("#") do |key, obj| obj << "/#{key.to_s.gsub('~', '~0').gsub('/', '~1')}" end end |
Instance Method Details
#fetch_from(data) ⇒ Object
Extracs referred value from given source by local path (after #)
46 47 48 |
# File 'lib/open_api/loader/ref.rb', line 46 def fetch_from(data) read(data, [], *path) end |
#path ⇒ Array<String>
The local pointer to the json
33 34 35 36 37 38 |
# File 'lib/open_api/loader/ref.rb', line 33 def path return [] if end_with? "#" split(%r{#/?}).last.to_s.split("/").map do |item| PARSER.unescape(item).gsub("~1", "/").gsub("~0", "~") end end |
#uri ⇒ URI?
The URI to the remote document
25 26 27 |
# File 'lib/open_api/loader/ref.rb', line 25 def uri URI split("#").first unless start_with? "#" end |