apiture 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apiture/api_builder.rb +2 -3
- data/lib/apiture/swagger/operation.rb +1 -1
- data/lib/apiture/swagger/parser.rb +8 -7
- data/lib/apiture/swagger/security.rb +1 -1
- data/lib/apiture/swagger/specification.rb +1 -1
- data/lib/apiture/version.rb +1 -1
- data/spec/apiture/swagger/parser_spec.rb +2 -2
- data/spec/apiture/swagger/specification_spec.rb +7 -6
- data/spec/files/github.json +23 -15
- data/spec/files/harvest.json +5 -3
- data/spec/files/honeybadger.json +5 -3
- data/spec/files/mandrill.json +5 -3
- data/spec/files/pivotal_tracker.json +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 987570957cf2e6c779b9c3ccb5fa06a52f008ef8
|
4
|
+
data.tar.gz: 058c845cfc7ae48422c7f1122c0eacc485099032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3efce36770c2060e613adf6c5491015ac85dcdf420b6a00a99c0dc76c7f4419c594b10c1d1b8acb5cd677c21a744d193c68776090f8e80b29c24294dac8cc72e
|
7
|
+
data.tar.gz: b5fdd0338d28917d4c55982822386ad251f852a1cb1e7697b8313503bdf9515fa04d9b6bf544fe874970f83e9e3b2f523451520a725503bb7f148d4fcad6f487
|
data/lib/apiture/api_builder.rb
CHANGED
@@ -80,8 +80,6 @@ module Apiture
|
|
80
80
|
(operation.produces && operation.produces.first) ||
|
81
81
|
(spec.produces && spec.produces.first)
|
82
82
|
|
83
|
-
security = operation.security || spec.security
|
84
|
-
|
85
83
|
use Apiture::Middleware::Debug
|
86
84
|
use Apiture::Middleware::SetHeader, 'User-Agent' => "apiture-rb/#{Apiture::VERSION}"
|
87
85
|
|
@@ -93,8 +91,9 @@ module Apiture
|
|
93
91
|
use Apiture::Middleware::SetHeader, 'Accept' => produces
|
94
92
|
end
|
95
93
|
|
94
|
+
security = operation.security || spec.security
|
96
95
|
security_ids = if security
|
97
|
-
security.
|
96
|
+
security.map(&:id)
|
98
97
|
else
|
99
98
|
if operation.security_definitions && !operation.security_definitions.empty?
|
100
99
|
[operation.security_definitions.keys.first]
|
@@ -19,9 +19,9 @@ module Apiture
|
|
19
19
|
list :parameters, validate: true
|
20
20
|
list :responses, validate: true
|
21
21
|
list :schemes
|
22
|
+
list :security, validate: true
|
22
23
|
|
23
24
|
hash :security_definitions, validate: true
|
24
|
-
hash :security, validate: true
|
25
25
|
|
26
26
|
def initialize(id)
|
27
27
|
super()
|
@@ -29,7 +29,7 @@ module Apiture
|
|
29
29
|
specification.produces = json['produces'] || []
|
30
30
|
specification.consumes = json['consumes'] || []
|
31
31
|
build_security_definition_hash(specification, json)
|
32
|
-
|
32
|
+
build_security_node_list(specification, json)
|
33
33
|
specification.paths = build_node_hash(Path, json, 'paths') do |path, path_json|
|
34
34
|
trace = [path.id]
|
35
35
|
[:get, :put, :post, :delete, :options, :head, :patch].each do |method|
|
@@ -49,7 +49,7 @@ module Apiture
|
|
49
49
|
trace.shift
|
50
50
|
end
|
51
51
|
build_security_definition_hash(op, json)
|
52
|
-
|
52
|
+
build_security_node_list(op, op_json)
|
53
53
|
path.send("#{method}=".to_sym, op)
|
54
54
|
trace.shift
|
55
55
|
end
|
@@ -71,14 +71,15 @@ module Apiture
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
74
|
+
def build_security_node_list(parent_node, json)
|
75
75
|
# leave security nil to defer security to parent. An empty hash means
|
76
76
|
# no security.
|
77
77
|
if sec_json = json['security']
|
78
|
-
parent_node.security = sec_json.
|
79
|
-
|
80
|
-
security
|
81
|
-
|
78
|
+
parent_node.security = sec_json.map do |h|
|
79
|
+
security_id = h.keys.first
|
80
|
+
security = Security.new(security_id)
|
81
|
+
security.scopes = h[security_id]
|
82
|
+
security
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
@@ -19,13 +19,13 @@ module Apiture
|
|
19
19
|
list :consumes
|
20
20
|
list :produces
|
21
21
|
list :tags, validate: true
|
22
|
+
list :security, validate: true
|
22
23
|
|
23
24
|
hash :paths, validate: true
|
24
25
|
hash :definitions, validate: true
|
25
26
|
hash :parameters, validate: true
|
26
27
|
hash :responses, validate: true
|
27
28
|
hash :security_definitions, validate: true
|
28
|
-
hash :security, validate: true
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/apiture/version.rb
CHANGED
@@ -26,7 +26,7 @@ describe Apiture::Swagger::Parser do
|
|
26
26
|
expect(api_token.in).to eq :header
|
27
27
|
expect(api_token.name).to eq "X-TrackerToken"
|
28
28
|
|
29
|
-
security = specification.security
|
29
|
+
security = specification.security.detect { |sec| sec.id == 'apiToken' }
|
30
30
|
expect(security).to_not be_nil
|
31
31
|
|
32
32
|
expect(specification.produces).to include "application/json"
|
@@ -94,7 +94,7 @@ describe Apiture::Swagger::Parser do
|
|
94
94
|
it "should parse a swagger specification with operation specific security" do
|
95
95
|
specification = Apiture::Swagger::Parser.new.parse(load_spec('github'))
|
96
96
|
op = specification.paths["/applications/{clientId}/tokens/{accessToken}"].get
|
97
|
-
expect(op.security
|
97
|
+
expect(op.security.detect { |sec| sec.id == 'basic' }).to_not be_nil
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should parse nested schema objects" do
|
@@ -8,12 +8,13 @@ describe Apiture::Swagger::Specification do
|
|
8
8
|
|
9
9
|
security = Apiture::Swagger::Security.new('oauth')
|
10
10
|
security.scopes = ['email']
|
11
|
-
spec.security =
|
11
|
+
spec.security = [security]
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
expect(
|
16
|
-
|
17
|
-
expect(
|
13
|
+
h = spec.serializable_hash
|
14
|
+
security_list = h['security']
|
15
|
+
expect(security_list).to_not be_nil
|
16
|
+
security = security_list.detect { |sec| sec.keys.first == 'oauth' }
|
17
|
+
expect(security).to_not be_nil
|
18
|
+
expect(security['oauth']).to eq ['email']
|
18
19
|
end
|
19
20
|
end
|
data/spec/files/github.json
CHANGED
@@ -48,9 +48,11 @@
|
|
48
48
|
}
|
49
49
|
},
|
50
50
|
|
51
|
-
"security":
|
52
|
-
|
53
|
-
|
51
|
+
"security": [
|
52
|
+
{
|
53
|
+
"oauth2": []
|
54
|
+
}
|
55
|
+
],
|
54
56
|
|
55
57
|
"paths": {
|
56
58
|
"/user": {
|
@@ -63,9 +65,11 @@
|
|
63
65
|
"get": {
|
64
66
|
"summary": "List email addresses for a user",
|
65
67
|
"operationId": "getUserEmails",
|
66
|
-
"security":
|
67
|
-
|
68
|
-
|
68
|
+
"security": [
|
69
|
+
{
|
70
|
+
"basic": ["user:email"]
|
71
|
+
}
|
72
|
+
]
|
69
73
|
}
|
70
74
|
},
|
71
75
|
"/user/repos": {
|
@@ -116,12 +120,14 @@
|
|
116
120
|
"get": {
|
117
121
|
"summary": "List organizations for the authenticated user",
|
118
122
|
"operationId": "getUserOrgs",
|
119
|
-
"security":
|
120
|
-
|
121
|
-
"
|
122
|
-
|
123
|
-
|
124
|
-
|
123
|
+
"security": [
|
124
|
+
{
|
125
|
+
"oauth2": [
|
126
|
+
"user",
|
127
|
+
"read:org"
|
128
|
+
]
|
129
|
+
}
|
130
|
+
]
|
125
131
|
}
|
126
132
|
},
|
127
133
|
"/orgs/{org}/repos": {
|
@@ -177,9 +183,11 @@
|
|
177
183
|
"in": "path",
|
178
184
|
"required": true
|
179
185
|
}],
|
180
|
-
"security":
|
181
|
-
|
182
|
-
|
186
|
+
"security": [
|
187
|
+
{
|
188
|
+
"basic": []
|
189
|
+
}
|
190
|
+
]
|
183
191
|
}
|
184
192
|
}
|
185
193
|
}
|
data/spec/files/harvest.json
CHANGED
data/spec/files/honeybadger.json
CHANGED
data/spec/files/mandrill.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calvin Yu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|