scorpio 0.4.1 → 0.4.2

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: 603bcc3914e849b35e8c4519682588fc7f56dda8d52c188fde80eef20bf7b34f
4
- data.tar.gz: aecb035dd48a48c8f97e7ca60ffb560abde598385db4cbaf4d0444226708a7ef
3
+ metadata.gz: 510fd6b2b4dc5e78a4d11c08dcb7fc53901b308a4eef0b53d3d7317aabdd265f
4
+ data.tar.gz: d2c92b80c26f24f5f98540c456b2177d74bc13e5a2e5f461a531525631afff96
5
5
  SHA512:
6
- metadata.gz: e462291e8caca9542c8de14c81402be9bb004571c93d2af7ce92d842ee22861df92a10e9be941149950d017d7751d41e70d6ada8bb17fb2822c0ba85a0a8cbd9
7
- data.tar.gz: 6cc6ebc90878d29cc2861c7c48e2231cd5554b7ed569efcbe529295275969d772f9bb1c328039d539ef4e579489f37269ae2003bd6a2d15da90645548cedafe9
6
+ metadata.gz: 52561bf683728001d750987ae8eb8df5356b75db3c0e1b734182a3af69227c4db6e4699d94b1a8f820802b5c5d804c9d73eebf49ea05991c309ef6b20d9ce8ff
7
+ data.tar.gz: 8144a386a93d397193ea952965d3de6bf398739a4b2c20a2e8dfcbd716f9721a3eae9949f5714695ce83e338353c8152954e1bee130af198973a41f7edb9e854
@@ -1,3 +1,7 @@
1
+ # v0.4.2
2
+ - improve documentation
3
+ - misc bugfixes
4
+
1
5
  # v0.4.1
2
6
  - Request#param_for
3
7
  - Operation#human_id
data/README.md CHANGED
@@ -9,7 +9,7 @@ Note: The canonical location of this README is on [RubyDoc](http://rubydoc.info/
9
9
 
10
10
  ## Background
11
11
 
12
- To start with, you need an OpenAPI (formerly known as Swagger) document describing a service you will be consuming. v2 and v3 are both supported[^1]. This document can be written by hand or sometimes generated from other existing sources. The creation of an OpenAPI document specifying your service is outside the scope of Scorpio. Here are several resources on OpenAPI:
12
+ To start with, you need an OpenAPI (formerly known as Swagger) document describing a service you will be consuming. v2 and v3 are both supported.[^1] This document can be written by hand or sometimes generated from other existing sources. The creation of an OpenAPI document specifying your service is outside the scope of Scorpio. Here are several resources on OpenAPI:
13
13
 
14
14
  - [OpenAPI Specification at Wikipedia](https://en.wikipedia.org/wiki/OpenAPI_Specification)
15
15
  - [OpenAPI Initiative](https://www.openapis.org/) is the official web site for OpenAPI
@@ -24,7 +24,7 @@ Once you have the OpenAPI document describing the service you will consume, you
24
24
 
25
25
  ## Pet Store (using Scorpio::ResourceBase)
26
26
 
27
- Let's dive into some code, shall we? If you have learned about OpenAPI, you likely learned using the example of the Pet Store service. This README will use the same service. Its documentation is at http://petstore.swagger.io/ and its OpenAPI 2 specification is at http://petstore.swagger.io/v2/swagger.json (yaml version: http://petstore.swagger.io/v2/swagger.yaml )
27
+ Let's dive into some code, shall we? If you have learned about OpenAPI, you likely learned using the example of the Pet Store service. This README will use the same service. Its documentation is at http://petstore.swagger.io/.
28
28
 
29
29
  Using the specification, we can start interacting with the pet store with very little code. Here is that code, with explanations of each part in the comments.
30
30
 
@@ -71,31 +71,29 @@ That should be all you need to start calling operations:
71
71
  sold_pets = PetStore::Pet.findPetsByStatus(status: 'sold')
72
72
  # sold_pets is an array-like collection of PetStore::Pet instances
73
73
 
74
- # compare to getPetById: http://petstore.swagger.io/#/pet/getPetById
75
- pet1 = sold_pets.last
76
- pet2 = PetStore::Pet.getPetById(petId: pet1['id'])
77
- # pet2 is the same pet as pet1, retrieved using the getPetById operation
78
-
79
- pet1 == pet2
80
- # should return true. they are the same pet.
74
+ pet = sold_pets.sample
81
75
 
82
- pet1.tags.map(&:name)
76
+ pet.tags.map(&:name)
83
77
  # note that you have accessors on PetStore::Pet like #tags, and also that
84
78
  # tags have accessors for properties 'name' and 'id' from the tags schema
85
79
  # (your tag names will be different depending on what's in the pet store)
86
80
  # => ["aucune"]
87
81
 
82
+ # compare to getPetById: http://petstore.swagger.io/#/pet/getPetById
83
+ pet == PetStore::Pet.getPetById(petId: pet['id'])
84
+ # pet is the same, retrieved using the getPetById operation
85
+
88
86
  # let's name the pet after ourself
89
- pet1.name = ENV['USER']
87
+ pet.name = ENV['USER']
90
88
 
91
89
  # store the result in the pet store. note the updatePet call from the instance - our
92
90
  # calls so far have been on the class PetStore::Pet, but scorpio defines instance
93
91
  # methods to call operations where appropriate as well.
94
92
  # updatePet: http://petstore.swagger.io/#/pet/updatePet
95
- pet1.updatePet
93
+ pet.updatePet
96
94
 
97
95
  # check that it was saved
98
- PetStore::Pet.getPetById(petId: pet1['id']).name
96
+ PetStore::Pet.getPetById(petId: pet['id']).name
99
97
  # => "ethan" (unless for some reason your name is not Ethan)
100
98
 
101
99
  # here is how errors are handled:
@@ -158,29 +156,28 @@ let's pick a state and find a pet. we'll go through the rest of the example in t
158
156
  sold_pets = pet_store_doc.operations['findPetsByStatus'].run(status: 'sold')
159
157
  # sold_pets is an array-like collection of JSI instances
160
158
 
161
- # compare to getPetById: http://petstore.swagger.io/#/pet/getPetById
162
- pet1 = sold_pets.detect { |pet| pet.tags.any? }
163
- pet2 = pet_store_doc.operations['getPetById'].run(petId: pet1['id'])
164
- # without ResourceBase, pet1 and pet2 are not considered to be the same though [TODO may change in jsi]
165
-
166
- pet1 == pet2
167
- # false
159
+ pet = sold_pets.detect { |pet| pet.tags.any? }
168
160
 
169
- pet1.tags.map(&:name)
161
+ pet.tags.map(&:name)
170
162
  # note that you have accessors on PetStore::Pet like #tags, and also that
171
163
  # tags have accessors for properties 'name' and 'id' from the tags schema
172
164
  # (your tag names will be different depending on what's in the pet store)
173
165
  # => ["aucune"]
174
166
 
167
+ # compare to getPetById: http://petstore.swagger.io/#/pet/getPetById
168
+ pet == pet_store_doc.operations['getPetById'].run(petId: pet['id'])
169
+ # => false
170
+ # without ResourceBase, pet is not considered to be the same compared with getPetById [TODO may change in jsi]
171
+
175
172
  # let's name the pet after ourself
176
- pet1.name = ENV['USER']
173
+ pet.name = ENV['USER']
177
174
 
178
175
  # store the result in the pet store.
179
176
  # updatePet: http://petstore.swagger.io/#/pet/updatePet
180
- pet_store_doc.operations['updatePet'].run(body_object: pet1)
177
+ pet_store_doc.operations['updatePet'].run(body_object: pet)
181
178
 
182
179
  # check that it was saved
183
- pet_store_doc.operations['getPetById'].run(petId: pet1['id']).name
180
+ pet_store_doc.operations['getPetById'].run(petId: pet['id']).name
184
181
  # => "ethan" (unless for some reason your name is not Ethan)
185
182
 
186
183
  # here is how errors are handled:
@@ -84,7 +84,7 @@ module Scorpio
84
84
  end
85
85
 
86
86
  module V3
87
- raise(Bug) unless const_defined?(:Document)
87
+ raise(Bug, 'const_defined? Scorpio::OpenAPI::V3::Document') unless const_defined?(:Document)
88
88
 
89
89
  # A document that defines or describes an API conforming to the OpenAPI Specification v3.
90
90
  #
@@ -127,7 +127,7 @@ module Scorpio
127
127
  end
128
128
 
129
129
  module V2
130
- raise(Bug) unless const_defined?(:Document)
130
+ raise(Bug, 'const_defined? Scorpio::OpenAPI::V2::Document') unless const_defined?(:Document)
131
131
 
132
132
  # A document that defines or describes an API conforming to the OpenAPI Specification v2 (aka Swagger).
133
133
  #
@@ -87,6 +87,8 @@ module Scorpio
87
87
  Addressable::Template.new(File.join(base_url, path_template_str))
88
88
  end
89
89
 
90
+ # @return the HTTP method of this operation as indicated by the attribute name
91
+ # for this operation from the parent PathItem
90
92
  def http_method
91
93
  return @http_method if instance_variable_defined?(:@http_method)
92
94
  @http_method = begin
@@ -155,21 +157,27 @@ module Scorpio
155
157
  end
156
158
  end
157
159
 
160
+ # @param a, b are passed to Scorpio::Request#initialize
161
+ # @return [Scorpio::Request]
158
162
  def build_request(*a, &b)
159
163
  Scorpio::Request.new(self, *a, &b)
160
164
  end
161
165
 
166
+ # @param a, b are passed to Scorpio::Request#initialize
167
+ # @return [Scorpio::Ur] response ur
162
168
  def run_ur(*a, &b)
163
169
  build_request(*a, &b).run_ur
164
170
  end
165
171
 
172
+ # @param a, b are passed to Scorpio::Request#initialize
173
+ # @return response body object
166
174
  def run(*a, &b)
167
175
  build_request(*a, &b).run
168
176
  end
169
177
  end
170
178
 
171
179
  module V3
172
- raise(Bug) unless const_defined?(:Operation)
180
+ raise(Bug, 'const_defined? Scorpio::OpenAPI::V3::Operation') unless const_defined?(:Operation)
173
181
 
174
182
  # Describes a single API operation on a path.
175
183
  #
@@ -205,6 +213,7 @@ module Scorpio
205
213
  end
206
214
  include Configurables
207
215
 
216
+ # @return [JSI::Schema]
208
217
  def request_schema(media_type: self.request_media_type)
209
218
  # TODO typechecking on requestBody & children
210
219
  schema_object = requestBody &&
@@ -214,6 +223,7 @@ module Scorpio
214
223
  schema_object ? JSI::Schema.from_object(schema_object) : nil
215
224
  end
216
225
 
226
+ # @return [Array<JSI::Schema>]
217
227
  def request_schemas
218
228
  if requestBody && requestBody['content']
219
229
  # oamt is for Scorpio::OpenAPI::V3::MediaType
@@ -224,7 +234,7 @@ module Scorpio
224
234
  end
225
235
  end
226
236
 
227
- # @return JSI::Schema
237
+ # @return [JSI::Schema]
228
238
  def response_schema(status: , media_type: )
229
239
  oa_response = self.oa_response(status: status)
230
240
  oa_media_types = oa_response ? oa_response['content'] : nil # Scorpio::OpenAPI::V3::MediaTypes
@@ -235,7 +245,7 @@ module Scorpio
235
245
  end
236
246
  end
237
247
  module V2
238
- raise(Bug) unless const_defined?(:Operation)
248
+ raise(Bug, 'const_defined? Scorpio::OpenAPI::V2::Operation') unless const_defined?(:Operation)
239
249
  class Operation
240
250
  module Configurables
241
251
  attr_writer :scheme
@@ -275,6 +285,8 @@ module Scorpio
275
285
  end
276
286
  end
277
287
 
288
+ # @param media_type unused
289
+ # @return [JSI::Schema] request schema for the given media_type
278
290
  def request_schema(media_type: nil)
279
291
  if body_parameter && body_parameter['schema']
280
292
  JSI::Schema.new(body_parameter['schema'])
@@ -283,11 +295,14 @@ module Scorpio
283
295
  end
284
296
  end
285
297
 
298
+ # @return [Array<JSI::Schema>]
286
299
  def request_schemas
287
300
  request_schema ? [request_schema] : []
288
301
  end
289
302
 
290
- # @return JSI::Schema
303
+ # @param status [Integer, String] response status
304
+ # @param media_type unused
305
+ # @return [JSI::Schema]
291
306
  def response_schema(status: , media_type: nil)
292
307
  oa_response = self.oa_response(status: status)
293
308
  oa_response_schema = oa_response ? oa_response['schema'] : nil # Scorpio::OpenAPI::V2::Schema
@@ -1,7 +1,7 @@
1
1
  module Scorpio
2
2
  module OpenAPI
3
3
  module V3
4
- raise(Bug) unless const_defined?(:Server)
4
+ raise(Bug, 'const_defined? Scorpio::OpenAPI::V3::Server') unless const_defined?(:Server)
5
5
 
6
6
  # An object representing a Server.
7
7
  #
@@ -240,7 +240,7 @@ module Scorpio
240
240
  # @param name [String, Symbol] the 'name' property of one applicable parameter
241
241
  # @param value [Object] the applicable parameter will be applied to the request with the given value.
242
242
  # @return [Object] echoes the value param
243
- # @raise [Scorpio::AmbiguousParameter] if more than one paramater has the given name
243
+ # @raise [Scorpio::AmbiguousParameter] if more than one parameter has the given name
244
244
  def set_param(name, value)
245
245
  param = param_for!(name)
246
246
  set_param_from(param['in'], param['name'], value)
@@ -249,7 +249,7 @@ module Scorpio
249
249
 
250
250
  # @param name [String, Symbol] the 'name' property of one applicable parameter
251
251
  # @return [Object] the value of the named parameter on this request
252
- # @raise [Scorpio::AmbiguousParameter] if more than one paramater has the given name
252
+ # @raise [Scorpio::AmbiguousParameter] if more than one parameter has the given name
253
253
  def get_param(name)
254
254
  param = param_for!(name)
255
255
  get_param_from(param['in'], param['name'])
@@ -427,10 +427,13 @@ module Scorpio
427
427
  end
428
428
 
429
429
  if object.respond_to?(:to_hash)
430
- out = JSI::Typelike.modified_copy(object) do
431
- object.map do |key, value|
430
+ out = JSI::Typelike.modified_copy(object) do |_object|
431
+ mod = object.map do |key, value|
432
432
  {key => response_object_to_instances(value, initialize_options)}
433
433
  end.inject({}, &:update)
434
+ mod = mod.instance if mod.is_a?(JSI::Base)
435
+ mod = mod.content if mod.is_a?(JSI::JSON::Node)
436
+ mod
434
437
  end
435
438
  if model
436
439
  model.new(out, initialize_options)
@@ -1,3 +1,3 @@
1
1
  module Scorpio
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-26 00:00:00.000000000 Z
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsi