Skip to content

Commit

Permalink
Merge remote-tracking branches 'origin/jsi' and 'origin/misc' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Jan 29, 2022
2 parents e63684a + 64b2b80 commit c4fba22
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/scorpio/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ module V2
end

begin
# the autoloads for OpenAPI::Operation and OpenAPI::Document
# should not be triggered until all the classes their files reference are defined (above)
# the autoloads for OpenAPI::Operation and OpenAPI::Document are triggered below. these
# should not be triggered until all the classes their files reference are defined (above).
end # (this block is here just so the above informative comment is not interpreted as module doc)

module V3
Expand Down
2 changes: 1 addition & 1 deletion lib/scorpio/openapi/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def base_url(scheme: self.scheme, server: nil, server_variables: nil)
scheme: scheme,
host: host,
path: basePath,
).to_s
)
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/scorpio/openapi/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def oa_response(status: )

# this method is not intended to be API-stable at the moment.
#
# @api private
# @return [#to_ary<#to_h>] the parameters specified for this operation, plus any others
# scorpio considers to be parameters
def inferred_parameters
Expand Down Expand Up @@ -136,7 +137,7 @@ def request_accessor_module
instance_method_modules = [Request, Request::Configurables]
instance_method_names = instance_method_modules.map do |mod|
(mod.instance_methods + mod.private_instance_methods).map(&:to_s)
end.inject(Set.new, &:|)
end.inject(Set.new, &:merge)
params_by_name.each do |name, params|
next if instance_method_names.include?(name)
if params.size == 1
Expand Down
17 changes: 8 additions & 9 deletions lib/scorpio/openapi/operations_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ module OpenAPI
# OperationsScope acts as an Enumerable of the Operations for an openapi_document,
# and offers subscripting by operationId.
class OperationsScope
include JSI::Util::Memoize

# @param openapi_document [Scorpio::OpenAPI::Document]
def initialize(openapi_document)
jsi_initialize_memos
@openapi_document = openapi_document
@operations_by_id = Hash.new do |h, operationId|
op = detect { |operation| operation.operationId == operationId }
unless op
raise(::KeyError, "operationId not found: #{operationId.inspect}")
end
op
end
end
attr_reader :openapi_document

Expand All @@ -28,13 +33,7 @@ def each
# @return [Scorpio::OpenAPI::Operation] the operation with the given operationId
# @raise [::KeyError] if the given operationId does not exist
def [](operationId)
jsi_memoize(:[], operationId) do |operationId_|
detect { |operation| operation.operationId == operationId_ }.tap do |op|
unless op
raise(::KeyError, "operationId not found: #{operationId_.inspect}")
end
end
end
@operations_by_id[operationId]
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/scorpio/openapi/reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Reference
# overrides JSI::Base#[] to implicitly dereference this Reference, except when
# the given token is present in this Reference's instance (this should usually
# only apply to the token '$ref')
#
# see JSI::Base#initialize documentation at https://www.rubydoc.info/gems/jsi/JSI/Base
def [](token, *a, &b)
if respond_to?(:to_hash) && !key?(token)
deref do |deref_jsi|
Expand Down
10 changes: 5 additions & 5 deletions lib/scorpio/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def initialize(operation, configuration = {}, &b)
# do the Configurables first
configuration.each do |name, value|
if Configurables.public_method_defined?("#{name}=")
Configurables.instance_method("#{name}=").bind(self).call(value)
Configurables.instance_method("#{name}=").bind_call(self, value)
params_set << name
end
end
Expand Down Expand Up @@ -174,11 +174,11 @@ def path
"which were empty: #{empty_variables.inspect}")
end

path_template.expand(path_params).tap do |path|
if query_params
path.query_values = query_params
end
path = path_template.expand(path_params)
if query_params
path.query_values = query_params
end
path
end

# @return [Addressable::URI] the full URL for this request
Expand Down
4 changes: 2 additions & 2 deletions lib/scorpio/resource_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def update_dynamic_methods
end

def all_schema_properties
represented_schemas.map(&:described_object_property_names).inject(Set.new, &:|)
represented_schemas.map(&:described_object_property_names).inject(Set.new, &:merge)
end

def update_instance_accessors
Expand Down Expand Up @@ -195,7 +195,7 @@ def operation_for_resource_instance?(operation)
# should we define an instance method?
#request_attributes |= method_desc['parameters'] ? method_desc['parameters'].keys : []

schema_attributes = represented_schemas.map(&:described_object_property_names).inject(Set.new, &:|)
schema_attributes = represented_schemas.map(&:described_object_property_names).inject(Set.new, &:merge)

return request_resource_is_self || (request_attributes & schema_attributes.to_a).any?
end
Expand Down
8 changes: 3 additions & 5 deletions test/blog_scorpio_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# this is a virtual model to parent models representing resources of the blog. it sets
# up connection information including base url, custom middleware or adapter for faraday.
# it describes the API by setting the API document, but this class itself represents no
# resources - it sets no resource_name and defines no schema_keys.
# resources - it sets no tag_name and defines no represented_schemas.
class BlogModel < Scorpio::ResourceBase
define_inheritable_accessor(:logger)
logpath = Pathname.new('log/test.log')
Expand All @@ -22,7 +22,7 @@ class BlogModel < Scorpio::ResourceBase
self.server_variables = {
'scheme' => 'http',
'host' => 'localhost',
'port' => $blog_port || raise(Bug, '$blog_port is nil'),
'port' => $blog_port || raise('$blog_port is nil'),
}
else
abort("bad SCORPIO_API_DESCRIPTION_FORMAT")
Expand All @@ -32,9 +32,7 @@ class BlogModel < Scorpio::ResourceBase
}
end

# this is a model of Article, a resource of the blog API. it sets the resource_name
# to the key of the 'resources' section of the API (described by the api document
# specified to BlogModel)
# this model, Article, is a resource of the blog API.
class Article < BlogModel
self.tag_name = 'articles'
if openapi_document.v2?
Expand Down

0 comments on commit c4fba22

Please sign in to comment.