Skip to content

Commit

Permalink
Merge 9570503 into 5a7158e
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Feb 12, 2021
2 parents 5a7158e + 9570503 commit ccca549
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ gem 'byebug'
gem 'coveralls_reborn', '~> 0.11'
gem 'wwtd'
gem 'ur', github: 'notEthan/ur', ref: 'fa495042596eb9cec4ff361bfb764f516174558a'
gem 'jsi', github: 'notEthan/jsi', ref: '9b4bd0f15f2fe8c2135ffa78a9e1af316300da3b'
gem 'jsi', github: 'notEthan/jsi', ref: '27a73cca8384b0386cac14ef41474869d971aac1'
1 change: 1 addition & 0 deletions lib/scorpio/openapi/operations_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class OperationsScope

# @param openapi_document [Scorpio::OpenAPI::Document]
def initialize(openapi_document)
jsi_initialize_memos
@openapi_document = openapi_document
end
attr_reader :openapi_document
Expand Down
22 changes: 22 additions & 0 deletions lib/scorpio/openapi/reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ def [](token, *a, &b)
end
return super
end

def deref
return unless respond_to?(:to_hash) && self['$ref'].respond_to?(:to_str)

ref_uri = Addressable::URI.parse(self['$ref'])
ref_uri_nofrag = ref_uri.merge(fragment: nil)

if !ref_uri_nofrag.empty? || ref_uri.fragment.nil?
raise(NotImplementedError,
"Scorpio currently only supports fragment URIs as OpenAPI references. cannot find reference by uri: #{self['$ref']}"
)
end

ptr = JSI::JSON::Pointer.from_fragment(ref_uri.fragment)
deref_jsi = ptr.evaluate(jsi_root_node)

# TODO type check deref_jsi

yield deref_jsi

nil
end
end
end
end

0 comments on commit ccca549

Please sign in to comment.