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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +21 -24
- data/lib/scorpio/openapi/document.rb +2 -2
- data/lib/scorpio/openapi/operation.rb +19 -4
- data/lib/scorpio/openapi/v3/server.rb +1 -1
- data/lib/scorpio/request.rb +2 -2
- data/lib/scorpio/resource_base.rb +5 -2
- data/lib/scorpio/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 510fd6b2b4dc5e78a4d11c08dcb7fc53901b308a4eef0b53d3d7317aabdd265f
|
4
|
+
data.tar.gz: d2c92b80c26f24f5f98540c456b2177d74bc13e5a2e5f461a531525631afff96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52561bf683728001d750987ae8eb8df5356b75db3c0e1b734182a3af69227c4db6e4699d94b1a8f820802b5c5d804c9d73eebf49ea05991c309ef6b20d9ce8ff
|
7
|
+
data.tar.gz: 8144a386a93d397193ea952965d3de6bf398739a4b2c20a2e8dfcbd716f9721a3eae9949f5714695ce83e338353c8152954e1bee130af198973a41f7edb9e854
|
data/CHANGELOG.md
CHANGED
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]
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
93
|
+
pet.updatePet
|
96
94
|
|
97
95
|
# check that it was saved
|
98
|
-
PetStore::Pet.getPetById(petId:
|
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
|
-
|
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
|
-
|
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
|
-
|
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:
|
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:
|
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
|
-
# @
|
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
|
data/lib/scorpio/request.rb
CHANGED
@@ -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
|
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
|
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)
|
data/lib/scorpio/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2019-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsi
|