scorpio 0.6.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f20e932b016747b1bfa5a3d45711d3b06c1362894bad9496fc002420f6b4678
4
- data.tar.gz: 96aa91530d7fb3e8b58b8c8002ea83faf9d7c10c3f660279e235a8cfccdf15b2
3
+ metadata.gz: 82437b6c802e013a8b001d837d74fc53df3a79a036308402baa958473282e2da
4
+ data.tar.gz: 5d27bec750c90aba761158e41e8a3396af9bf08a0ca1bb03ad6fe5d88f12b139
5
5
  SHA512:
6
- metadata.gz: 13858da58324b2648053d7c16c78ed1d5f4f5754a348d0ad442c2dd517fd13c9a6cdbb3f1295658795d9dae1ddd7eac7399028d9a1f087909c6b95de2d6a4ded
7
- data.tar.gz: 2ed8c1fd1a150fd00fdee372bf0ff98624458826986f67f28daa76a5db428efa346615afd1e5aa9aa2d085f3841dbb1e5ad26fe843368c89e1380d9e8371a5b4
6
+ metadata.gz: 077caed57f2e2d38c46f7b56f17328f732929404ba1bed3a6bead041cb6449dabe61b32ca7c1fc6bc0b30eac9c8c1b0a58ebf47f9aa74ff852595243213b3b2e
7
+ data.tar.gz: d995f27814a468e9652de92b5b7e4579a3ca0626798be1cf56b155a5bb83dcbf38e60158c225ecc55c455672fb1d5efb4327615725da5745e1cd5ef26802399b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v0.6.3
2
+
3
+ - JSI = v0.8.0
4
+
5
+ # v0.6.2
6
+ - replace deprecated calls to JSI
7
+
1
8
  # v0.6.1
2
9
  - compatibility
3
10
  - JSI 0.7
@@ -3,7 +3,7 @@
3
3
  module Scorpio
4
4
  module Google
5
5
  discovery_rest_description_doc = ::JSON.parse(Scorpio.root.join('documents/www.googleapis.com/discovery/v1/apis/discovery/v1/rest').read)
6
- discovery_rest_description = JSI::MetaschemaNode.new(
6
+ discovery_rest_description = JSI::MetaSchemaNode.new(
7
7
  discovery_rest_description_doc,
8
8
  metaschema_root_ptr: JSI::Ptr['schemas']['JsonSchema'],
9
9
  root_schema_ptr: JSI::Ptr['schemas']['RestDescription'],
@@ -29,13 +29,16 @@ module Scorpio
29
29
  # google does a weird thing where it defines a schema with a $ref property where a json-schema is to be used in the document (method request and response fields), instead of just setting the schema to be the json-schema schema. we'll share a module across those schema classes that really represent schemas. is this confusingly meta enough?
30
30
  module SchemaLike
31
31
  def to_openapi
32
- dup_doc = JSI::Typelike.as_json(self)
33
32
  # openapi does not want an id field on schemas
34
- dup_doc.delete('id')
33
+ dup_doc = jsi_node_content.reject { |k, _| k == 'id' }
35
34
  if dup_doc['properties'].is_a?(Hash)
36
- required_properties = dup_doc['properties'].select do |key, value|
37
- value.is_a?(Hash) ? value.delete('required') : nil
38
- end.keys
35
+ required_properties = []
36
+ dup_doc['properties'].each do |key, value|
37
+ if value.is_a?(Hash) && value.key?('required')
38
+ required_properties.push(key) if value['required']
39
+ dup_doc = dup_doc.merge({'properties' => value.reject { |vk, _| vk == 'required' }})
40
+ end
41
+ end
39
42
  # put required before properties
40
43
  unless required_properties.empty?
41
44
  dup_doc = dup_doc.map do |k, v|
@@ -55,8 +58,7 @@ module Scorpio
55
58
  end
56
59
 
57
60
  def to_openapi_hash(options = {})
58
- # we will be modifying the api document (RestDescription). clone self and modify that one.
59
- ad = self.class.new(JSI::Typelike.as_json(self))
61
+ ad = self
60
62
  ad_methods = []
61
63
  if ad['methods']
62
64
  ad_methods += ad['methods'].map do |mn, m|
@@ -164,7 +166,7 @@ module Scorpio
164
166
  #'url' => '',
165
167
  #},
166
168
  },
167
- 'host' => ad.rootUrl ? Addressable::URI.parse(ad.rootUrl).host : ad.baseUrl ? Addressable::URI.parse(ad.rootUrl).host : ad.name, # uhh ... got nothin' better
169
+ 'host' => ad.rootUrl ? Addressable::URI.parse(ad.rootUrl).host : ad.baseUrl ? Addressable::URI.parse(ad.baseUrl).host : ad.name, # uhh ... got nothin' better
168
170
  'basePath' => begin
169
171
  path = ad.servicePath || ad.basePath || (ad.baseUrl ? Addressable::URI.parse(ad.baseUrl).path : '/')
170
172
  path =~ %r(\A/) ? path : "/" + path
@@ -212,7 +214,7 @@ module Scorpio
212
214
  end.call(openapi)
213
215
  end
214
216
  end
215
- JSI::Typelike.as_json(openapi)
217
+ JSI::Util.as_json(openapi)
216
218
  end
217
219
  end
218
220
  end
@@ -165,22 +165,29 @@ module Scorpio
165
165
  # instantiates a {Scorpio::Request} for this operation.
166
166
  # parameters are all passed to {Scorpio::Request#initialize}.
167
167
  # @return [Scorpio::Request]
168
- def build_request(*a, &b)
169
- Scorpio::Request.new(self, *a, &b)
168
+ def build_request(**config, &b)
169
+ @request_class ||= Scorpio::Request.request_class_by_operation(self)
170
+ @request_class.new(**config, &b)
170
171
  end
171
172
 
172
173
  # runs a {Scorpio::Request} for this operation, returning a {Scorpio::Ur}.
173
174
  # parameters are all passed to {Scorpio::Request#initialize}.
174
175
  # @return [Scorpio::Ur] response ur
175
- def run_ur(*a, &b)
176
- build_request(*a, &b).run_ur
176
+ def run_ur(**config, &b)
177
+ build_request(**config, &b).run_ur
177
178
  end
178
179
 
179
180
  # runs a {Scorpio::Request} for this operation - see {Scorpio::Request#run}.
180
181
  # parameters are all passed to {Scorpio::Request#initialize}.
181
182
  # @return response body object
182
- def run(*a, &b)
183
- build_request(*a, &b).run
183
+ def run(**config, &b)
184
+ build_request(**config, &b).run
185
+ end
186
+
187
+ private
188
+
189
+ def jsi_object_group_text
190
+ [*super, http_method, path_template_str].freeze
184
191
  end
185
192
  end
186
193
 
@@ -6,10 +6,10 @@ module Scorpio
6
6
  # overrides JSI::Base#[] to implicitly dereference this Reference, except when
7
7
  # the given token is present in this Reference's instance (this should usually
8
8
  # only apply to the token '$ref')
9
- def [](token, *a, &b)
9
+ def [](token, **kw)
10
10
  if respond_to?(:to_hash) && !key?(token)
11
11
  deref do |deref_jsi|
12
- return deref_jsi[token]
12
+ return(deref_jsi[token, **kw])
13
13
  end
14
14
  end
15
15
  return super
@@ -25,8 +25,8 @@ module Scorpio
25
25
  'documents/github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0/schema.yaml'
26
26
  )))
27
27
 
28
- # the schema represented by Scorpio::OpenAPI::V3::Schema will describe schemas itself, so we set it
29
- # include on its schema module the jsi_schema_instance_modules that implement schema functionality.
28
+ # the schema represented by Scorpio::OpenAPI::V3::Schema will describe schemas itself.
29
+ # JSI::Schema#describes_schema! enables this to implement the functionality of schemas.
30
30
  describe_schema = [
31
31
  openapi_document_schema.definitions['Schema'],
32
32
  openapi_document_schema.definitions['SchemaReference'],
@@ -40,7 +40,7 @@ module Scorpio
40
40
  # a problem, and this way also applies when none of the anyOf match due to schema errors.)
41
41
  openapi_document_schema.definitions['Schema'].properties['additionalProperties'],
42
42
  ]
43
- describe_schema.each { |s| s.jsi_schema_instance_modules = [JSI::Schema::Draft04] }
43
+ describe_schema.each { |s| s.describes_schema!([JSI::Schema::Draft04]) }
44
44
 
45
45
  Document = openapi_document_schema.jsi_schema_module
46
46
 
@@ -118,14 +118,14 @@ module Scorpio
118
118
  'documents/swagger.io/v2/schema.json'
119
119
  ).read))
120
120
 
121
- # the schema represented by Scorpio::OpenAPI::V2::Schema will describe schemas itself, so we set it to
122
- # include on its schema module the jsi_schema_instance_modules that implement schema functionality.
121
+ # the schema represented by Scorpio::OpenAPI::V2::Schema will describe schemas itself.
122
+ # JSI::Schema#describes_schema! enables this to implement the functionality of schemas.
123
123
  describe_schema = [
124
124
  openapi_document_schema.definitions['schema'],
125
125
  # comments above on v3's definitions['Schema'].properties['additionalProperties'] apply here too
126
126
  openapi_document_schema.definitions['schema'].properties['additionalProperties'],
127
127
  ]
128
- describe_schema.each { |s| s.jsi_schema_instance_modules = [JSI::Schema::Draft04] }
128
+ describe_schema.each { |s| s.describes_schema!([JSI::Schema::Draft04]) }
129
129
 
130
130
  Document = openapi_document_schema.jsi_schema_module
131
131
 
@@ -71,7 +71,7 @@ module Scorpio
71
71
  return @body if instance_variable_defined?(:@body)
72
72
  if instance_variable_defined?(:@body_object)
73
73
  if content_type && content_type.json?
74
- JSON.pretty_generate(JSI::Typelike.as_json(body_object))
74
+ JSON.pretty_generate(JSI::Util.as_json(body_object))
75
75
  elsif content_type && content_type.form_urlencoded?
76
76
  URI.encode_www_form(body_object)
77
77
 
@@ -129,13 +129,21 @@ module Scorpio
129
129
  end
130
130
  include Configurables
131
131
 
132
- # @param operation [Scorpio::OpenAPI::Operation]
132
+ @request_class_by_operation = Hash.new do |h, op|
133
+ h[op] = Class.new(Request) do
134
+ define_method(:operation) { op }
135
+ include(op.request_accessor_module)
136
+ end
137
+ end
138
+
139
+ def self.request_class_by_operation(operation)
140
+ @request_class_by_operation[operation]
141
+ end
142
+
133
143
  # @param configuration [#to_hash] a hash keyed with configurable attributes for
134
144
  # the request - instance methods of Scorpio::Request::Configurables, whose values
135
145
  # will be assigned for those attributes.
136
- def initialize(operation, configuration = {}, &b)
137
- @operation = operation
138
-
146
+ def initialize(configuration = {}, &b)
139
147
  configuration = JSI::Util.stringify_symbol_keys(configuration)
140
148
  params_set = Set.new # the set of params that have been set
141
149
  # do the Configurables first
@@ -151,8 +159,6 @@ module Scorpio
151
159
  set_param_from(param['in'], param['name'], value)
152
160
  end
153
161
 
154
- extend operation.request_accessor_module
155
-
156
162
  if block_given?
157
163
  yield self
158
164
  end
@@ -324,7 +324,7 @@ module Scorpio
324
324
  else
325
325
  jsi = operation.request_schema.new_jsi(o)
326
326
  end
327
- jsi.jsi_select_children_leaf_first do |node|
327
+ jsi.jsi_select_descendents_leaf_first do |node|
328
328
  # we want to specifically reject only nodes described (only) by a false schema.
329
329
  # note that for OpenAPI schemas, false is only a valid schema as a value
330
330
  # of `additionalProperties`
@@ -418,7 +418,7 @@ module Scorpio
418
418
  end
419
419
 
420
420
  def as_json(*opt)
421
- JSI::Typelike.as_json(contained_object, *opt)
421
+ JSI::Util.as_json(contained_object, *opt)
422
422
  end
423
423
 
424
424
  def inspect
@@ -439,7 +439,7 @@ module Scorpio
439
439
  end
440
440
  end
441
441
 
442
- include JSI::Util::FingerprintHash
442
+ include(JSI::Util::Private::FingerprintHash)
443
443
 
444
444
  def jsi_fingerprint
445
445
  {class: self.class, contained_object: as_json}
@@ -497,39 +497,92 @@ module Scorpio
497
497
 
498
498
  class ResourceBase
499
499
  class Container
500
- @container_classes = Hash.new do |h, modules|
501
- container_class = Class.new(Container)
502
- modules.each do |mod|
503
- container_class.include(mod)
500
+ @container_classes = Hash.new do |h, key|
501
+ modules, schemas = key[:modules], key[:schemas]
502
+
503
+ container_class = Class.new(Container) do
504
+ modules.each do |mod|
505
+ include(mod)
506
+ end
507
+
508
+ schemas.each do |schema|
509
+ include(JSI::SchemaClasses.schema_property_reader_module(schema, conflicting_modules: modules + [Container]))
510
+ include(JSI::SchemaClasses.schema_property_writer_module(schema, conflicting_modules: modules + [Container]))
511
+ end
504
512
  end
505
- h[modules] = container_class
513
+ h[key] = container_class
506
514
  end
507
515
 
508
516
  class << self
509
517
  def new_container(object, openapi_document_class, options = {})
510
518
  container_modules = Set[]
511
519
 
512
- # TODO this is JSI internals that scorpio shouldn't really be using
513
520
  if object.respond_to?(:to_hash)
514
- container_modules << JSI::Base::HashNode
521
+ container_modules << Container::Hash
515
522
  end
516
523
  if object.respond_to?(:to_ary)
517
- container_modules << JSI::Base::ArrayNode
524
+ container_modules << Container::Array
518
525
  end
519
526
 
520
- container_modules += object.jsi_schemas.map do |schema|
521
- JSI::SchemaClasses.accessor_module_for_schema(schema,
522
- conflicting_modules: container_modules + [Container],
523
- )
524
- end
525
-
526
- container_class = @container_classes[container_modules.freeze]
527
+ container_class = @container_classes[{modules: container_modules.freeze, schemas: object.jsi_schemas}]
527
528
 
528
529
  container_class.new(object, openapi_document_class, options)
529
530
  end
530
531
  end
531
532
  end
532
533
 
534
+ module Container::Hash
535
+ include(Enumerable)
536
+ include(JSI::Util::Hashlike) # TODO this is JSI internals that scorpio shouldn't really be using
537
+
538
+ def each(**kw, &block)
539
+ return(to_enum(__method__, **kw) { contained_object.size }) unless block
540
+ if block.arity > 1
541
+ contained_object.each_key { |k| yield(k, self[k, **kw]) }
542
+ else
543
+ contained_object.each_key { |k| yield([k, self[k, **kw]]) }
544
+ end
545
+ self
546
+ end
547
+
548
+ def to_hash(**kw)
549
+ hash = {}
550
+ contained_object.each_key { |k| hash[k] = self[k, **kw] }
551
+ hash
552
+ end
553
+
554
+ def as_json(options = {})
555
+ hash = {}
556
+ each_key do |k|
557
+ ks = k.is_a?(String) ? k :
558
+ k.is_a?(Symbol) ? k.to_s :
559
+ k.respond_to?(:to_str) && (kstr = k.to_str).is_a?(String) ? kstr :
560
+ raise(TypeError, "JSON object (Hash) cannot be keyed with: #{k.pretty_inspect.chomp}")
561
+ hash[ks] = JSI::Util.as_json(self[k], **options)
562
+ end
563
+ hash
564
+ end
565
+ end
566
+
567
+ module Container::Array
568
+ include(Enumerable)
569
+ include(JSI::Util::Arraylike) # TODO this is JSI internals that scorpio shouldn't really be using
570
+
571
+ def each(**kw, &block)
572
+ return(to_enum(__method__, **kw) { contained_object.size }) unless block
573
+ contained_object.each_index { |i| yield(self[i, **kw]) }
574
+ self
575
+ end
576
+
577
+ def to_ary(**kw)
578
+ to_a(**kw)
579
+ end
580
+
581
+ def as_json(options = {})
582
+ each_index.map { |i| JSI::Util.as_json(self[i], **options) }
583
+ end
584
+ end
585
+
533
586
  class Container
534
587
  include Containment
535
588
 
@@ -26,7 +26,7 @@ module Scorpio
26
26
  end
27
27
 
28
28
  if response_schema && (body_object.respond_to?(:to_hash) || body_object.respond_to?(:to_ary))
29
- body_object = response_schema.new_jsi(body_object)
29
+ body_object = response_schema.new_jsi(body_object, mutable: true)
30
30
  end
31
31
 
32
32
  body_object
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scorpio
4
- VERSION = "0.6.1".freeze
4
+ VERSION = "0.6.3".freeze
5
5
  end
data/scorpio.gemspec CHANGED
@@ -1,7 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'scorpio/version'
1
+ require_relative('lib/scorpio/version')
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = "scorpio"
@@ -26,8 +23,8 @@ Gem::Specification.new do |spec|
26
23
 
27
24
  spec.require_paths = ["lib"]
28
25
 
29
- spec.add_dependency "jsi", "~> 0.7.0"
30
- spec.add_dependency "ur", "~> 0.2.1"
26
+ spec.add_dependency "jsi", "= 0.8.0"
27
+ spec.add_dependency "ur", "~> 0.2.4"
31
28
  spec.add_dependency "faraday", "< 3.0"
32
29
  spec.add_dependency "addressable", '~> 2.3'
33
30
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-12 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.0
19
+ version: 0.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.0
26
+ version: 0.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ur
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.1
33
+ version: 0.2.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.1
40
+ version: 0.2.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.1.6
120
+ rubygems_version: 3.4.10
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Scorpio REST client