swagger-blocks 1.2.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab191a7e9a7e6ce98804cf2bc2758b410d45a180
4
- data.tar.gz: 1acad4d0e8ceef63c8cccc30e0d45a0080ad0e16
3
+ metadata.gz: 9c7496406adf0203039b05240d05884c3797dbe6
4
+ data.tar.gz: 04a0a51888a8984b63b0ba0e5afd1e7b1e1f69d2
5
5
  SHA512:
6
- metadata.gz: eb3e2ec51fe800b455c77323d6810703350def5daa5b8d6955c7e67511c76a5db08a1da20a99248050a578967ef18ab9b6f9d7ab3a276dd849278537e6059498
7
- data.tar.gz: f05b5583475152d4e73934ac05d5ed3c8af9e0c24a1a79d7f6549fd5fb151e8c97c484ee0e4e0cdb0f64962e3a5dac8b20a653f2d4921232e2492587f8e35251
6
+ metadata.gz: 8741eca62a459b7efa76feafd0437f4659d964013776ac719cf84d654139917ea2d64827583dd2b1236014bdf728d49b37138e081f7d7dffe59340da783d5d38
7
+ data.tar.gz: aa8fa55c5e433bf6dd0aa02ab64a527639985a9409ec8e518e300db2b972b35c17134b92260375ae6bec2dc51b0e2774d70382a338793028938dc78f62f3cbb1
@@ -1,6 +1,10 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  rvm:
3
5
  - 1.9.3
4
6
  - 2.1.1
5
7
  - ruby-head
8
+ before_install:
9
+ - gem update bundler
6
10
  script: bundle exec rspec
data/README.md CHANGED
@@ -17,7 +17,7 @@ It helps you write API docs in the [Swagger](https://helloreverb.com/developers/
17
17
 
18
18
  ## Swagger UI demo
19
19
 
20
- http://petstore.swagger.wordnik.com/#!/pet
20
+ http://petstore.swagger.io/
21
21
 
22
22
  ![swagger-sample](https://cloud.githubusercontent.com/assets/75300/5822830/4769805c-a08c-11e4-9efe-d57cf0f752e0.png)
23
23
 
@@ -331,6 +331,37 @@ The `key` block simply takes the value you give and puts it directly into the fi
331
331
  key :foo, {some_complex: {nested_object: true}}
332
332
  ```
333
333
 
334
+ #### Inline keys
335
+
336
+ It is possible to omit numerous `key` calls using inline hash keys on any block.
337
+
338
+ All three calls are equivalent:
339
+
340
+ ```ruby
341
+ parameter do
342
+ key :paramType, :path
343
+ key :name, :petId
344
+ key :description, 'ID of pet that needs to be fetched'
345
+ key :type, :string
346
+ end
347
+ ```
348
+
349
+ ```ruby
350
+ parameter paramType: :path, name: :petId do
351
+ key :description, 'ID of pet that needs to be fetched'
352
+ key :type, :string
353
+ end
354
+ ```
355
+
356
+ ```ruby
357
+ parameter paramType: :path,
358
+ name: :petId,
359
+ description: 'ID of pet that needs to be fetched',
360
+ type: :string
361
+ ```
362
+
363
+ These inline keys can be used on any block, not just `parameter` blocks.
364
+
334
365
  #### Writing JSON to a file
335
366
 
336
367
  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:
@@ -340,6 +371,16 @@ swagger_data = Swagger::Blocks.build_root_json(SWAGGERED_CLASSES)
340
371
  File.open('swagger.json', 'w') { |file| file.write(swagger_data.to_json) }
341
372
  ```
342
373
 
374
+ #### Overriding attributes
375
+
376
+ If certain attributes must be customized on-the-fly, you can merge a hash containing the customized values on the returned JSON. You can wrap ```build_root_json``` inside your own method:
377
+
378
+ ```Ruby
379
+ def build_and_override_root_json(overrides = {})
380
+ Swagger::Blocks.build_root_json(SWAGGERED_CLASSES).merge(overrides)
381
+ end
382
+ ```
383
+
343
384
  ### Swagger 1.2 example (Rails)
344
385
 
345
386
  See the [v1.2 docs](https://github.com/fotinakis/swagger-blocks/blob/master/README_v1_2.md).
@@ -358,8 +399,21 @@ See the [swagger_v2_blocks_spec.rb](https://github.com/fotinakis/swagger-blocks/
358
399
 
359
400
  Throw a ★ on it! :)
360
401
 
402
+ ## Filing issues
403
+
404
+ **Please DO [file an issue](https://github.com/fotinakis/swagger-blocks/issues)**:
405
+
406
+ - If you find a bug or some part of the Swagger 2.0 spec that swagger-blocks does not support.
407
+ - To propose and discuss a code change before submitting a PR for it.
408
+ - To talk about anything related specifically to swagger-blocks, not Swagger itself.
409
+
410
+ **Please DO NOT file an issue**:
411
+
412
+ - If you have a question about Swagger or Swagger UI. We simply cannot support all Swagger-related questions. Check out the http://swagger.io/community/ for help.
413
+
361
414
  ## Release notes
362
415
 
416
+ * v1.3.0: Added support for condensed syntax via inline keys on every block.
363
417
  * v1.2.0: Improved support for `$ref` Path Item Object parameters.
364
418
  * v1.1.3: Rename tags directive to tag for consistency.
365
419
  * v1.1.2: Bugfix for security definition support.
@@ -113,8 +113,8 @@ module Swagger
113
113
  # v1.2: http://goo.gl/PvwUXj#51-resource-listing
114
114
  # v2.0: Defines a Swagger Object
115
115
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#swagger-object
116
- def swagger_root(&block)
117
- @swagger_root_node ||= Swagger::Blocks::RootNode.call(&block)
116
+ def swagger_root(inline_keys = nil, &block)
117
+ @swagger_root_node ||= Swagger::Blocks::RootNode.call(inline_keys: inline_keys, &block)
118
118
  end
119
119
 
120
120
  # v1.2: Defines a Swagger API Declaration.
@@ -122,7 +122,7 @@ module Swagger
122
122
  # v1.2:
123
123
  # v1.2: @param resource_name [Symbol] An identifier for this API. All swagger_api_root declarations
124
124
  # v1.2: with the same resource_name will be into a single API root node.
125
- def swagger_api_root(resource_name, &block)
125
+ def swagger_api_root(resource_name, inline_keys = nil, &block)
126
126
  resource_name = resource_name.to_sym
127
127
 
128
128
  # Map of path names to ApiDeclarationNodes.
@@ -136,7 +136,7 @@ module Swagger
136
136
  api_node.instance_eval(&block)
137
137
  else
138
138
  # First time we've seen this `swagger_api_root :resource_name`.
139
- api_node = Swagger::Blocks::ApiDeclarationNode.call(version: '1.2', &block)
139
+ api_node = Swagger::Blocks::ApiDeclarationNode.call(version: '1.2', inline_keys: inline_keys, &block)
140
140
  end
141
141
 
142
142
  # Add it into the resource_name to node map (may harmlessly overwrite the same object).
@@ -165,16 +165,16 @@ module Swagger
165
165
 
166
166
  # v1.2: Defines a Swagger Model.
167
167
  # v1.2: http://goo.gl/PvwUXj#526-models-object
168
- def swagger_model(name, &block)
168
+ def swagger_model(name, inline_keys = nil, &block)
169
169
  @swagger_models_node ||= Swagger::Blocks::ModelsNode.new
170
170
  @swagger_models_node.version = '1.2'
171
- @swagger_models_node.model(name, &block)
171
+ @swagger_models_node.model(name, inline_keys, &block)
172
172
  end
173
173
 
174
174
  # v2.0: Defines a Swagger Definition Schema,
175
175
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#definitionsObject and
176
176
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#schema-object
177
- def swagger_schema(name, &block)
177
+ def swagger_schema(name, inline_keys = nil, &block)
178
178
  @swagger_schema_node_map ||= {}
179
179
 
180
180
  schema_node = @swagger_schema_node_map[name]
@@ -183,7 +183,7 @@ module Swagger
183
183
  schema_node.instance_eval(&block)
184
184
  else
185
185
  # First time we've seen this schema_node
186
- @swagger_schema_node_map[name] = Swagger::Blocks::SchemaNode.call(version: '2.0', &block)
186
+ @swagger_schema_node_map[name] = Swagger::Blocks::SchemaNode.call(version: '2.0', inline_keys: inline_keys, &block)
187
187
  end
188
188
  end
189
189
 
@@ -217,7 +217,8 @@ module Swagger
217
217
  instance = new
218
218
  instance.name = options[:name] if options[:name]
219
219
  instance.version = options[:version]
220
- instance.instance_eval(&block)
220
+ instance.keys options[:inline_keys]
221
+ instance.instance_eval(&block) if block
221
222
  instance
222
223
  end
223
224
 
@@ -248,6 +249,10 @@ module Swagger
248
249
  @data ||= {}
249
250
  end
250
251
 
252
+ def keys(data)
253
+ self.data.merge!(data) if data
254
+ end
255
+
251
256
  def key(key, value)
252
257
  self.data[key] = value
253
258
  end
@@ -288,60 +293,60 @@ module Swagger
288
293
  api_paths.include?(api_path)
289
294
  end
290
295
 
291
- def authorization(name, &block)
296
+ def authorization(name, inline_keys = nil, &block)
292
297
  raise NotSupportedError unless is_swagger_1_2?
293
298
 
294
299
  self.data[:authorizations] ||= Swagger::Blocks::ResourceListingAuthorizationsNode.new
295
300
  self.data[:authorizations].version = version
296
- self.data[:authorizations].authorization(name, &block)
301
+ self.data[:authorizations].authorization(name, inline_keys, &block)
297
302
  end
298
303
 
299
- def info(&block)
300
- self.data[:info] = Swagger::Blocks::InfoNode.call(version: version, &block)
304
+ def info(inline_keys = nil, &block)
305
+ self.data[:info] = Swagger::Blocks::InfoNode.call(version: version, inline_keys: inline_keys, &block)
301
306
  end
302
307
 
303
- def api(&block)
308
+ def api(inline_keys = nil, &block)
304
309
  raise NotSupportedError unless is_swagger_1_2?
305
310
 
306
311
  self.data[:apis] ||= []
307
- self.data[:apis] << Swagger::Blocks::ResourceNode.call(version: version, &block)
312
+ self.data[:apis] << Swagger::Blocks::ResourceNode.call(version: version, inline_keys: inline_keys ,&block)
308
313
  end
309
314
 
310
- def parameter(param, &block)
315
+ def parameter(param, inline_keys = nil, &block)
311
316
  raise NotSupportedError unless is_swagger_2_0?
312
317
 
313
318
  # TODO validate 'param' is as per spec
314
319
  self.data[:parameters] ||= {}
315
- self.data[:parameters][param] = Swagger::Blocks::ParameterNode.call(version: version, &block)
320
+ self.data[:parameters][param] = Swagger::Blocks::ParameterNode.call(version: version, inline_keys: inline_keys, &block)
316
321
  end
317
322
 
318
- def response(resp, &block)
323
+ def response(resp, inline_keys = nil, &block)
319
324
  raise NotSupportedError unless is_swagger_2_0?
320
325
 
321
326
  # TODO validate 'resp' is as per spec
322
327
  self.data[:responses] ||= {}
323
- self.data[:responses][resp] = Swagger::Blocks::ResponseNode.call(version: version, &block)
328
+ self.data[:responses][resp] = Swagger::Blocks::ResponseNode.call(version: version, inline_keys: inline_keys, &block)
324
329
  end
325
330
 
326
- def security_definition(name, &block)
331
+ def security_definition(name, inline_keys = nil, &block)
327
332
  raise NotSupportedError unless is_swagger_2_0?
328
333
 
329
334
  self.data[:securityDefinitions] ||= {}
330
- self.data[:securityDefinitions][name] = Swagger::Blocks::SecuritySchemeNode.call(version: version, &block)
335
+ self.data[:securityDefinitions][name] = Swagger::Blocks::SecuritySchemeNode.call(version: version, inline_keys: inline_keys, &block)
331
336
  end
332
337
 
333
- def security(&block)
338
+ def security(inline_keys = nil, &block)
334
339
  raise NotSupportedError unless is_swagger_2_0?
335
340
 
336
341
  self.data[:security] ||= []
337
- self.data[:security] << Swagger::Blocks::SecurityRequirementNode.call(version: version, &block)
342
+ self.data[:security] << Swagger::Blocks::SecurityRequirementNode.call(version: version, inline_keys: inline_keys, &block)
338
343
  end
339
344
 
340
- def tag(&block)
345
+ def tag(inline_keys = nil, &block)
341
346
  raise NotSupportedError unless is_swagger_2_0?
342
347
 
343
348
  self.data[:tags] ||= []
344
- self.data[:tags] << Swagger::Blocks::TagNode.call(version: version, &block)
349
+ self.data[:tags] << Swagger::Blocks::TagNode.call(version: version, inline_keys: inline_keys, &block)
345
350
  end
346
351
 
347
352
  # Use 'tag' instead.
@@ -355,8 +360,8 @@ module Swagger
355
360
  # v1.2: NOTE: in the spec this is different than API Declaration authorizations.
356
361
  # v1.2: http://goo.gl/PvwUXj#514-authorizations-object
357
362
  class ResourceListingAuthorizationsNode < Node
358
- def authorization(name, &block)
359
- self.data[name] = Swagger::Blocks::ResourceListingAuthorizationNode.call(version: version, &block)
363
+ def authorization(name, inline_keys = nil, &block)
364
+ self.data[name] = Swagger::Blocks::ResourceListingAuthorizationNode.call(version: version, inline_keys: inline_keys, &block)
360
365
  end
361
366
  end
362
367
 
@@ -365,33 +370,33 @@ module Swagger
365
370
  class ResourceListingAuthorizationNode < Node
366
371
  GRANT_TYPES = [:implicit, :authorization_code].freeze
367
372
 
368
- def scope(&block)
373
+ def scope(inline_keys = nil, &block)
369
374
  self.data[:scopes] ||= []
370
- self.data[:scopes] << Swagger::Blocks::ScopeNode.call(version: version, &block)
375
+ self.data[:scopes] << Swagger::Blocks::ScopeNode.call(version: version, inline_keys: inline_keys, &block)
371
376
  end
372
377
 
373
- def grant_type(name, &block)
378
+ def grant_type(name, inline_keys = nil, &block)
374
379
  raise ArgumentError.new("#{name} not in #{GRANT_TYPES}") if !GRANT_TYPES.include?(name)
375
380
  self.data[:grantTypes] ||= Swagger::Blocks::GrantTypesNode.new
376
381
  self.data[:grantTypes].version = version
377
- self.data[:grantTypes].implicit(&block) if name == :implicit
378
- self.data[:grantTypes].authorization_code(&block) if name == :authorization_code
382
+ self.data[:grantTypes].implicit(inline_keys, &block) if name == :implicit
383
+ self.data[:grantTypes].authorization_code(inline_keys, &block) if name == :authorization_code
379
384
  end
380
385
  end
381
386
 
382
387
  # v1.2: http://goo.gl/PvwUXj#513-info-object
383
388
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#infoObject
384
389
  class InfoNode < Node
385
- def contact(&block)
390
+ def contact(inline_keys = nil, &block)
386
391
  raise NotSupportedError unless is_swagger_2_0?
387
392
 
388
- self.data[:contact] = Swagger::Blocks::ContactNode.call(version: version, &block)
393
+ self.data[:contact] = Swagger::Blocks::ContactNode.call(version: version, inline_keys: inline_keys, &block)
389
394
  end
390
395
 
391
- def license(&block)
396
+ def license(inline_keys = nil, &block)
392
397
  raise NotSupportedError unless is_swagger_2_0?
393
398
 
394
- self.data[:license] = Swagger::Blocks::LicenseNode.call(version: version, &block)
399
+ self.data[:license] = Swagger::Blocks::LicenseNode.call(version: version, inline_keys: inline_keys, &block)
395
400
  end
396
401
  end
397
402
 
@@ -409,12 +414,12 @@ module Swagger
409
414
 
410
415
  # v1.2: http://goo.gl/PvwUXj#517-grant-types-object
411
416
  class GrantTypesNode < Node
412
- def implicit(&block)
413
- self.data[:implicit] = Swagger::Blocks::ImplicitNode.call(version: version, &block)
417
+ def implicit(inline_keys, &block)
418
+ self.data[:implicit] = Swagger::Blocks::ImplicitNode.call(inline_keys: inline_keys, version: version, &block)
414
419
  end
415
420
 
416
- def authorization_code(&block)
417
- self.data[:authorization_code] = Swagger::Blocks::AuthorizationCodeNode.call(version: version, &block)
421
+ def authorization_code(inline_keys, &block)
422
+ self.data[:authorization_code] = Swagger::Blocks::AuthorizationCodeNode.call(inline_keys: inline_keys, version: version, &block)
418
423
  end
419
424
  end
420
425
 
@@ -430,12 +435,12 @@ module Swagger
430
435
 
431
436
  # v1.2: http://goo.gl/PvwUXj#519-authorization-code-object
432
437
  class AuthorizationCodeNode < Node
433
- def token_request_endpoint(&block)
434
- self.data[:tokenRequestEndpoint] = Swagger::Blocks::TokenRequestEndpointNode.call(version: version, &block)
438
+ def token_request_endpoint(inline_keys = nil, &block)
439
+ self.data[:tokenRequestEndpoint] = Swagger::Blocks::TokenRequestEndpointNode.call(version: version, inline_keys: inline_keys, &block)
435
440
  end
436
441
 
437
- def token_endpoint(&block)
438
- self.data[:tokenEndpoint] = Swagger::Blocks::TokenEndpointNode.call(version: version, &block)
442
+ def token_endpoint(inline_keys = nil, &block)
443
+ self.data[:tokenEndpoint] = Swagger::Blocks::TokenEndpointNode.call(version: version, inline_keys: inline_keys, &block)
439
444
  end
440
445
  end
441
446
 
@@ -451,7 +456,7 @@ module Swagger
451
456
 
452
457
  # v1.2: http://goo.gl/PvwUXj#52-api-declaration
453
458
  class ApiDeclarationNode < Node
454
- def api(&block)
459
+ def api(inline_keys = nil, &block)
455
460
  self.data[:apis] ||= []
456
461
 
457
462
  # Important: to conform with the Swagger spec, merge with any previous API declarations
@@ -461,7 +466,7 @@ module Swagger
461
466
  # http://goo.gl/PvwUXj#522-api-object
462
467
  # - The API Object describes one or more operations on a single path. In the apis array,
463
468
  # there MUST be only one API Object per path.
464
- temp_api_node = Swagger::Blocks::ApiNode.call(version: version, &block)
469
+ temp_api_node = Swagger::Blocks::ApiNode.call(version: version, inline_keys: inline_keys, &block)
465
470
  api_node = self.data[:apis].select do |api|
466
471
  api.data[:path] == temp_api_node.data[:path]
467
472
  end[0] # Embrace Ruby wtfs.
@@ -478,9 +483,9 @@ module Swagger
478
483
 
479
484
  # v1.2: http://goo.gl/PvwUXj#522-api-object
480
485
  class ApiNode < Node
481
- def operation(&block)
486
+ def operation(inline_keys = nil, &block)
482
487
  self.data[:operations] ||= []
483
- self.data[:operations] << Swagger::Blocks::OperationNode.call(version: version, &block)
488
+ self.data[:operations] << Swagger::Blocks::OperationNode.call(version: version, inline_keys: inline_keys, &block)
484
489
  end
485
490
  end
486
491
 
@@ -489,10 +494,10 @@ module Swagger
489
494
  OPERATION_TYPES = [:get, :put, :post, :delete, :options, :head, :patch].freeze
490
495
 
491
496
  # TODO support ^x- Vendor Extensions
492
- def operation(op, &block)
497
+ def operation(op, inline_keys = nil, &block)
493
498
  op = op.to_sym
494
499
  raise ArgumentError.new("#{name} not in #{OPERATION_TYPES}") if !OPERATION_TYPES.include?(op)
495
- self.data[op] = Swagger::Blocks::OperationNode.call(version: version, &block)
500
+ self.data[op] = Swagger::Blocks::OperationNode.call(version: version, inline_keys: inline_keys, &block)
496
501
  end
497
502
  end
498
503
 
@@ -500,51 +505,51 @@ module Swagger
500
505
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#operation-object
501
506
  class OperationNode < Node
502
507
 
503
- def parameter(&block)
508
+ def parameter(inline_keys = nil, &block)
504
509
  self.data[:parameters] ||= []
505
- self.data[:parameters] << Swagger::Blocks::ParameterNode.call(version: version, &block)
510
+ self.data[:parameters] << Swagger::Blocks::ParameterNode.call(version: version, inline_keys: inline_keys, &block)
506
511
  end
507
512
 
508
- def response_message(&block)
513
+ def response_message(inline_keys = nil, &block)
509
514
  raise NotSupportedError unless is_swagger_1_2?
510
515
 
511
516
  self.data[:responseMessages] ||= []
512
- self.data[:responseMessages] << Swagger::Blocks::Node.call(version: version, &block)
517
+ self.data[:responseMessages] << Swagger::Blocks::Node.call(version: version, inline_keys: inline_keys, &block)
513
518
  end
514
519
 
515
- def authorization(name, &block)
520
+ def authorization(name, inline_keys = nil, &block)
516
521
  raise NotSupportedError unless is_swagger_1_2?
517
522
 
518
523
  self.data[:authorizations] ||= Swagger::Blocks::ApiAuthorizationsNode.new
519
524
  self.data[:authorizations].version = version
520
- self.data[:authorizations].authorization(name, &block)
525
+ self.data[:authorizations].authorization(name, inline_keys, &block)
521
526
  end
522
527
 
523
- def items(&block)
528
+ def items(inline_keys = nil, &block)
524
529
  raise NotSupportedError unless is_swagger_1_2?
525
530
 
526
- self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, &block)
531
+ self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, inline_keys: inline_keys, &block)
527
532
  end
528
533
 
529
- def response(resp, &block)
534
+ def response(resp, inline_keys = nil, &block)
530
535
  raise NotSupportedError unless is_swagger_2_0?
531
536
 
532
537
  # TODO validate 'resp' is as per spec
533
538
  self.data[:responses] ||= {}
534
- self.data[:responses][resp] = Swagger::Blocks::ResponseNode.call(version: version, &block)
539
+ self.data[:responses][resp] = Swagger::Blocks::ResponseNode.call(version: version, inline_keys: inline_keys, &block)
535
540
  end
536
541
 
537
- def externalDocs(&block)
542
+ def externalDocs(inline_keys = nil, &block)
538
543
  raise NotSupportedError unless is_swagger_2_0?
539
544
 
540
- self.data[:externalDocs] = Swagger::Blocks::ExternalDocsNode.call(version: version, &block)
545
+ self.data[:externalDocs] = Swagger::Blocks::ExternalDocsNode.call(version: version, inline_keys: inline_keys, &block)
541
546
  end
542
547
 
543
- def security(&block)
548
+ def security(inline_keys = nil, &block)
544
549
  raise NotSupportedError unless is_swagger_2_0?
545
550
 
546
551
  self.data[:security] ||= []
547
- self.data[:security] << Swagger::Blocks::SecurityRequirementNode.call(version: version, &block)
552
+ self.data[:security] << Swagger::Blocks::SecurityRequirementNode.call(version: version, inline_keys: inline_keys, &block)
548
553
  end
549
554
  end
550
555
 
@@ -558,16 +563,16 @@ module Swagger
558
563
  class SecuritySchemeNode < Node
559
564
  # TODO support ^x- Vendor Extensions
560
565
 
561
- def scopes(&block)
562
- self.data[:scopes] = Swagger::Blocks::ScopesNode.call(version: version, &block)
566
+ def scopes(inline_keys = nil, &block)
567
+ self.data[:scopes] = Swagger::Blocks::ScopesNode.call(version: version, inline_keys: inline_keys, &block)
563
568
  end
564
569
  end
565
570
 
566
571
  # v1.2: NOTE: in the spec this is different than Resource Listing's authorizations.
567
572
  # v1.2: http://goo.gl/PvwUXj#514-authorizations-object
568
573
  class ApiAuthorizationsNode < Node
569
- def authorization(name, &block)
570
- self.data[name] ||= Swagger::Blocks::ApiAuthorizationNode.call(version: version, &block)
574
+ def authorization(name, inline_keys, &block)
575
+ self.data[name] ||= Swagger::Blocks::ApiAuthorizationNode.call(version: version, inline_keys: inline_keys, &block)
571
576
  end
572
577
  end
573
578
 
@@ -581,9 +586,9 @@ module Swagger
581
586
  self.data[:_scopes].map { |s| s.as_json }
582
587
  end
583
588
 
584
- def scope(&block)
589
+ def scope(inline_keys = nil, &block)
585
590
  self.data[:_scopes] ||= []
586
- self.data[:_scopes] << Swagger::Blocks::ApiAuthorizationScopeNode.call(version: version, &block)
591
+ self.data[:_scopes] << Swagger::Blocks::ApiAuthorizationScopeNode.call(version: version, inline_keys: inline_keys, &block)
587
592
  end
588
593
  end
589
594
 
@@ -593,20 +598,20 @@ module Swagger
593
598
 
594
599
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responseObject
595
600
  class ResponseNode < Node
596
- def schema(&block)
597
- self.data[:schema] = Swagger::Blocks::SchemaNode.call(version: version, &block)
601
+ def schema(inline_keys = nil, &block)
602
+ self.data[:schema] = Swagger::Blocks::SchemaNode.call(version: version, inline_keys: inline_keys, &block)
598
603
  end
599
604
 
600
- def header(head, &block)
605
+ def header(head, inline_keys = nil, &block)
601
606
  # TODO validate 'head' is as per spec
602
607
  self.data[:headers] ||= {}
603
- self.data[:headers][head] = Swagger::Blocks::HeaderNode.call(version: version, &block)
608
+ self.data[:headers][head] = Swagger::Blocks::HeaderNode.call(version: version, inline_keys: inline_keys, &block)
604
609
  end
605
610
 
606
- def example(exam, &block)
611
+ def example(exam, inline_keys = nil, &block)
607
612
  # TODO validate 'exam' is as per spec
608
613
  self.data[:examples] ||= {}
609
- self.data[:examples][exam] = Swagger::Blocks::ExampleNode.call(version: version, &block)
614
+ self.data[:examples][exam] = Swagger::Blocks::ExampleNode.call(version: version, inline_keys: inline_keys, &block)
610
615
  end
611
616
  end
612
617
 
@@ -642,40 +647,40 @@ module Swagger
642
647
  raise NotSupportedError
643
648
  end
644
649
 
645
- def schema(&block)
646
- data << Swagger::Blocks::SchemaNode.call(version: version, &block)
650
+ def schema(inline_keys = nil, &block)
651
+ data << Swagger::Blocks::SchemaNode.call(version: version, inline_keys: inline_keys, &block)
647
652
  end
648
653
  end
649
654
 
650
655
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#schema-object
651
656
  class SchemaNode < Node
652
- def items(&block)
653
- self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, &block)
657
+ def items(inline_keys = nil, &block)
658
+ self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, inline_keys: inline_keys, &block)
654
659
  end
655
660
 
656
661
  def allOf(&block)
657
662
  self.data[:allOf] = Swagger::Blocks::AllOfNode.call(version: version, &block)
658
663
  end
659
664
 
660
- def property(name, &block)
665
+ def property(name, inline_keys = nil, &block)
661
666
  self.data[:properties] ||= Swagger::Blocks::PropertiesNode.new
662
667
  self.data[:properties].version = version
663
- self.data[:properties].property(name, &block)
668
+ self.data[:properties].property(name, inline_keys, &block)
664
669
  end
665
670
 
666
- def xml(&block)
667
- self.data[:xml] = Swagger::Blocks::XmlNode.call(version: version, &block)
671
+ def xml(inline_keys = nil, &block)
672
+ self.data[:xml] = Swagger::Blocks::XmlNode.call(version: version, inline_keys: inline_keys, &block)
668
673
  end
669
674
 
670
- def externalDocs(&block)
671
- self.data[:externalDocs] = Swagger::Blocks::ExternalDocsNode.call(version: version, &block)
675
+ def externalDocs(inline_keys = nil, &block)
676
+ self.data[:externalDocs] = Swagger::Blocks::ExternalDocsNode.call(version: version, inline_keys: inline_keys, &block)
672
677
  end
673
678
  end
674
679
 
675
680
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#headerObject
676
681
  class HeaderNode < Node
677
- def items(&block)
678
- self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, &block)
682
+ def items(inline_keys = nil, &block)
683
+ self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, inline_keys: inline_keys, &block)
679
684
  end
680
685
  end
681
686
 
@@ -692,16 +697,16 @@ module Swagger
692
697
  # v1.2: http://goo.gl/PvwUXj#524-parameter-object
693
698
  # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameter-object
694
699
  class ParameterNode < Node
695
- def schema(&block)
700
+ def schema(inline_keys = nil, &block)
696
701
  raise NotSupportedError unless is_swagger_2_0?
697
702
 
698
- self.data[:schema] = Swagger::Blocks::SchemaNode.call(version: version, &block)
703
+ self.data[:schema] = Swagger::Blocks::SchemaNode.call(version: version, inline_keys: inline_keys, &block)
699
704
  end
700
705
 
701
- def items(&block)
706
+ def items(inline_keys = nil, &block)
702
707
  raise NotSupportedError unless is_swagger_2_0?
703
708
 
704
- self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, &block)
709
+ self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, inline_keys: inline_keys, &block)
705
710
  end
706
711
  end
707
712
 
@@ -710,8 +715,8 @@ module Swagger
710
715
 
711
716
  # TODO support ^x- Vendor Extensions
712
717
 
713
- def externalDocs(&block)
714
- self.data[:externalDocs] = Swagger::Blocks::ExternalDocsNode.call(version: version, &block)
718
+ def externalDocs(inline_keys = nil, &block)
719
+ self.data[:externalDocs] = Swagger::Blocks::ExternalDocsNode.call(version: version, inline_keys: inline_keys, &block)
715
720
  end
716
721
  end
717
722
 
@@ -725,31 +730,31 @@ module Swagger
725
730
  self.data.merge!(other_models_node.data)
726
731
  end
727
732
 
728
- def model(name, &block)
729
- self.data[name] ||= Swagger::Blocks::ModelNode.call(version: version, &block)
733
+ def model(name, inline_keys, &block)
734
+ self.data[name] ||= Swagger::Blocks::ModelNode.call(version: version, inline_keys: inline_keys, &block)
730
735
  end
731
736
  end
732
737
 
733
738
  # v1.2: http://goo.gl/PvwUXj#527-model-object
734
739
  class ModelNode < Node
735
- def property(name, &block)
740
+ def property(name, inline_keys = nil, &block)
736
741
  self.data[:properties] ||= Swagger::Blocks::PropertiesNode.new
737
742
  self.data[:properties].version = version
738
- self.data[:properties].property(name, &block)
743
+ self.data[:properties].property(name, inline_keys, &block)
739
744
  end
740
745
  end
741
746
 
742
747
  # v1.2: http://goo.gl/PvwUXj#527-model-object
743
748
  class PropertiesNode < Node
744
- def property(name, &block)
745
- self.data[name] = Swagger::Blocks::PropertyNode.call(version: version, &block)
749
+ def property(name, inline_keys = nil, &block)
750
+ self.data[name] = Swagger::Blocks::PropertyNode.call(version: version, inline_keys: inline_keys, &block)
746
751
  end
747
752
  end
748
753
 
749
754
  # v1.2: http://goo.gl/PvwUXj#527-model-object
750
755
  class PropertyNode < Node
751
- def items(&block)
752
- self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, &block)
756
+ def items(inline_keys = nil, &block)
757
+ self.data[:items] = Swagger::Blocks::ItemsNode.call(version: version, inline_keys: inline_keys, &block)
753
758
  end
754
759
  end
755
760
  end
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Blocks
3
- VERSION = '1.2.0'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
@@ -10,21 +10,16 @@ API_DECLARATION_JSON = open(File.expand_path('../swagger_api_declaration.json',
10
10
  class PetController
11
11
  include Swagger::Blocks
12
12
 
13
- swagger_root do
14
- key :swaggerVersion, '1.2'
13
+ swagger_root swaggerVersion: '1.2'do
15
14
  key :apiVersion, '1.0.0'
16
- info do
17
- key :title, 'Swagger Sample App'
15
+ info title: 'Swagger Sample App' do
18
16
  key :description, "This is a sample server Petstore server. You can find out more about Swagger \n at <a href=\"http://swagger.wordnik.com\">http://swagger.wordnik.com</a> or on irc.freenode.net, #swagger. For this sample,\n you can use the api key \"special-key\" to test the authorization filters"
19
17
  key :termsOfServiceUrl, 'http://helloreverb.com/terms/'
20
- key :contact, 'apiteam@wordnik.com'
21
- key :license, 'Apache 2.0'
22
- key :licenseUrl, 'http://www.apache.org/licenses/LICENSE-2.0.html'
23
- end
24
- api do
25
- key :path, '/pet'
26
- key :description, 'Operations about pets'
18
+ keys contact: 'apiteam@wordnik.com',
19
+ license: 'Apache 2.0',
20
+ licenseUrl: 'http://www.apache.org/licenses/LICENSE-2.0.html'
27
21
  end
22
+ api path: '/pet', description: 'Operations about pets'
28
23
  api do
29
24
  key :path, '/user'
30
25
  key :description, 'Operations about user'
@@ -33,39 +28,31 @@ class PetController
33
28
  key :path, '/store'
34
29
  key :description, 'Operations about store'
35
30
  end
36
- authorization :oauth2 do
37
- key :type, 'oauth2'
38
- scope do
39
- key :scope, 'email'
40
- key :description, 'Access to your email address'
41
- end
31
+ authorization :oauth2, type: 'oauth2' do
32
+ scope scope: 'email', description: 'Access to your email address'
42
33
  scope do
43
34
  key :scope, 'pets'
44
35
  key :description, 'Access to your pets'
45
36
  end
46
- grant_type :implicit do
37
+ grant_type :implicit, tokenName: 'access_token' do
47
38
  login_endpoint do
48
39
  key :url, 'http://petstore.swagger.wordnik.com/oauth/dialog'
49
40
  end
50
- key :tokenName, 'access_token'
51
41
  end
52
42
  grant_type :authorization_code do
53
- token_request_endpoint do
43
+ token_request_endpoint clientSecretName: 'client_secret' do
54
44
  key :url, 'http://petstore.swagger.wordnik.com/oauth/requestToken'
55
45
  key :clientIdName, 'client_id'
56
- key :clientSecretName, 'client_secret'
57
46
  end
58
- token_endpoint do
47
+ token_endpoint tokenName: 'access_code' do
59
48
  key :url, 'http://petstore.swagger.wordnik.com/oauth/token'
60
- key :tokenName, 'access_code'
61
49
  end
62
50
  end
63
51
  end
64
52
  end
65
53
 
66
54
  # All swagger_api_root declarations with the same key will be merged.
67
- swagger_api_root :pets do
68
- key :swaggerVersion, '1.2'
55
+ swagger_api_root :pets, swaggerVersion: '1.2' do
69
56
  key :apiVersion, '1.0.0'
70
57
  key :basePath, 'http://petstore.swagger.wordnik.com/api'
71
58
  key :resourcePath, '/pet'
@@ -131,8 +118,7 @@ class PetController
131
118
  key :description, 'anything'
132
119
  end
133
120
  end
134
- parameter do
135
- key :paramType, :path
121
+ parameter paramType: :path do
136
122
  key :name, :petId
137
123
  key :description, 'ID of pet that needs to be fetched'
138
124
  key :required, true
@@ -145,8 +131,7 @@ class PetController
145
131
  key :required, true
146
132
  key :type, :Pet
147
133
  end
148
- response_message do
149
- key :code, 400
134
+ response_message code: 400 do
150
135
  key :message, 'Invalid tag value'
151
136
  end
152
137
  end
@@ -156,15 +141,12 @@ class PetController
156
141
  swagger_api_root :pets do
157
142
  api do
158
143
  key :path, '/pet/findByStatus'
159
- operation do
160
- key :method, 'GET'
144
+ operation method: 'GET' do
161
145
  key :summary, 'Finds Pets by status'
162
146
  key :notes, 'Multiple status values can be provided with comma seperated strings'
163
147
  key :type, :array
164
148
  key :nickname, :findPetsByStatus
165
- items do
166
- key :'$ref', :Pet
167
- end
149
+ items :'$ref' => :Pet
168
150
  parameter do
169
151
  key :paramType, :query
170
152
  key :name, :status
@@ -178,10 +160,7 @@ class PetController
178
160
  'sold',
179
161
  ]
180
162
  end
181
- response_message do
182
- key :code, 400
183
- key :message, 'Invalid status value'
184
- end
163
+ response_message code: 400, message: 'Invalid status value'
185
164
  end
186
165
  end
187
166
  end
@@ -225,8 +204,7 @@ end
225
204
  class OtherModelsContainer
226
205
  include Swagger::Blocks
227
206
 
228
- swagger_model :Pet do
229
- key :id, :Pet
207
+ swagger_model :Pet, id: :Pet do
230
208
  key :required, [:id, :name]
231
209
  property :id do
232
210
  key :type, :integer
@@ -8,10 +8,9 @@ RESOURCE_LISTING_JSON_V2 = open(File.expand_path('../swagger_v2_api_declaration.
8
8
  class PetControllerV2
9
9
  include Swagger::Blocks
10
10
 
11
- swagger_root do
11
+ swagger_root host: 'petstore.swagger.wordnik.com' do
12
12
  key :swagger, '2.0'
13
- info do
14
- key :version, '1.0.0'
13
+ info version: '1.0.0' do
15
14
  key :title, 'Swagger Petstore'
16
15
  key :description, 'A sample API that uses a petstore as an example to ' \
17
16
  'demonstrate features in the swagger-2.0 specification'
@@ -23,13 +22,11 @@ class PetControllerV2
23
22
  key :name, 'MIT'
24
23
  end
25
24
  end
26
- key :host, 'petstore.swagger.wordnik.com'
27
25
  key :basePath, '/api'
28
26
  key :schemes, ['http']
29
27
  key :consumes, ['application/json']
30
28
  key :produces, ['application/json']
31
- security_definition :api_key do
32
- key :type, :apiKey
29
+ security_definition :api_key, type: :apiKey do
33
30
  key :name, :api_key
34
31
  key :in, :header
35
32
  end
@@ -37,16 +34,13 @@ class PetControllerV2
37
34
  key :type, :oauth2
38
35
  key :authorizationUrl, 'http://swagger.io/api/oauth/dialog'
39
36
  key :flow, :implicit
40
- scopes do
41
- key 'write:pets', 'modify pets in your account'
37
+ scopes 'write:pets' => 'modify pets in your account' do
42
38
  key 'read:pets', 'read your pets'
43
39
  end
44
40
  end
45
- tag do
46
- key :name, 'pet'
41
+ tag name: 'pet' do
47
42
  key :description, 'Pets operations'
48
- externalDocs do
49
- key :description, 'Find more info here'
43
+ externalDocs description: 'Find more info here' do
50
44
  key :url, 'https://swagger.io'
51
45
  end
52
46
  end
@@ -83,8 +77,7 @@ class PetControllerV2
83
77
  end
84
78
  response 200 do
85
79
  key :description, 'pet response'
86
- schema do
87
- key :type, :array
80
+ schema type: :array do
88
81
  items do
89
82
  key :'$ref', :Pet
90
83
  end
@@ -119,8 +112,7 @@ class PetControllerV2
119
112
  key :'$ref', '#/parameters/Pet'
120
113
  end
121
114
  end
122
- response :default do
123
- key :description, 'unexpected error'
115
+ response :default, description: 'unexpected error' do
124
116
  schema do
125
117
  key :'$ref', :ErrorModel
126
118
  end
@@ -158,9 +150,7 @@ class PetControllerV2
158
150
  key :'$ref', :ErrorModel
159
151
  end
160
152
  end
161
- security do
162
- key :api_key, []
163
- end
153
+ security api_key: []
164
154
  security do
165
155
  key :petstore_auth, ['write:pets', 'read:pets']
166
156
  end
@@ -193,8 +183,7 @@ end
193
183
  class PetV2
194
184
  include Swagger::Blocks
195
185
 
196
- swagger_schema :Pet do
197
- key :required, [:id, :name]
186
+ swagger_schema :Pet, required: [:id, :name] do
198
187
  property :id do
199
188
  key :type, :integer
200
189
  key :format, :int64
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.2.0
4
+ version: 1.3.0
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-08-28 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler