swagger-blocks 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b866c42150b355a3435ee64d3e614c8833f66e0
4
- data.tar.gz: 25c4cce082108016db076e702d8800a04190a2e7
3
+ metadata.gz: a6055711e3ea9c391a362d51dab6494f1fb4c8e8
4
+ data.tar.gz: 03248ded0ff0ba04e55345a94ec0ce82d3e4134b
5
5
  SHA512:
6
- metadata.gz: 43785e40a8cd10c442e7691cda08c23270218bbaa1de1a7ff96100ce2401230c36f4868bda1f6d3e13fc383dfda65f2a00510c291e697cf70ddcd9e3c18419b8
7
- data.tar.gz: 6e9b4abc905314c968557731fd758e9cc28fda85c42e7cf389ab4b24a2caaadedb085717ab4c71e4c5f54dfb5e0118d2a2494104114348d2d690efcdebc7682c
6
+ metadata.gz: 344b4923bf905546cd1242854220f0da1b4cafc0510286e14c1fecb33fac05d7056218a0cede84afd989a2a277d9b7537d5d06964ba14ee3b9b2b9ff793f0537
7
+ data.tar.gz: e81f1506e5286e47168e83e65e5c2e130c108fc66805c383da4266c891c8dd13de5b9bbea01099c7da7d1273d9173716f7cfa87c16b6bcc4c8d86da15a0294df
data/README.md CHANGED
@@ -45,6 +45,9 @@ class PetsController < ActionController::Base
45
45
  operation :get do
46
46
  key :description, 'Returns a single pet if the user has access'
47
47
  key :operationId, 'findPetById'
48
+ key :tags, [
49
+ 'pet'
50
+ ]
48
51
  parameter do
49
52
  key :name, :id
50
53
  key :in, :path
@@ -75,6 +78,9 @@ class PetsController < ActionController::Base
75
78
  'application/json',
76
79
  'text/html',
77
80
  ]
81
+ key :tags, [
82
+ 'pet'
83
+ ]
78
84
  parameter do
79
85
  key :name, :tags
80
86
  key :in, :query
@@ -116,6 +122,9 @@ class PetsController < ActionController::Base
116
122
  key :produces, [
117
123
  'application/json'
118
124
  ]
125
+ key :tags, [
126
+ 'pet'
127
+ ]
119
128
  parameter do
120
129
  key :name, :pet
121
130
  key :in, :body
@@ -231,6 +240,14 @@ class ApidocsController < ActionController::Base
231
240
  key :name, 'MIT'
232
241
  end
233
242
  end
243
+ tags do
244
+ key :name, 'pet'
245
+ key :description, 'Pets operations'
246
+ externalDocs do
247
+ key :description, 'Find more info here'
248
+ key :url, 'https://swagger.io'
249
+ end
250
+ end
234
251
  key :host, 'petstore.swagger.wordnik.com'
235
252
  key :basePath, '/api'
236
253
  key :consumes, ['application/json']
@@ -261,6 +278,60 @@ That is the only line necessary to build the full [root Swagger object](https://
261
278
 
262
279
  Now, simply point Swagger UI at `/apidocs` and everything should Just Work™. If you change any of the Swagger block definitions, you can simply refresh Swagger UI to see the changes.
263
280
 
281
+ #### Security handling
282
+
283
+ To support Swagger's definitions for API key auth or OAuth2, use `security_definition` in your `swagger_root`:
284
+
285
+ ```Ruby
286
+ swagger_root do
287
+ key :swagger, '2.0'
288
+
289
+ # ...
290
+
291
+ security_definition :api_key do
292
+ key :type, :apiKey
293
+ key :name, :api_key
294
+ key :in, :header
295
+ end
296
+ security_definition :petstore_auth do
297
+ key :type, :oauth2
298
+ key :authorizationUrl, 'http://swagger.io/api/oauth/dialog'
299
+ key :flow, :implicit
300
+ scopes do
301
+ key 'write:pets', 'modify pets in your account'
302
+ key 'read:pets', 'read your pets'
303
+ end
304
+ end
305
+ end
306
+ ```
307
+
308
+ You can then apply [security requirement objects](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securityRequirementObject) to the entire `swagger_root`, or to individual operations:
309
+
310
+ ```Ruby
311
+ swagger_path '/pets/{id}' do
312
+ operation :get do
313
+
314
+ # ...
315
+
316
+ security do
317
+ key :api_key, []
318
+ end
319
+ security do
320
+ key :petstore_auth, ['write:pets', 'read:pets']
321
+ end
322
+ end
323
+ end
324
+ ```
325
+
326
+ #### Writing JSON to a file
327
+
328
+ If you are not serving the JSON directly and need to write it to a file for some reason, you can easily use `build_root_json` for that as well:
329
+
330
+ ```Ruby
331
+ swagger_data = Swagger::Blocks.build_root_json(SWAGGERED_CLASSES)
332
+ File.open('swagger.json', 'w') { |file| file.write(swagger_data.to_json) }
333
+ ```
334
+
264
335
  ### Swagger 1.2 example (Rails)
265
336
 
266
337
  See the [v1.2 docs](https://github.com/fotinakis/swagger-blocks/blob/master/README_v1_2.md).
data/README_v1_2.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Swagger 1.2 example (Rails)
2
2
 
3
+ **NOTE: this is old, you probably want to [use the latest syntax](https://github.com/fotinakis/swagger-blocks).**
4
+
3
5
  This is a simplified example based on the objects in the Petstore [Swagger Sample App](http://petstore.swagger.wordnik.com/#!/pet). For a more complex and complete example, see the [swagger_blocks_spec.rb](https://github.com/fotinakis/swagger-blocks/blob/master/spec/lib/swagger_blocks_spec.rb) file.
4
6
 
5
7
  Also note that Rails is not required, you can use Swagger::Blocks with any Ruby web framework.
@@ -400,6 +400,9 @@ module Swagger
400
400
  # v1.2: http://goo.gl/PvwUXj#516-scope-object
401
401
  class ScopeNode < Node; end
402
402
 
403
+ # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#scopes-object
404
+ class ScopesNode < Node; end
405
+
403
406
  # v1.2: http://goo.gl/PvwUXj#517-grant-types-object
404
407
  class GrantTypesNode < Node
405
408
  def implicit(&block)
@@ -551,9 +554,8 @@ module Swagger
551
554
  class SecuritySchemeNode < Node
552
555
  # TODO support ^x- Vendor Extensions
553
556
 
554
- def scope(name, description)
555
- self.data[:scopes] ||= {}
556
- self.data[:scopes][name] = description
557
+ def scopes(&block)
558
+ self.data[:scopes] = Swagger::Blocks::ScopesNode.call(version: version, &block)
557
559
  end
558
560
  end
559
561
 
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Blocks
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.2'
4
4
  end
5
5
  end
@@ -23,6 +23,22 @@
23
23
  "produces": [
24
24
  "application/json"
25
25
  ],
26
+ "securityDefinitions": {
27
+ "api_key": {
28
+ "type": "apiKey",
29
+ "name": "api_key",
30
+ "in": "header"
31
+ },
32
+ "petstore_auth": {
33
+ "type": "oauth2",
34
+ "authorizationUrl": "http://swagger.io/api/oauth/dialog",
35
+ "flow": "implicit",
36
+ "scopes": {
37
+ "write:pets": "modify pets in your account",
38
+ "read:pets": "read your pets"
39
+ }
40
+ }
41
+ },
26
42
  "tags": [
27
43
  {
28
44
  "name": "pet",
@@ -149,7 +165,18 @@
149
165
  "$ref": "#/definitions/ErrorModel"
150
166
  }
151
167
  }
152
- }
168
+ },
169
+ "security": [
170
+ {
171
+ "api_key": []
172
+ },
173
+ {
174
+ "petstore_auth": [
175
+ "write:pets",
176
+ "read:pets"
177
+ ]
178
+ }
179
+ ]
153
180
  },
154
181
  "delete": {
155
182
  "description": "deletes a single pet based on the ID supplied",
@@ -28,6 +28,20 @@ class PetControllerV2
28
28
  key :schemes, ['http']
29
29
  key :consumes, ['application/json']
30
30
  key :produces, ['application/json']
31
+ security_definition :api_key do
32
+ key :type, :apiKey
33
+ key :name, :api_key
34
+ key :in, :header
35
+ end
36
+ security_definition :petstore_auth do
37
+ key :type, :oauth2
38
+ key :authorizationUrl, 'http://swagger.io/api/oauth/dialog'
39
+ key :flow, :implicit
40
+ scopes do
41
+ key 'write:pets', 'modify pets in your account'
42
+ key 'read:pets', 'read your pets'
43
+ end
44
+ end
31
45
  tags do
32
46
  key :name, 'pet'
33
47
  key :description, 'Pets operations'
@@ -143,6 +157,12 @@ class PetControllerV2
143
157
  key :'$ref', :ErrorModel
144
158
  end
145
159
  end
160
+ security do
161
+ key :api_key, []
162
+ end
163
+ security do
164
+ key :petstore_auth, ['write:pets', 'read:pets']
165
+ end
146
166
  end
147
167
  operation :delete do
148
168
  key :description, 'deletes a single pet based on the ID supplied'
@@ -234,6 +254,9 @@ describe 'Swagger::Blocks v2' do
234
254
  expect(actual['paths']).to be
235
255
  expect(actual['paths']['/pets']).to be
236
256
  expect(actual['paths']['/pets']).to eq(data['paths']['/pets'])
257
+ expect(actual['paths']['/pets/{id}']).to be
258
+ expect(actual['paths']['/pets/{id}']['get']).to be
259
+ expect(actual['paths']['/pets/{id}']['get']).to eq(data['paths']['/pets/{id}']['get'])
237
260
  expect(actual['paths']).to eq(data['paths'])
238
261
  expect(actual['definitions']).to eq(data['definitions'])
239
262
  expect(actual).to eq(data)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger-blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Fotinakis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler