scorpio 0.4.6 → 0.5.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/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/scorpio/google_api_document.rb +16 -9
- data/lib/scorpio/openapi.rb +125 -131
- data/lib/scorpio/openapi/document.rb +4 -4
- data/lib/scorpio/openapi/operation.rb +2 -2
- data/lib/scorpio/openapi/operations_scope.rb +1 -1
- data/lib/scorpio/openapi/v3/server.rb +1 -1
- data/lib/scorpio/request.rb +13 -9
- data/lib/scorpio/resource_base.rb +9 -2
- data/lib/scorpio/response.rb +3 -1
- data/lib/scorpio/ur.rb +12 -15
- data/lib/scorpio/version.rb +1 -1
- data/scorpio.gemspec +4 -3
- data/test/blog.openapi2.yml +113 -0
- data/test/blog.openapi3.yml +131 -0
- data/test/blog.rb +117 -0
- data/test/blog.rest_description.yml +67 -0
- data/test/blog_scorpio_models.rb +49 -0
- data/test/scorpio_test.rb +105 -0
- data/test/test_helper.rb +86 -0
- metadata +25 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ef095c64774f95040582a9945d63cb2e58685403b66d49a9df1ec8976c5d12b
|
4
|
+
data.tar.gz: 777af82e020ab367e4280f10995b0aa84648782a157bc925529132c79e0b57d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10fc95d393931ac8931c16bbe12dd62366e73480dc7ac5fa7c38efe8ab21cf49506eb659b0734bc3848df1a4994795adb6eb15302c3e3d942051ebe74f92dc09
|
7
|
+
data.tar.gz: e1ebe65228ca3412b24fedf99d0fbf84cd46acea560d09b32fc54a6142308fbfa088b471e65a0128b0ebffa1b1b4f5a3143be8c7f5b823a8c19c1d02eaaf5054
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -262,6 +262,6 @@ The detailed, machine-interpretable description of an API provided by a properly
|
|
262
262
|
|
263
263
|
[<img align="right" src="https://github.com/notEthan/scorpio/raw/master/resources/icons/AGPL-3.0.png">](https://www.gnu.org/licenses/agpl-3.0.html)
|
264
264
|
|
265
|
-
Scorpio is
|
265
|
+
Scorpio is licensed under the terms of the [GNU Affero General Public License version 3](https://www.gnu.org/licenses/agpl-3.0.html).
|
266
266
|
|
267
267
|
Unlike the MIT or BSD licenses more commonly used with Ruby gems, this license requires that if you modify Scorpio and propagate your changes, e.g. by including it in a web application, your modified version must be publicly available. The common path of forking on Github should satisfy this requirement.
|
@@ -4,13 +4,20 @@ module Scorpio
|
|
4
4
|
discovery_rest_description = JSI::MetaschemaNode.new(discovery_rest_description_doc, metaschema_root_ptr: JSI::JSON::Pointer['schemas']['JsonSchema'], root_schema_ptr: JSI::JSON::Pointer['schemas']['RestDescription'])
|
5
5
|
|
6
6
|
# naming these is not strictly necessary, but is nice to have.
|
7
|
-
DirectoryList
|
8
|
-
JsonSchema
|
9
|
-
RestDescription
|
10
|
-
RestMethod
|
11
|
-
RestResource
|
12
|
-
|
13
|
-
|
7
|
+
DirectoryList = discovery_rest_description.schemas['DirectoryList'].jsi_schema_module
|
8
|
+
JsonSchema = discovery_rest_description.schemas['JsonSchema'].jsi_schema_module
|
9
|
+
RestDescription = discovery_rest_description.schemas['RestDescription'].jsi_schema_module
|
10
|
+
RestMethod = discovery_rest_description.schemas['RestMethod'].jsi_schema_module
|
11
|
+
RestResource = discovery_rest_description.schemas['RestResource'].jsi_schema_module
|
12
|
+
|
13
|
+
module RestDescription
|
14
|
+
Resources = properties['resources']
|
15
|
+
end
|
16
|
+
|
17
|
+
module RestMethod
|
18
|
+
Request = properties['request']
|
19
|
+
Response = properties['response']
|
20
|
+
end
|
14
21
|
|
15
22
|
# 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?
|
16
23
|
module SchemaLike
|
@@ -33,9 +40,9 @@ module Scorpio
|
|
33
40
|
dup_doc
|
34
41
|
end
|
35
42
|
end
|
36
|
-
[JsonSchema,
|
43
|
+
[JsonSchema, RestMethod::Request, RestMethod::Response].each { |m| m.send(:include, SchemaLike) }
|
37
44
|
|
38
|
-
|
45
|
+
module RestDescription
|
39
46
|
def to_openapi_document(options = {})
|
40
47
|
Scorpio::OpenAPI::Document.from_instance(to_openapi_hash(options))
|
41
48
|
end
|
data/lib/scorpio/openapi.rb
CHANGED
@@ -19,75 +19,72 @@ module Scorpio
|
|
19
19
|
|
20
20
|
module V3
|
21
21
|
openapi_schema = JSI::Schema.new(::YAML.load_file(Scorpio.root.join('documents/github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0/schema.yaml')))
|
22
|
-
openapi_class = proc do |*key|
|
23
|
-
JSI.class_for_schema(key.inject(openapi_schema, &:[]))
|
24
|
-
end
|
25
22
|
|
26
|
-
Document =
|
23
|
+
Document = openapi_schema.jsi_schema_module
|
27
24
|
|
28
25
|
# naming these is not strictly necessary, but is nice to have.
|
29
|
-
# generated: `puts JSI::Schema.new(::YAML.load_file(Scorpio.root.join('documents/github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0/schema.yaml')))['definitions'].select { |k,v| ['object', nil].include?(v['type']) }.keys.map { |k| "#{k[0].upcase}#{k[1..-1]} =
|
30
|
-
Reference =
|
31
|
-
SchemaReference =
|
32
|
-
Info =
|
33
|
-
Contact =
|
34
|
-
License =
|
35
|
-
Server =
|
36
|
-
ServerVariable =
|
37
|
-
Components =
|
38
|
-
Schema =
|
39
|
-
Discriminator =
|
40
|
-
XML =
|
41
|
-
Response =
|
42
|
-
MediaType =
|
43
|
-
MediaTypeWithExample =
|
44
|
-
MediaTypeWithExamples =
|
45
|
-
Example =
|
46
|
-
Header =
|
47
|
-
HeaderWithSchema =
|
48
|
-
HeaderWithSchemaWithExample =
|
49
|
-
HeaderWithSchemaWithExamples =
|
50
|
-
HeaderWithContent =
|
51
|
-
Paths =
|
52
|
-
PathItem =
|
53
|
-
Operation =
|
54
|
-
Responses =
|
55
|
-
SecurityRequirement =
|
56
|
-
Tag =
|
57
|
-
ExternalDocumentation =
|
58
|
-
Parameter =
|
59
|
-
ParameterWithSchema =
|
60
|
-
ParameterWithSchemaWithExample =
|
61
|
-
ParameterWithSchemaWithExampleInPath =
|
62
|
-
ParameterWithSchemaWithExampleInQuery =
|
63
|
-
ParameterWithSchemaWithExampleInHeader =
|
64
|
-
ParameterWithSchemaWithExampleInCookie =
|
65
|
-
ParameterWithSchemaWithExamples =
|
66
|
-
ParameterWithSchemaWithExamplesInPath =
|
67
|
-
ParameterWithSchemaWithExamplesInQuery =
|
68
|
-
ParameterWithSchemaWithExamplesInHeader =
|
69
|
-
ParameterWithSchemaWithExamplesInCookie =
|
70
|
-
ParameterWithContent =
|
71
|
-
ParameterWithContentInPath =
|
72
|
-
ParameterWithContentNotInPath =
|
73
|
-
RequestBody =
|
74
|
-
SecurityScheme =
|
75
|
-
APIKeySecurityScheme =
|
76
|
-
HTTPSecurityScheme =
|
77
|
-
NonBearerHTTPSecurityScheme =
|
78
|
-
BearerHTTPSecurityScheme =
|
79
|
-
OAuth2SecurityScheme =
|
80
|
-
OpenIdConnectSecurityScheme =
|
81
|
-
OAuthFlows =
|
82
|
-
ImplicitOAuthFlow =
|
83
|
-
PasswordOAuthFlow =
|
84
|
-
ClientCredentialsFlow =
|
85
|
-
AuthorizationCodeOAuthFlow =
|
86
|
-
Link =
|
87
|
-
LinkWithOperationRef =
|
88
|
-
LinkWithOperationId =
|
89
|
-
Callback =
|
90
|
-
Encoding =
|
26
|
+
# generated: `puts JSI::Schema.new(::YAML.load_file(Scorpio.root.join('documents/github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0/schema.yaml')))['definitions'].select { |k,v| ['object', nil].include?(v['type']) }.keys.map { |k| "#{k[0].upcase}#{k[1..-1]} = Document.definitions['#{k}']" }`
|
27
|
+
Reference = Document.definitions['Reference']
|
28
|
+
SchemaReference = Document.definitions['SchemaReference']
|
29
|
+
Info = Document.definitions['Info']
|
30
|
+
Contact = Document.definitions['Contact']
|
31
|
+
License = Document.definitions['License']
|
32
|
+
Server = Document.definitions['Server']
|
33
|
+
ServerVariable = Document.definitions['ServerVariable']
|
34
|
+
Components = Document.definitions['Components']
|
35
|
+
Schema = Document.definitions['Schema']
|
36
|
+
Discriminator = Document.definitions['Discriminator']
|
37
|
+
XML = Document.definitions['XML']
|
38
|
+
Response = Document.definitions['Response']
|
39
|
+
MediaType = Document.definitions['MediaType']
|
40
|
+
MediaTypeWithExample = Document.definitions['MediaTypeWithExample']
|
41
|
+
MediaTypeWithExamples = Document.definitions['MediaTypeWithExamples']
|
42
|
+
Example = Document.definitions['Example']
|
43
|
+
Header = Document.definitions['Header']
|
44
|
+
HeaderWithSchema = Document.definitions['HeaderWithSchema']
|
45
|
+
HeaderWithSchemaWithExample = Document.definitions['HeaderWithSchemaWithExample']
|
46
|
+
HeaderWithSchemaWithExamples = Document.definitions['HeaderWithSchemaWithExamples']
|
47
|
+
HeaderWithContent = Document.definitions['HeaderWithContent']
|
48
|
+
Paths = Document.definitions['Paths']
|
49
|
+
PathItem = Document.definitions['PathItem']
|
50
|
+
Operation = Document.definitions['Operation']
|
51
|
+
Responses = Document.definitions['Responses']
|
52
|
+
SecurityRequirement = Document.definitions['SecurityRequirement']
|
53
|
+
Tag = Document.definitions['Tag']
|
54
|
+
ExternalDocumentation = Document.definitions['ExternalDocumentation']
|
55
|
+
Parameter = Document.definitions['Parameter']
|
56
|
+
ParameterWithSchema = Document.definitions['ParameterWithSchema']
|
57
|
+
ParameterWithSchemaWithExample = Document.definitions['ParameterWithSchemaWithExample']
|
58
|
+
ParameterWithSchemaWithExampleInPath = Document.definitions['ParameterWithSchemaWithExampleInPath']
|
59
|
+
ParameterWithSchemaWithExampleInQuery = Document.definitions['ParameterWithSchemaWithExampleInQuery']
|
60
|
+
ParameterWithSchemaWithExampleInHeader = Document.definitions['ParameterWithSchemaWithExampleInHeader']
|
61
|
+
ParameterWithSchemaWithExampleInCookie = Document.definitions['ParameterWithSchemaWithExampleInCookie']
|
62
|
+
ParameterWithSchemaWithExamples = Document.definitions['ParameterWithSchemaWithExamples']
|
63
|
+
ParameterWithSchemaWithExamplesInPath = Document.definitions['ParameterWithSchemaWithExamplesInPath']
|
64
|
+
ParameterWithSchemaWithExamplesInQuery = Document.definitions['ParameterWithSchemaWithExamplesInQuery']
|
65
|
+
ParameterWithSchemaWithExamplesInHeader = Document.definitions['ParameterWithSchemaWithExamplesInHeader']
|
66
|
+
ParameterWithSchemaWithExamplesInCookie = Document.definitions['ParameterWithSchemaWithExamplesInCookie']
|
67
|
+
ParameterWithContent = Document.definitions['ParameterWithContent']
|
68
|
+
ParameterWithContentInPath = Document.definitions['ParameterWithContentInPath']
|
69
|
+
ParameterWithContentNotInPath = Document.definitions['ParameterWithContentNotInPath']
|
70
|
+
RequestBody = Document.definitions['RequestBody']
|
71
|
+
SecurityScheme = Document.definitions['SecurityScheme']
|
72
|
+
APIKeySecurityScheme = Document.definitions['APIKeySecurityScheme']
|
73
|
+
HTTPSecurityScheme = Document.definitions['HTTPSecurityScheme']
|
74
|
+
NonBearerHTTPSecurityScheme = Document.definitions['NonBearerHTTPSecurityScheme']
|
75
|
+
BearerHTTPSecurityScheme = Document.definitions['BearerHTTPSecurityScheme']
|
76
|
+
OAuth2SecurityScheme = Document.definitions['OAuth2SecurityScheme']
|
77
|
+
OpenIdConnectSecurityScheme = Document.definitions['OpenIdConnectSecurityScheme']
|
78
|
+
OAuthFlows = Document.definitions['OAuthFlows']
|
79
|
+
ImplicitOAuthFlow = Document.definitions['ImplicitOAuthFlow']
|
80
|
+
PasswordOAuthFlow = Document.definitions['PasswordOAuthFlow']
|
81
|
+
ClientCredentialsFlow = Document.definitions['ClientCredentialsFlow']
|
82
|
+
AuthorizationCodeOAuthFlow = Document.definitions['AuthorizationCodeOAuthFlow']
|
83
|
+
Link = Document.definitions['Link']
|
84
|
+
LinkWithOperationRef = Document.definitions['LinkWithOperationRef']
|
85
|
+
LinkWithOperationId = Document.definitions['LinkWithOperationId']
|
86
|
+
Callback = Document.definitions['Callback']
|
87
|
+
Encoding = Document.definitions['Encoding']
|
91
88
|
|
92
89
|
# the schema of Scorpio::OpenAPI::V3::Schema describes a schema itself, so we extend it
|
93
90
|
# with the module indicating that.
|
@@ -96,68 +93,65 @@ module Scorpio
|
|
96
93
|
end
|
97
94
|
module V2
|
98
95
|
openapi_schema = JSI::Schema.new(::JSON.parse(Scorpio.root.join('documents/swagger.io/v2/schema.json').read))
|
99
|
-
openapi_class = proc do |*key|
|
100
|
-
JSI.class_for_schema(key.inject(openapi_schema, &:[]))
|
101
|
-
end
|
102
96
|
|
103
|
-
Document =
|
97
|
+
Document = openapi_schema.jsi_schema_module
|
104
98
|
|
105
99
|
# naming these is not strictly necessary, but is nice to have.
|
106
|
-
# generated: `puts
|
107
|
-
Info =
|
108
|
-
Contact =
|
109
|
-
License =
|
110
|
-
Paths =
|
111
|
-
Definitions =
|
112
|
-
ParameterDefinitions =
|
113
|
-
ResponseDefinitions =
|
114
|
-
ExternalDocs =
|
115
|
-
Examples =
|
116
|
-
Operation =
|
117
|
-
PathItem =
|
118
|
-
Responses =
|
119
|
-
ResponseValue =
|
120
|
-
Response =
|
121
|
-
Headers =
|
122
|
-
Header =
|
123
|
-
VendorExtension =
|
124
|
-
BodyParameter =
|
125
|
-
HeaderParameterSubSchema =
|
126
|
-
QueryParameterSubSchema =
|
127
|
-
FormDataParameterSubSchema =
|
128
|
-
PathParameterSubSchema =
|
129
|
-
NonBodyParameter =
|
130
|
-
Parameter =
|
131
|
-
Schema =
|
132
|
-
FileSchema =
|
133
|
-
PrimitivesItems =
|
134
|
-
SecurityRequirement =
|
135
|
-
Xml =
|
136
|
-
Tag =
|
137
|
-
SecurityDefinitions =
|
138
|
-
BasicAuthenticationSecurity =
|
139
|
-
ApiKeySecurity =
|
140
|
-
Oauth2ImplicitSecurity =
|
141
|
-
Oauth2PasswordSecurity =
|
142
|
-
Oauth2ApplicationSecurity =
|
143
|
-
Oauth2AccessCodeSecurity =
|
144
|
-
Oauth2Scopes =
|
145
|
-
Title =
|
146
|
-
Description =
|
147
|
-
Default =
|
148
|
-
MultipleOf =
|
149
|
-
Maximum =
|
150
|
-
ExclusiveMaximum =
|
151
|
-
Minimum =
|
152
|
-
ExclusiveMinimum =
|
153
|
-
MaxLength =
|
154
|
-
MinLength =
|
155
|
-
Pattern =
|
156
|
-
MaxItems =
|
157
|
-
MinItems =
|
158
|
-
UniqueItems =
|
159
|
-
Enum =
|
160
|
-
JsonReference =
|
100
|
+
# generated: `puts JSI::Schema.new(::JSON.parse(Scorpio.root.join('documents/swagger.io/v2/schema.json').read))['definitions'].select { |k,v| ['object', nil].include?(v['type']) }.keys.map { |k| "#{k[0].upcase}#{k[1..-1]} = Document.definitions['#{k}']" }`
|
101
|
+
Info = Document.definitions['info']
|
102
|
+
Contact = Document.definitions['contact']
|
103
|
+
License = Document.definitions['license']
|
104
|
+
Paths = Document.definitions['paths']
|
105
|
+
Definitions = Document.definitions['definitions']
|
106
|
+
ParameterDefinitions = Document.definitions['parameterDefinitions']
|
107
|
+
ResponseDefinitions = Document.definitions['responseDefinitions']
|
108
|
+
ExternalDocs = Document.definitions['externalDocs']
|
109
|
+
Examples = Document.definitions['examples']
|
110
|
+
Operation = Document.definitions['operation']
|
111
|
+
PathItem = Document.definitions['pathItem']
|
112
|
+
Responses = Document.definitions['responses']
|
113
|
+
ResponseValue = Document.definitions['responseValue']
|
114
|
+
Response = Document.definitions['response']
|
115
|
+
Headers = Document.definitions['headers']
|
116
|
+
Header = Document.definitions['header']
|
117
|
+
VendorExtension = Document.definitions['vendorExtension']
|
118
|
+
BodyParameter = Document.definitions['bodyParameter']
|
119
|
+
HeaderParameterSubSchema = Document.definitions['headerParameterSubSchema']
|
120
|
+
QueryParameterSubSchema = Document.definitions['queryParameterSubSchema']
|
121
|
+
FormDataParameterSubSchema = Document.definitions['formDataParameterSubSchema']
|
122
|
+
PathParameterSubSchema = Document.definitions['pathParameterSubSchema']
|
123
|
+
NonBodyParameter = Document.definitions['nonBodyParameter']
|
124
|
+
Parameter = Document.definitions['parameter']
|
125
|
+
Schema = Document.definitions['schema']
|
126
|
+
FileSchema = Document.definitions['fileSchema']
|
127
|
+
PrimitivesItems = Document.definitions['primitivesItems']
|
128
|
+
SecurityRequirement = Document.definitions['securityRequirement']
|
129
|
+
Xml = Document.definitions['xml']
|
130
|
+
Tag = Document.definitions['tag']
|
131
|
+
SecurityDefinitions = Document.definitions['securityDefinitions']
|
132
|
+
BasicAuthenticationSecurity = Document.definitions['basicAuthenticationSecurity']
|
133
|
+
ApiKeySecurity = Document.definitions['apiKeySecurity']
|
134
|
+
Oauth2ImplicitSecurity = Document.definitions['oauth2ImplicitSecurity']
|
135
|
+
Oauth2PasswordSecurity = Document.definitions['oauth2PasswordSecurity']
|
136
|
+
Oauth2ApplicationSecurity = Document.definitions['oauth2ApplicationSecurity']
|
137
|
+
Oauth2AccessCodeSecurity = Document.definitions['oauth2AccessCodeSecurity']
|
138
|
+
Oauth2Scopes = Document.definitions['oauth2Scopes']
|
139
|
+
Title = Document.definitions['title']
|
140
|
+
Description = Document.definitions['description']
|
141
|
+
Default = Document.definitions['default']
|
142
|
+
MultipleOf = Document.definitions['multipleOf']
|
143
|
+
Maximum = Document.definitions['maximum']
|
144
|
+
ExclusiveMaximum = Document.definitions['exclusiveMaximum']
|
145
|
+
Minimum = Document.definitions['minimum']
|
146
|
+
ExclusiveMinimum = Document.definitions['exclusiveMinimum']
|
147
|
+
MaxLength = Document.definitions['maxLength']
|
148
|
+
MinLength = Document.definitions['minLength']
|
149
|
+
Pattern = Document.definitions['pattern']
|
150
|
+
MaxItems = Document.definitions['maxItems']
|
151
|
+
MinItems = Document.definitions['minItems']
|
152
|
+
UniqueItems = Document.definitions['uniqueItems']
|
153
|
+
Enum = Document.definitions['enum']
|
154
|
+
JsonReference = Document.definitions['jsonReference']
|
161
155
|
|
162
156
|
# the schema of Scorpio::OpenAPI::V2::Schema describes a schema itself, so we extend it
|
163
157
|
# with the module indicating that.
|
@@ -170,26 +164,26 @@ module Scorpio
|
|
170
164
|
end # (this block is here just so the above informative comment is not interpreted as module doc)
|
171
165
|
|
172
166
|
module V3
|
173
|
-
|
167
|
+
module Operation
|
174
168
|
include OpenAPI::Operation
|
175
169
|
end
|
176
|
-
|
170
|
+
module Document
|
177
171
|
include OpenAPI::Document
|
178
172
|
end
|
179
|
-
|
173
|
+
module Reference
|
180
174
|
include OpenAPI::Reference
|
181
175
|
end
|
182
176
|
require 'scorpio/openapi/v3/server'
|
183
177
|
end
|
184
178
|
|
185
179
|
module V2
|
186
|
-
|
180
|
+
module Operation
|
187
181
|
include OpenAPI::Operation
|
188
182
|
end
|
189
|
-
|
183
|
+
module Document
|
190
184
|
include OpenAPI::Document
|
191
185
|
end
|
192
|
-
|
186
|
+
module JsonReference
|
193
187
|
include OpenAPI::Reference
|
194
188
|
end
|
195
189
|
end
|
@@ -18,9 +18,9 @@ module Scorpio
|
|
18
18
|
raise(TypeError, "instance is unexpected JSI type: #{instance.class.inspect}")
|
19
19
|
elsif instance.respond_to?(:to_hash)
|
20
20
|
if instance['swagger'] =~ /\A2(\.|\z)/
|
21
|
-
instance = Scorpio::OpenAPI::V2::Document.
|
21
|
+
instance = Scorpio::OpenAPI::V2::Document.new_jsi(instance)
|
22
22
|
elsif instance['openapi'] =~ /\A3(\.|\z)/
|
23
|
-
instance = Scorpio::OpenAPI::V3::Document.
|
23
|
+
instance = Scorpio::OpenAPI::V3::Document.new_jsi(instance)
|
24
24
|
else
|
25
25
|
raise(ArgumentError, "instance does not look like a recognized openapi document")
|
26
26
|
end
|
@@ -83,7 +83,7 @@ module Scorpio
|
|
83
83
|
# A document that defines or describes an API conforming to the OpenAPI Specification v3.
|
84
84
|
#
|
85
85
|
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#oasObject
|
86
|
-
|
86
|
+
module Document
|
87
87
|
module Configurables
|
88
88
|
def scheme
|
89
89
|
nil
|
@@ -126,7 +126,7 @@ module Scorpio
|
|
126
126
|
# A document that defines or describes an API conforming to the OpenAPI Specification v2 (aka Swagger).
|
127
127
|
#
|
128
128
|
# The root document is known as the Swagger Object.
|
129
|
-
|
129
|
+
module Document
|
130
130
|
module Configurables
|
131
131
|
attr_writer :scheme
|
132
132
|
def scheme
|
@@ -174,7 +174,7 @@ module Scorpio
|
|
174
174
|
# Describes a single API operation on a path.
|
175
175
|
#
|
176
176
|
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#operationObject
|
177
|
-
|
177
|
+
module Operation
|
178
178
|
module Configurables
|
179
179
|
def scheme
|
180
180
|
# not applicable; for OpenAPI v3, scheme is specified by servers.
|
@@ -238,7 +238,7 @@ module Scorpio
|
|
238
238
|
end
|
239
239
|
module V2
|
240
240
|
raise(Bug, 'const_defined? Scorpio::OpenAPI::V2::Operation') unless const_defined?(:Operation)
|
241
|
-
|
241
|
+
module Operation
|
242
242
|
module Configurables
|
243
243
|
attr_writer :scheme
|
244
244
|
def scheme
|
@@ -3,7 +3,7 @@ module Scorpio
|
|
3
3
|
# OperationsScope acts as an Enumerable of the Operations for an openapi_document,
|
4
4
|
# and offers subscripting by operationId.
|
5
5
|
class OperationsScope
|
6
|
-
include JSI::Memoize
|
6
|
+
include JSI::Util::Memoize
|
7
7
|
|
8
8
|
# @param openapi_document [Scorpio::OpenAPI::Document]
|
9
9
|
def initialize(openapi_document)
|
@@ -6,7 +6,7 @@ module Scorpio
|
|
6
6
|
# An object representing a Server.
|
7
7
|
#
|
8
8
|
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#serverObject
|
9
|
-
|
9
|
+
module Server
|
10
10
|
# expands this server's #url using the given_server_variables. any variables
|
11
11
|
# that are in the url but not in the given server variables are filled in
|
12
12
|
# using the default value for the variable.
|
data/lib/scorpio/request.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Scorpio
|
2
2
|
class Request
|
3
3
|
SUPPORTED_REQUEST_MEDIA_TYPES = ['application/json', 'application/x-www-form-urlencoded']
|
4
|
+
FALLBACK_CONTENT_TYPE = 'application/x-www-form-urlencoded'
|
5
|
+
|
4
6
|
def self.best_media_type(media_types)
|
5
7
|
if media_types.size == 1
|
6
8
|
media_types.first
|
@@ -208,11 +210,6 @@ module Scorpio
|
|
208
210
|
operation.request_schema(media_type: media_type)
|
209
211
|
end
|
210
212
|
|
211
|
-
# @return [Class subclassing JSI::Base]
|
212
|
-
def request_schema_class(media_type: self.media_type)
|
213
|
-
JSI.class_for_schema(request_schema(media_type: media_type))
|
214
|
-
end
|
215
|
-
|
216
213
|
# builds a Faraday connection with this Request's faraday_builder and faraday_adapter.
|
217
214
|
# passes a given proc yield_ur to middleware to yield an Ur for requests made with the connection.
|
218
215
|
#
|
@@ -222,8 +219,9 @@ module Scorpio
|
|
222
219
|
Faraday.new do |faraday_connection|
|
223
220
|
faraday_builder.call(faraday_connection)
|
224
221
|
if yield_ur
|
225
|
-
::Ur::Faraday # autoload trigger
|
226
|
-
|
222
|
+
-> { ::Ur::Faraday }.() # autoload trigger
|
223
|
+
|
224
|
+
faraday_connection.response(:yield_ur, schemas: Set[Scorpio::Ur.schema], logger: self.logger, &yield_ur)
|
227
225
|
end
|
228
226
|
faraday_connection.adapter(*faraday_adapter)
|
229
227
|
end
|
@@ -322,8 +320,14 @@ module Scorpio
|
|
322
320
|
if user_agent
|
323
321
|
headers['User-Agent'] = user_agent
|
324
322
|
end
|
325
|
-
if
|
326
|
-
|
323
|
+
if !content_type_header
|
324
|
+
if media_type
|
325
|
+
headers['Content-Type'] = media_type
|
326
|
+
else
|
327
|
+
# I'd rather not have a default content-type, but if none is set then the HTTP adapter sets this to
|
328
|
+
# application/x-www-form-urlencoded and issues a warning about it.
|
329
|
+
headers['Content-Type'] = FALLBACK_CONTENT_TYPE
|
330
|
+
end
|
327
331
|
end
|
328
332
|
if self.headers
|
329
333
|
headers.update(self.headers)
|