scorpio 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +6 -1
- data/CHANGELOG.md +10 -2
- data/LICENSE.md +2 -4
- data/README.md +81 -67
- data/documents/{github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0 → spec.openapis.org/oas/3.0}/schema.yaml +164 -628
- data/documents/spec.openapis.org/oas/3.1/dialect/base.schema.yaml +22 -0
- data/documents/spec.openapis.org/oas/3.1/meta/base.schema.yaml +71 -0
- data/documents/spec.openapis.org/oas/3.1/schema-base.yaml +21 -0
- data/documents/spec.openapis.org/oas/3.1/schema.yaml +980 -0
- data/documents/swagger.io/v2/schema.json +1 -1
- data/documents/www.googleapis.com/discovery/v1/apis/discovery/v1/rest.yml +44 -4
- data/lib/scorpio/google_api_document.rb +121 -193
- data/lib/scorpio/openapi/document.rb +63 -31
- data/lib/scorpio/openapi/operation.rb +114 -96
- data/lib/scorpio/openapi/operations_scope.rb +35 -19
- data/lib/scorpio/openapi/reference.rb +88 -23
- data/lib/scorpio/openapi/schema_elements/type_nullable.rb +38 -0
- data/lib/scorpio/openapi/schema_elements.rb +7 -0
- data/lib/scorpio/openapi/server.rb +34 -0
- data/lib/scorpio/openapi/tag.rb +19 -3
- data/lib/scorpio/openapi/v2/dialect.rb +66 -0
- data/lib/scorpio/openapi/v2.rb +124 -0
- data/lib/scorpio/openapi/v3_0/dialect.rb +76 -0
- data/lib/scorpio/openapi/v3_0.rb +130 -0
- data/lib/scorpio/openapi/v3_1.rb +243 -0
- data/lib/scorpio/openapi.rb +23 -203
- data/lib/scorpio/request.rb +67 -61
- data/lib/scorpio/resource_base.rb +57 -49
- data/lib/scorpio/response.rb +28 -10
- data/lib/scorpio/ur.rb +7 -3
- data/lib/scorpio/version.rb +1 -1
- data/lib/scorpio.rb +12 -6
- data/pages/Request_Configuration.md +69 -0
- data/pages/Security.md +50 -0
- data/scorpio.gemspec +6 -5
- metadata +28 -15
- data/documents/www.googleapis.com/discovery/v1/apis/discovery/v1/rest +0 -684
- data/lib/scorpio/openapi/v3/server.rb +0 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1f812bf2fd5370f04a99f7f4acfa20e731f91209a27bbec923b647620dba75e7
|
|
4
|
+
data.tar.gz: 4ba616f4cb7e42f5ac4ac82b04ec6f2c6ecb9ac7777e3efc275a620180ec0f37
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70bd41fd5637305698660684e25d4cd3e3726aeb12faa17ffcf9ef7d04a0417ba271e01d85b6e2d95bbff08ee83951f6fb0542fbba6eb941a547a67f88aca34a
|
|
7
|
+
data.tar.gz: 7e61e67b208a251d88f838aaaa481498ce2e44797ea955ae3b31f6b3108a42e3c6e67a0e27765deed911d578770cfd9b2131b4b44f8164d40191c395c91e09a6
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# v0.7.0
|
|
2
|
+
|
|
3
|
+
- OpenAPI v3.1 (OpenAPI::V3_1)
|
|
4
|
+
- rename OpenAPI::V3 to OpenAPI::V3_0
|
|
5
|
+
- OpenAPI::Reference resolves $ref across documents
|
|
6
|
+
- Scorpio::Google::RestDescription is an API description document on its own; rm conversion to OpenAPI
|
|
7
|
+
- JSI ~> v0.9
|
|
8
|
+
|
|
1
9
|
# v0.6.4
|
|
2
10
|
|
|
3
11
|
- JSI ~> v0.8.1
|
|
@@ -51,7 +59,7 @@
|
|
|
51
59
|
- bugfixes
|
|
52
60
|
|
|
53
61
|
# v0.4.0
|
|
54
|
-
- Scorpio::OpenAPI v3 classes updated from OAI/OpenAPI-Specification branch oas3-schema
|
|
62
|
+
- Scorpio::OpenAPI v3.0 classes updated from OAI/OpenAPI-Specification branch oas3-schema
|
|
55
63
|
- any uniquely-named request parameter will have accessors on Request and can be passed as config to #initialize
|
|
56
64
|
- Request#each_page_ur for pagination
|
|
57
65
|
- significantly improved documentation
|
|
@@ -61,7 +69,7 @@
|
|
|
61
69
|
- miscellaneous minor fixes and improvements
|
|
62
70
|
|
|
63
71
|
# v0.3.0
|
|
64
|
-
- OpenAPI v3 support
|
|
72
|
+
- OpenAPI v3.0 support
|
|
65
73
|
- classes Request/Response, OpenAPI::Operation, OpenAPI::Document handle a request. ResourceBase relies on these.
|
|
66
74
|
- extract SchemaInstanceBase and friends to gem JSI
|
|
67
75
|
|
data/LICENSE.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
Scorpio Copyright © [Ethan](https://github.com/notEthan/), licensed under the terms of the [GNU Affero General Public License version 3](https://www.gnu.org/licenses/agpl-3.0.html).
|
|
2
2
|
|
|
3
|
-
[<img align="right" src="https://
|
|
4
|
-
|
|
5
|
-
Scorpio is licensed under the terms of the [GNU Affero General Public License version 3](https://www.gnu.org/licenses/agpl-3.0.html).
|
|
3
|
+
[<img align="right" src="https://www.gnu.org/graphics/agplv3-155x51.png">](https://www.gnu.org/licenses/agpl-3.0.html)
|
|
6
4
|
|
|
7
5
|
GNU Affero General Public License
|
|
8
6
|
=================================
|
data/README.md
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
# Scorpio
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
[](https://coveralls.io/github/notEthan/scorpio)
|
|
5
5
|
|
|
6
|
-
Scorpio is a library that helps you, as a client, consume
|
|
6
|
+
Scorpio is a library that helps you, as a client, consume a service whose API is described by an OpenAPI description. You provide the OpenAPI description document, a little bit of configuration, and using that Scorpio will dynamically construct interfaces for you to call the service's operations and interact with its resources like an ORM.
|
|
7
7
|
|
|
8
|
-
Note: The canonical location of this README is on [RubyDoc](
|
|
8
|
+
Note: The canonical location of this README is on [RubyDoc](https://rubydoc.info/gems/scorpio/). When viewed on [Github](https://github.com/notEthan/scorpio/), it may be inconsistent with the latest released gem, and Yardoc links will not work.
|
|
9
9
|
|
|
10
10
|
## Background
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
### OpenAPI specification and OpenAPI documents
|
|
13
13
|
|
|
14
|
+
To start with, you need an OpenAPI document (an OAD) describing a service you will be consuming. OpenAPI Specification v3.1, v3.0, and v2 (formerly known as Swagger) are supported. An OAD can be written by hand or sometimes generated from other existing sources. The creation of an OpenAPI document describing a given service is outside the scope of Scorpio. Here are several resources on OpenAPI:
|
|
15
|
+
|
|
16
|
+
- [Learn about OpenAPI](https://learn.openapis.org/)
|
|
14
17
|
- [OpenAPI Specification at Wikipedia](https://en.wikipedia.org/wiki/OpenAPI_Specification)
|
|
15
|
-
-
|
|
16
|
-
- [OpenAPI Specification on GitHub](https://github.com/OAI/OpenAPI-Specification)
|
|
17
|
-
|
|
18
|
+
- OpenAPI Specifications [v3.1](https://spec.openapis.org/oas/v3.1.html), [v3.0](https://spec.openapis.org/oas/v3.0.html), [v2.0](https://spec.openapis.org/oas/v2.0.html)
|
|
19
|
+
- [OpenAPI Specification development on GitHub](https://github.com/OAI/OpenAPI-Specification)
|
|
20
|
+
|
|
21
|
+
### JSON Schema, JSI
|
|
22
|
+
|
|
23
|
+
[JSON Schema](https://json-schema.org/) is an important part of OpenAPI documents, in which it is used to describe various components of a service's requests and responses.
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
[JSI](https://github.com/notEthan/jsi) is a Ruby library that offers an Object-Oriented representation for JSON data using JSON Schemas.
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
Scorpio utilizes JSI to instantiate components of the API described by JSON schemas, in particular JSON request and response bodies.
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
Scorpio's core is built on JSI. It uses the JSON Schema describing OpenAPI documents (which is published along with the OpenAPI specification) with JSI to instantiate an OAD and to define functionality of the document, operations, and other components.
|
|
24
30
|
|
|
25
31
|
## Pet Store (using Scorpio::ResourceBase)
|
|
26
32
|
|
|
@@ -33,38 +39,46 @@ require 'scorpio'
|
|
|
33
39
|
# PetStore is a module to contain our pet store related classes.
|
|
34
40
|
# it is optional - your naming conventions are your own.
|
|
35
41
|
module PetStore
|
|
36
|
-
# Scorpio's recommended structure is to have a base class which
|
|
37
|
-
# Scorpio::ResourceBase to represent the Pet Store
|
|
42
|
+
# Scorpio's recommended structure is to have a base class which
|
|
43
|
+
# inherits from Scorpio::ResourceBase to represent the Pet Store
|
|
44
|
+
# and all its resources.
|
|
38
45
|
#
|
|
39
|
-
#
|
|
46
|
+
# You configure the OpenAPI document and other shared configuration
|
|
47
|
+
# on this class.
|
|
40
48
|
class Resource < Scorpio::ResourceBase
|
|
41
|
-
#
|
|
42
|
-
# (making network calls at application boot
|
|
43
|
-
# example we will do a
|
|
44
|
-
|
|
45
|
-
self.openapi_document = JSON.parse(Faraday.get('https://petstore.swagger.io/v2/swagger.json').body)
|
|
49
|
+
# Set the OpenAPI document. You'll usually want this to be a file in
|
|
50
|
+
# your local filesystem (making network calls at application boot
|
|
51
|
+
# time is usually a bad idea), but for this example we will do a
|
|
52
|
+
# quick-and-dirty HTTP get.
|
|
53
|
+
self.openapi_document = JSON.parse(Faraday.get('https://petstore.swagger.io/v2/swagger.json').body, freeze: true)
|
|
46
54
|
end
|
|
47
55
|
|
|
48
|
-
# a Pet is a resource of the pet store, so inherits from
|
|
56
|
+
# a Pet is a resource of the pet store, so inherits from
|
|
57
|
+
# PetStore::Resource
|
|
49
58
|
class Pet < Resource
|
|
50
|
-
#
|
|
51
|
-
# class and its instances.
|
|
59
|
+
# Setting the tag name tells Scorpio to associate operations tagged
|
|
60
|
+
# with 'pet' with this class and its instances. This lets you call
|
|
61
|
+
# operations such as addPet, updatePet, etc.
|
|
52
62
|
self.tag_name = 'pet'
|
|
53
63
|
|
|
54
|
-
#
|
|
55
|
-
# calls properly instantiated as
|
|
56
|
-
#
|
|
64
|
+
# Setting the schemas which represent a Pet will let Scorpio
|
|
65
|
+
# return results from operation calls properly instantiated as
|
|
66
|
+
# Pet instances. For example, calling getPetById will return a
|
|
67
|
+
# PetStore::Pet instance since its success response refers
|
|
68
|
+
# to #/definitions/Pet.
|
|
57
69
|
#
|
|
58
|
-
#
|
|
59
|
-
# #/definitions/Pet and likewise Scorpio will
|
|
70
|
+
# This works for nested structures as well, e.g. findPetsByStatus
|
|
71
|
+
# returns an array of #/definitions/Pet and likewise Scorpio will
|
|
72
|
+
# return an array of PetStore::Pet instances.
|
|
60
73
|
#
|
|
61
|
-
#
|
|
74
|
+
# This also adds accessors for properties of the schema - in this
|
|
75
|
+
# case #id, #name, #tags, etc.
|
|
62
76
|
self.represented_schemas = [openapi_document.definitions['Pet']]
|
|
63
77
|
end
|
|
64
78
|
end
|
|
65
79
|
```
|
|
66
80
|
|
|
67
|
-
That
|
|
81
|
+
That is all you need to start calling operations:
|
|
68
82
|
|
|
69
83
|
```ruby
|
|
70
84
|
# call the operation findPetsByStatus
|
|
@@ -73,6 +87,7 @@ sold_pets = PetStore::Pet.findPetsByStatus(status: 'sold')
|
|
|
73
87
|
# sold_pets is an array-like collection of PetStore::Pet instances
|
|
74
88
|
|
|
75
89
|
pet = sold_pets.sample
|
|
90
|
+
# => #<PetStore::Pet #{<JSI> "id" => 9, "name" => "Ix", "status" => "sold", ...}>
|
|
76
91
|
|
|
77
92
|
pet.tags.map(&:name)
|
|
78
93
|
# note that you have accessors on PetStore::Pet like #tags, and also that
|
|
@@ -87,9 +102,10 @@ pet == PetStore::Pet.getPetById(petId: pet['id'])
|
|
|
87
102
|
# let's name the pet after ourself
|
|
88
103
|
pet.name = ENV['USER']
|
|
89
104
|
|
|
90
|
-
#
|
|
91
|
-
# calls so far have been on the class PetStore::Pet,
|
|
92
|
-
# methods to call operations where
|
|
105
|
+
# Store the result in the pet store. Note the updatePet call from the
|
|
106
|
+
# instance - our calls so far have been on the class PetStore::Pet,
|
|
107
|
+
# but Scorpio defines instance methods to call operations where
|
|
108
|
+
# appropriate as well.
|
|
93
109
|
# updatePet: https://petstore.swagger.io/#/pet/updatePet
|
|
94
110
|
pet.updatePet
|
|
95
111
|
|
|
@@ -106,23 +122,25 @@ PetStore::Pet.getPetById(petId: 0)
|
|
|
106
122
|
|
|
107
123
|
Isn't that cool? You get class methods like getPetById, instance methods like updatePet, attribute accessors like #name and #tags, all dynamically generated from the OpenAPI description. You just make a few classes with a line or two of configuration in each.
|
|
108
124
|
|
|
109
|
-
## Pet Store (
|
|
125
|
+
## Pet Store (without Scorpio::ResourceBase)
|
|
110
126
|
|
|
111
|
-
You do not have to define resource classes to use Scorpio to
|
|
127
|
+
You do not have to define resource classes as above to use Scorpio to interact with a service - ResourceBase is a helpful representation of the service's resources, but operations can be run directly from Scorpio's representation of the OpenAPI document.
|
|
112
128
|
|
|
113
|
-
|
|
129
|
+
This representation uses [JSI](https://github.com/notEthan/jsi) with the JSON schema describing OpenAPI documents (for the relevant version of the OpenAPI specification). Scorpio's API client functionality is implemented using these schemas, and the result is that the instantiated OpenAPI document is itself the client to the service it describes.
|
|
130
|
+
|
|
131
|
+
To consume the Pet Store service, we start by instantiating the OpenAPI document. {Scorpio.new_document} returns a JSI instance described by the appropriate OpenAPI document schema.
|
|
114
132
|
|
|
115
133
|
```ruby
|
|
116
134
|
require 'scorpio'
|
|
117
|
-
|
|
118
|
-
|
|
135
|
+
pet_store_content = JSON.parse(Faraday.get('https://petstore.swagger.io/v2/swagger.json').body, freeze: true)
|
|
136
|
+
pet_store_oad = Scorpio::OpenAPI::Document.from_instance(pet_store_content)
|
|
137
|
+
# => #{<JSI (Scorpio::OpenAPI::V2::Document)> "swagger" => "2.0", ...}
|
|
119
138
|
```
|
|
120
139
|
|
|
121
|
-
|
|
140
|
+
Within `pet_store_oad` we can access an operation under the OAD's `#paths` property - JSI objects have accessors for described properties, or can be subscripted as with the Hash/Array nodes they represent.
|
|
122
141
|
|
|
123
142
|
```ruby
|
|
124
|
-
|
|
125
|
-
inventory_op = pet_store_doc.paths['/store/inventory']['get']
|
|
143
|
+
inventory_op = pet_store_oad.paths['/store/inventory']['get']
|
|
126
144
|
# => #{<JSI (Scorpio::OpenAPI::V2::Operation)>
|
|
127
145
|
# "summary" => "Returns pet inventories by status",
|
|
128
146
|
# "operationId" => "getInventory",
|
|
@@ -130,14 +148,14 @@ inventory_op = pet_store_doc.paths['/store/inventory']['get']
|
|
|
130
148
|
# }
|
|
131
149
|
```
|
|
132
150
|
|
|
133
|
-
Alternatively, Scorpio defines a helper
|
|
151
|
+
Alternatively, Scorpio defines a helper {Scorpio::OpenAPI::Document#operations} which is an Enumerable of all the Operations in the Document. It can be subscripted with an `operationId`:
|
|
134
152
|
|
|
135
153
|
```ruby
|
|
136
|
-
inventory_op =
|
|
154
|
+
inventory_op = pet_store_oad.operations['getInventory']
|
|
137
155
|
# => returns the same inventory_op as above.
|
|
138
156
|
```
|
|
139
157
|
|
|
140
|
-
Now that we have an operation, we can run requests from it
|
|
158
|
+
Now that we have an operation, we can run requests from it with {Scorpio::OpenAPI::Operation#run}. On success, it returns the parsed response body, instantiated using the JSON schema for the operation response, if that is specified in the OAD.
|
|
141
159
|
|
|
142
160
|
```ruby
|
|
143
161
|
inventory = inventory_op.run
|
|
@@ -150,25 +168,29 @@ inventory = inventory_op.run
|
|
|
150
168
|
# }
|
|
151
169
|
```
|
|
152
170
|
|
|
153
|
-
|
|
171
|
+
We'll pick a state, find a pet, and go through the rest of the example in the ResourceBase section pretty much like it is up there:
|
|
154
172
|
|
|
155
173
|
```ruby
|
|
156
174
|
# call the operation findPetsByStatus
|
|
157
175
|
# doc: https://petstore.swagger.io/#/pet/findPetsByStatus
|
|
158
|
-
|
|
159
|
-
|
|
176
|
+
# we will be mutating one of these, so we pass mutable: true
|
|
177
|
+
sold_pets = pet_store_oad.operations['findPetsByStatus'].run(status: 'sold', mutable: true)
|
|
178
|
+
# sold_pets is an array-like collection of JSI instances.
|
|
179
|
+
# Each item is described by the OAD's Pet schema.
|
|
180
|
+
sold_pets.first.described_by?(pet_store_oad.definitions['Pet']) # => true
|
|
160
181
|
|
|
161
182
|
pet = sold_pets.detect { |pet| pet.tags.any? }
|
|
162
183
|
|
|
163
184
|
pet.tags.map(&:name)
|
|
164
|
-
#
|
|
165
|
-
# tags have accessors for properties 'name' and 'id' from the tags
|
|
166
|
-
# (your tag names will be different depending on what's in the
|
|
185
|
+
# Note that you have accessors on the returned JSI like #tags, and also
|
|
186
|
+
# that tags have accessors for properties 'name' and 'id' from the tags
|
|
187
|
+
# schema (your tag names will be different depending on what's in the
|
|
188
|
+
# pet store).
|
|
167
189
|
# => ["aucune"]
|
|
168
190
|
|
|
169
191
|
# compare the pet from findPetsByStatus to one returned from getPetById
|
|
170
192
|
# doc: https://petstore.swagger.io/#/pet/getPetById
|
|
171
|
-
pet_by_id =
|
|
193
|
+
pet_by_id = pet_store_oad.operations['getPetById'].run(petId: pet['id'])
|
|
172
194
|
|
|
173
195
|
# unlike ResourceBase instances above, JSI instances have stricter
|
|
174
196
|
# equality and the pets returned from different operations are not
|
|
@@ -181,14 +203,14 @@ pet.name = ENV['USER']
|
|
|
181
203
|
|
|
182
204
|
# store the result in the pet store.
|
|
183
205
|
# updatePet: https://petstore.swagger.io/#/pet/updatePet
|
|
184
|
-
|
|
206
|
+
pet_store_oad.operations['updatePet'].run(body_object: pet)
|
|
185
207
|
|
|
186
208
|
# check that it was saved
|
|
187
|
-
|
|
209
|
+
pet_store_oad.operations['getPetById'].run(petId: pet['id']).name
|
|
188
210
|
# => "ethan" (unless for some reason your name is not Ethan)
|
|
189
211
|
|
|
190
212
|
# here is how errors are handled:
|
|
191
|
-
|
|
213
|
+
pet_store_oad.operations['getPetById'].run(petId: 0)
|
|
192
214
|
# raises: Scorpio::HTTPErrors::NotFound404Error
|
|
193
215
|
# Error calling operation getPetById:
|
|
194
216
|
# {"code":1,"type":"error","message":"Pet not found"}
|
|
@@ -198,7 +220,7 @@ pet_store_doc.operations['getPetById'].run(petId: 0)
|
|
|
198
220
|
|
|
199
221
|
For another example of an API that a client interacts with using Scorpio::ResourceBase, Scorpio's tests implement the Blog service. This is defined in test/blog.rb. The service uses ActiveRecord models and Sinatra to make a simple RESTful service.
|
|
200
222
|
|
|
201
|
-
Its API is described in `test/blog.openapi
|
|
223
|
+
Its API is described in `test/blog.openapi<version>.yml`, defining the Article resource, several operations, and schemas. The client is set up in `test/blog_scorpio_models.rb`. The base class BlogModel defines the base_url and the api description, as well as some other optional setup done for testing. Its operations are tested in `test/scorpio_test.rb`.
|
|
202
224
|
|
|
203
225
|
## Scorpio::ResourceBase
|
|
204
226
|
|
|
@@ -222,12 +244,12 @@ When these are set, Scorpio::ResourceBase looks through the API description and
|
|
|
222
244
|
|
|
223
245
|
## Scorpio::Ur
|
|
224
246
|
|
|
225
|
-
If you need a more complete representation of the HTTP request and/or response, Scorpio::OpenAPI::Operation#run_ur
|
|
247
|
+
If you need a more complete representation of the HTTP request and/or response, {Scorpio::OpenAPI::Operation#run_ur} will return a representation of the request and response defined by the gem [Ur](https://github.com/notEthan/ur). See that link for more detail. Relating to the example above titled "Pet Store (without Scorpio::ResourceBase)", this code will return an Ur:
|
|
226
248
|
|
|
227
249
|
```ruby
|
|
228
|
-
inventory_op = Scorpio
|
|
250
|
+
inventory_op = Scorpio.new_document(JSON.parse(Faraday.get('https://petstore.swagger.io/v2/swagger.json').body, freeze: true)).paths['/store/inventory']['get']
|
|
229
251
|
inventory_ur = inventory_op.run_ur
|
|
230
|
-
# => #{<Scorpio::Ur
|
|
252
|
+
# => #{<JSI (Ur + Scorpio::Ur)> "bound" => "outbound", "request" => ...}
|
|
231
253
|
```
|
|
232
254
|
|
|
233
255
|
### Scorpio ResourceBase pickle adapter
|
|
@@ -236,24 +258,16 @@ Scorpio provides a pickle adapter to use models with [Pickle](https://rubygems.o
|
|
|
236
258
|
|
|
237
259
|
### Google API discovery service
|
|
238
260
|
|
|
239
|
-
|
|
261
|
+
Scorpio was initially built to work with the API description format defined for Google's API discovery service. Though Scorpio is now primarily built for OpenAPI, Google's format is still supported.
|
|
240
262
|
|
|
241
263
|
For background on the Google discovery service and the API description format it defines, see:
|
|
242
264
|
|
|
243
265
|
- https://developers.google.com/discovery/
|
|
244
266
|
- https://developers.google.com/discovery/v1/reference/
|
|
245
267
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
```ruby
|
|
249
|
-
class MyModel < Scorpio::ResourceBase
|
|
250
|
-
rest_description_doc = YAML.load_file('path/to/doc.yml')
|
|
251
|
-
rest_description = Scorpio::Google::RestDescription.new(rest_description_doc)
|
|
252
|
-
self.openapi_document = rest_description.to_openapi_document
|
|
268
|
+
Such an API description (called a "rest description" or sometimes "discovery document") is an instance of {Scorpio::Google::RestDescription}. Note that Scorpio being OpenAPI-centric, some interfaces use the idioms or terminology of OpenAPI, e.g. a {Scorpio::Google::RestMethod} uses the interface of {Scorpio::OpenAPI::Operation}. See `examples/google` in Scorpio's repository for example usage.
|
|
253
269
|
|
|
254
|
-
|
|
255
|
-
end
|
|
256
|
-
```
|
|
270
|
+
Google does provide official [API clients in Ruby](https://github.com/googleapis/google-api-ruby-client). These weigh in at nearly 5 million lines of code across about 500 gems, almost all generated code from the same API documents Scorpio uses. Scorpio's dynamic handling of API documents and their schemas provides comparable functionality.
|
|
257
271
|
|
|
258
272
|
## Other
|
|
259
273
|
|