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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43c92cdbf01d3a08d09f7c9f142326e68d571933
4
- data.tar.gz: 64c58f798e154f7508efc272ee60cf9095f18b3c
3
+ metadata.gz: 987570957cf2e6c779b9c3ccb5fa06a52f008ef8
4
+ data.tar.gz: 058c845cfc7ae48422c7f1122c0eacc485099032
5
5
  SHA512:
6
- metadata.gz: c7e72e4e47a2b83fc42324f71b21c363257cac465cac965330888d7310cc3a82a9e01a75c407cb7290f97e059c00570ed13b5cbbdedad00ec393d097a46d5109
7
- data.tar.gz: 4e26f7d33a5d0ed70b12c77017d2eb4574c52a3622bf5da0c0dcbcceb3fd4819b1194c9721695d330cf838f3ab30c673ed6bfbd6a7e46d6f8e296591b18bcba9
6
+ metadata.gz: 3efce36770c2060e613adf6c5491015ac85dcdf420b6a00a99c0dc76c7f4419c594b10c1d1b8acb5cd677c21a744d193c68776090f8e80b29c24294dac8cc72e
7
+ data.tar.gz: b5fdd0338d28917d4c55982822386ad251f852a1cb1e7697b8313503bdf9515fa04d9b6bf544fe874970f83e9e3b2f523451520a725503bb7f148d4fcad6f487
@@ -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.keys
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
- build_security_hash(specification, json)
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
- build_security_hash(op, op_json)
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 build_security_hash(parent_node, json)
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.reduce({}) do |memo, (k,v)|
79
- memo[k] = security = Security.new(k)
80
- security.scopes = v
81
- memo
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
@@ -13,7 +13,7 @@ module Apiture
13
13
  end
14
14
 
15
15
  def serializable_hash
16
- scopes || []
16
+ { id => scopes || [] }
17
17
  end
18
18
 
19
19
  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
@@ -1,3 +1,3 @@
1
1
  module Apiture
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -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['apiToken']
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["basic"]).to_not be_nil
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 = { 'oauth' => security }
11
+ spec.security = [security]
12
12
 
13
- hash = spec.serializable_hash
14
- security_hash = hash['security']
15
- expect(security_hash).to_not be_nil
16
- scopes = security_hash['oauth']
17
- expect(scopes).to eq ['email']
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
@@ -48,9 +48,11 @@
48
48
  }
49
49
  },
50
50
 
51
- "security": {
52
- "oauth2": []
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
- "basic": ["user:email"]
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
- "oauth2": [
121
- "user",
122
- "read:org"
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
- "basic": []
182
- }
186
+ "security": [
187
+ {
188
+ "basic": []
189
+ }
190
+ ]
183
191
  }
184
192
  }
185
193
  }
@@ -24,9 +24,11 @@
24
24
  }
25
25
  },
26
26
 
27
- "security": {
28
- "oauth2": []
29
- },
27
+ "security": [
28
+ {
29
+ "oauth2": []
30
+ }
31
+ ],
30
32
 
31
33
  "paths": {
32
34
  "/invoices": {
@@ -74,7 +74,9 @@
74
74
  }
75
75
  },
76
76
 
77
- "security": {
78
- "authToken": []
79
- }
77
+ "security": [
78
+ {
79
+ "authToken": []
80
+ }
81
+ ]
80
82
  }
@@ -23,9 +23,11 @@
23
23
  }
24
24
  },
25
25
 
26
- "security": {
27
- "key": []
28
- },
26
+ "security": [
27
+ {
28
+ "key": []
29
+ }
30
+ ],
29
31
 
30
32
  "paths": {
31
33
  "/users/info.json": {
@@ -88,7 +88,9 @@
88
88
  }
89
89
  },
90
90
 
91
- "security": {
92
- "apiToken": []
93
- }
91
+ "security": [
92
+ {
93
+ "apiToken": []
94
+ }
95
+ ]
94
96
  }
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.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-06-11 00:00:00.000000000 Z
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler