grape-swagger 0.31.0 → 0.31.1

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
  SHA256:
3
- metadata.gz: fb1e3a26202efe81153ad53197d67e8e3865ba34271a841d35e921eea5dc7a77
4
- data.tar.gz: e0d34f81243e4d327d5268d100d0f654c5fbb0b63f95e47a50ba74e7ced602b2
3
+ metadata.gz: 5e20b96cce4f137604bc4133b23249fde90b242160469cd6ed347d2840bd5b74
4
+ data.tar.gz: 5e6d17f9875b63983b186d920dc28cdc4a957f13bc9f511a61991dbc7196ce50
5
5
  SHA512:
6
- metadata.gz: 97396d5bcecae0c152c5c67c060da11373cd080cd126f2e443766790663355ffb358743beb2b2d309fa80399b1cb813053bb83ef8f89686e0d6c63f2f2b23919
7
- data.tar.gz: 5afd698ad351518cb9d5cc73dfe45360e182263203bab5993c2766fa5ece2cd6bf61328b90223e1b4883444798d9ae769b6f3dc32f7b442303911286d66a1e34
6
+ metadata.gz: f2596bf6f153d0447fec637fc4c035fa2bc1d3806feebf2f71a9e6fcd9c950a40d7bbd02fa703ad11994a0b4969fb014a0342a4dc01a7c3224c6670d126ffb73
7
+ data.tar.gz: 39e5bfb7503ae7ea188231768db59fd89b8ef41494edb18ec8bf3e1cc458fda5fcf6db381663e06681e2b4b476e454147a4494232c316901a88caf2955ea7e92
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-12-13 08:44:09 +0100 using RuboCop version 0.52.0.
3
+ # on 2018-09-28 22:03:50 -0400 using RuboCop version 0.59.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -13,26 +13,20 @@ Gemspec/RequiredRubyVersion:
13
13
  Exclude:
14
14
  - 'grape-swagger.gemspec'
15
15
 
16
-
17
16
  # Offense count: 30
18
17
  Metrics/AbcSize:
19
- Max: 56
20
-
21
- # Offense count: 3
22
- # Configuration parameters: CountComments.
23
- Metrics/ClassLength:
24
- Max: 248
18
+ Max: 57
25
19
 
26
20
  # Offense count: 10
27
21
  Metrics/CyclomaticComplexity:
28
22
  Max: 13
29
23
 
30
- # Offense count: 20
31
- # Configuration parameters: CountComments.
24
+ # Offense count: 22
25
+ # Configuration parameters: CountComments, ExcludedMethods.
32
26
  Metrics/MethodLength:
33
- Max: 40
27
+ Max: 44
34
28
 
35
- # Offense count: 6
29
+ # Offense count: 7
36
30
  Metrics/PerceivedComplexity:
37
31
  Max: 14
38
32
 
@@ -41,6 +35,6 @@ Style/ClassVars:
41
35
  Exclude:
42
36
  - 'lib/grape-swagger/doc_methods.rb'
43
37
 
44
- # Offense count: 20
38
+ # Offense count: 21
45
39
  Style/Documentation:
46
40
  Enabled: false
@@ -1,12 +1,8 @@
1
- ### Next
1
+ ### 0.31.1 (October 23, 2018)
2
2
 
3
3
  #### Features
4
4
 
5
- * Your contribution here.
6
-
7
- #### Fixes
8
-
9
- * Your contribution here.
5
+ * [#710](https://github.com/ruby-grape/grape-swagger/issues/710): Re-implement `api_documentation` and `specific_api_documentation` options - [@dblock](https://github.com/dblock).
10
6
 
11
7
  ### 0.31.0 (August 22, 2018)
12
8
 
@@ -14,7 +10,6 @@
14
10
 
15
11
  * [#622](https://github.com/ruby-grape/grape-swagger/pull/622): Add support for 'brackets' collection format - [@korstiaan](https://github.com/korstiaan).
16
12
  * [#637](https://github.com/ruby-grape/grape-swagger/pull/637): Add an option to add braces to array params - [@adie](https://github.com/adie).
17
-
18
13
  * [#688](https://github.com/ruby-grape/grape-swagger/pull/688): Use deep merge for nested parameter definitions - [@jdmurphy](https://github.com/jdmurphy).
19
14
  * [#691](https://github.com/ruby-grape/grape-swagger/pull/691): Disregard order when parsing request params for arrays - [@jdmurphy](https://github.com/jdmurphy).
20
15
  * [#696](https://github.com/ruby-grape/grape-swagger/pull/696): Delegate required properties parsing to model parsers - [@Bugagazavr](https://github.com/Bugagazavr).
data/Gemfile CHANGED
@@ -26,7 +26,7 @@ group :development, :test do
26
26
  gem 'rake'
27
27
  gem 'rdoc'
28
28
  gem 'rspec', '~> 3.0'
29
- gem 'rubocop', '~> 0.58', require: false
29
+ gem 'rubocop', '~> 0.59', require: false
30
30
  end
31
31
 
32
32
  group :test do
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/grape-swagger.svg)](http://badge.fury.io/rb/grape-swagger)
2
2
  [![Build Status](https://travis-ci.org/ruby-grape/grape-swagger.svg?branch=master)](https://travis-ci.org/ruby-grape/grape-swagger)
3
3
  [![Coverage Status](https://coveralls.io/repos/github/ruby-grape/grape-swagger/badge.svg?branch=master)](https://coveralls.io/github/ruby-grape/grape-swagger?branch=master)
4
- [![Dependency Status](https://gemnasium.com/ruby-grape/grape-swagger.svg)](https://gemnasium.com/ruby-grape/grape-swagger)
5
4
  [![Code Climate](https://codeclimate.com/github/ruby-grape/grape-swagger.svg)](https://codeclimate.com/github/ruby-grape/grape-swagger)
6
5
 
7
6
  ##### Table of Contents
@@ -21,7 +20,7 @@
21
20
  * [Rake Tasks](#rake)
22
21
 
23
22
 
24
- ## What is grape-swagger? <a name="what" />
23
+ ## What is grape-swagger? <a name="what"></a>
25
24
 
26
25
  The grape-swagger gem provides an autogenerated documentation for your [Grape](https://github.com/ruby-grape/grape) API. The generated documentation is Swagger-compliant, meaning it can easily be discovered in [Swagger UI](https://github.com/wordnik/swagger-ui). You should be able to point [the petstore demo](http://petstore.swagger.io/) to your API.
27
26
 
@@ -30,7 +29,7 @@ The grape-swagger gem provides an autogenerated documentation for your [Grape](h
30
29
  This screenshot is based on the [Hussars](https://github.com/LeFnord/hussars) sample app.
31
30
 
32
31
 
33
- ## Related Projects <a name="related" />
32
+ ## Related Projects <a name="related"></a>
34
33
 
35
34
  * [Grape](https://github.com/ruby-grape/grape)
36
35
  * [Grape Swagger Entity](https://github.com/ruby-grape/grape-swagger-entity)
@@ -40,7 +39,7 @@ This screenshot is based on the [Hussars](https://github.com/LeFnord/hussars) sa
40
39
 
41
40
 
42
41
 
43
- ## Compatibility <a name="version" />
42
+ ## Compatibility <a name="version"></a>
44
43
 
45
44
  The following versions of grape, grape-entity and grape-swagger can currently be used together.
46
45
 
@@ -53,14 +52,14 @@ grape-swagger | swagger spec | grape | grape-entity | represen
53
52
  0.27.0 | 2.0 | >= 0.16.2 | >= 0.5.0 | >= 2.4.1 |
54
53
 
55
54
 
56
- ## Swagger-Spec <a name="swagger-spec" />
55
+ ## Swagger-Spec <a name="swagger-spec"></a>
57
56
 
58
57
  Grape-swagger generates documentation per [Swagger / OpenAPI Spec 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).
59
58
 
60
59
  <!-- validating it with: http://bigstickcarpet.com/swagger-parser/www/index.html -->
61
60
 
62
61
 
63
- ## Installation <a name="install" />
62
+ ## Installation <a name="install"></a>
64
63
 
65
64
  Add to your Gemfile:
66
65
 
@@ -74,9 +73,9 @@ Please see [UPGRADING](UPGRADING.md) when upgrading from a previous version.
74
73
 
75
74
 
76
75
 
77
- ## Usage <a name="usage" />
76
+ ## Usage <a name="usage"></a>
78
77
 
79
- Mount all your different APIs (with ```Grape::API``` superclass) on a root node. In the root class definition, include ```add_swagger_documentation```, this sets up the system and registers the documentation on '/swagger_doc'. See [example/config.ru](example/config.ru) for a simple demo.
78
+ Mount all your different APIs (with `Grape::API` superclass) on a root node. In the root class definition, include `add_swagger_documentation`, this sets up the system and registers the documentation on '/swagger_doc'. See [example/config.ru](example/config.ru) for a simple demo.
80
79
 
81
80
 
82
81
  ```ruby
@@ -97,7 +96,7 @@ To explore your API, either download [Swagger UI](https://github.com/wordnik/swa
97
96
 
98
97
 
99
98
 
100
- ## Model Parsers <a name="model_parsers" />
99
+ ## Model Parsers <a name="model_parsers"></a>
101
100
 
102
101
  Since 0.21.0, `Grape::Entity` is not a part of grape-swagger, you need to add `grape-swagger-entity` manually to your Gemfile.
103
102
  Also added support for [representable](https://github.com/apotonick/representable) via `grape-swagger-representable`.
@@ -183,7 +182,7 @@ end
183
182
 
184
183
 
185
184
 
186
- ## Configure <a name="configure" />
185
+ ## Configure <a name="configure"></a>
187
186
 
188
187
  * [host](#host)
189
188
  * [base_path](#base_path)
@@ -200,7 +199,9 @@ end
200
199
  * [tags](#tags)
201
200
  * [hide_documentation_path](#hide_documentation_path)
202
201
  * [info](#info)
203
- * [array_uses_braces](#array_uses_braces)
202
+ * [array_use_braces](#array_use_braces)
203
+ * [api_documentation](#api_documentation)
204
+ * [specific_api_documentation](#specific_api_documentation)
204
205
 
205
206
  You can pass a hash with optional configuration settings to ```add_swagger_documentation```.
206
207
  The examples show the default value.
@@ -214,7 +215,7 @@ add_swagger_documentation \
214
215
  ```
215
216
 
216
217
 
217
- #### host: <a name="host" />
218
+ #### host: <a name="host"></a>
218
219
  Sets explicit the `host`, default would be taken from `request`.
219
220
  ```ruby
220
221
  add_swagger_documentation \
@@ -222,7 +223,7 @@ add_swagger_documentation \
222
223
  ```
223
224
 
224
225
 
225
- #### base_path: <a name="base_path" />
226
+ #### base_path: <a name="base_path"></a>
226
227
  Base path of the API that's being exposed, default would be taken from `request`.
227
228
  ```ruby
228
229
  add_swagger_documentation \
@@ -232,21 +233,22 @@ add_swagger_documentation \
232
233
  `host` and `base_path` are also accepting a `proc` or `lambda`
233
234
 
234
235
 
235
- #### mount_path: <a name="mount_path" />
236
+ #### mount_path: <a name="mount_path"></a>
236
237
  The path where the API documentation is loaded, default is: `/swagger_doc`.
237
238
  ```ruby
238
239
  add_swagger_documentation \
239
240
  mount_path: '/swagger_doc'
240
241
  ```
241
242
 
242
- #### add_base_path:
243
+ #### add_base_path: <a name="add_base_path"></a>
243
244
  Add `basePath` key to the documented path keys, default is: `false`.
244
245
  ```ruby
245
246
  add_swagger_documentation \
246
247
  add_base_path: true # only if base_path given
247
248
  ```
248
249
 
249
- #### add_version:
250
+ #### add_version: <a name="add_version"></a>
251
+
250
252
  Add `version` key to the documented path keys, default is: `true`,
251
253
  here the version is the API version, specified by `grape` in [`path`](https://github.com/ruby-grape/grape/#path)
252
254
 
@@ -256,7 +258,8 @@ add_swagger_documentation \
256
258
  ```
257
259
 
258
260
 
259
- #### doc_version: <a name="doc_version" />
261
+ #### doc_version: <a name="doc_version"></a>
262
+
260
263
  Specify the version of the documentation at [info section](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#info-object), default is: `'0.0.1'`
261
264
  ```ruby
262
265
  add_swagger_documentation \
@@ -264,7 +267,8 @@ add_swagger_documentation \
264
267
  ```
265
268
 
266
269
 
267
- #### endpoint_auth_wrapper: <a name="endpoint_auth_wrapper" />
270
+ #### endpoint_auth_wrapper: <a name="endpoint_auth_wrapper"></a>
271
+
268
272
  Specify the middleware to use for securing endpoints.
269
273
 
270
274
  ```ruby
@@ -273,7 +277,7 @@ add_swagger_documentation \
273
277
  ```
274
278
 
275
279
 
276
- #### swagger_endpoint_guard: <a name="swagger_endpoint_guard" />
280
+ #### swagger_endpoint_guard: <a name="swagger_endpoint_guard"></a>
277
281
  Specify the method and auth scopes, used by the middleware for securing endpoints.
278
282
 
279
283
  ```ruby
@@ -282,7 +286,7 @@ add_swagger_documentation \
282
286
  ```
283
287
 
284
288
 
285
- #### token_owner: <a name="token_owner" />
289
+ #### token_owner: <a name="token_owner"></a>
286
290
  Specify the token_owner method, provided by the middleware, which is typically named 'resource_owner'.
287
291
 
288
292
  ```ruby
@@ -291,7 +295,7 @@ add_swagger_documentation \
291
295
  ```
292
296
 
293
297
 
294
- #### security_definitions: <a name="security_definitions" />
298
+ #### security_definitions: <a name="security_definitions"></a>
295
299
  Specify the [Security Definitions Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-definitions-object)
296
300
 
297
301
  _NOTE: [Swagger-UI is supporting only implicit flow yet](https://github.com/swagger-api/swagger-ui/issues/2406#issuecomment-248651879)_
@@ -307,7 +311,8 @@ add_swagger_documentation \
307
311
  }
308
312
  ```
309
313
 
310
- #### security: <a name="security" />
314
+ #### security: <a name="security"></a>
315
+
311
316
  Specify the [Security Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#securityRequirementObject)
312
317
 
313
318
  ```ruby
@@ -320,7 +325,7 @@ add_swagger_documentation \
320
325
  ```
321
326
 
322
327
 
323
- #### models: <a name="models" />
328
+ #### models: <a name="models"></a>
324
329
  A list of entities to document. Combine with the [grape-entity](https://github.com/ruby-grape/grape-entity) gem.
325
330
 
326
331
  These would be added to the definitions section of the swagger file.
@@ -334,7 +339,8 @@ add_swagger_documentation \
334
339
  ```
335
340
 
336
341
 
337
- #### tags: <a name="tags" />
342
+ #### tags: <a name="tags"></a>
343
+
338
344
  A list of tags to document. By default tags are automatically generated
339
345
  for endpoints based on route names.
340
346
 
@@ -346,7 +352,8 @@ add_swagger_documentation \
346
352
  ```
347
353
 
348
354
 
349
- #### hide_documentation_path: (default: `true`) <a name="hide_documentation_path" />
355
+ #### hide_documentation_path: (default: `true`) <a name="hide_documentation_path"></a>
356
+
350
357
  ```ruby
351
358
  add_swagger_documentation \
352
359
  hide_documentation_path: true
@@ -355,7 +362,8 @@ add_swagger_documentation \
355
362
  Don't show the `/swagger_doc` path in the generated swagger documentation.
356
363
 
357
364
 
358
- #### info: <a name="info" />
365
+ #### info: <a name="info"></a>
366
+
359
367
  ```ruby
360
368
  add_swagger_documentation \
361
369
  info: {
@@ -372,7 +380,8 @@ add_swagger_documentation \
372
380
 
373
381
  A hash merged into the `info` key of the JSON documentation.
374
382
 
375
- #### array_uses_braces: <a name="array_uses_braces" />
383
+ #### array_use_braces: <a name="array_use_braces"></a>
384
+
376
385
  ```ruby
377
386
  add_swagger_documentation \
378
387
  array_use_braces: true
@@ -383,25 +392,43 @@ params do
383
392
  optional :metadata, type: Array[String]
384
393
  end
385
394
  ```
386
- with `array_uses_braces: true`:
395
+ with `array_use_braces: true`:
387
396
  ```
388
397
  metadata[]: { "name": "Asset ID", "value": "12345" }
389
398
  metadata[]: { "name": "Asset Tag", "value": "654321"}
390
399
  ```
391
- with `array_uses_braces: false`:
400
+ with `array_use_braces: false`:
392
401
  ```
393
402
  metadata: {"name": "Asset ID", "value": "123456"}
394
403
  metadata: {"name": "Asset Tag", "value": "654321"}
395
404
  ```
396
405
 
397
- ## Routes Configuration <a name="routes" />
406
+ #### api_documentation
407
+
408
+ Customize the Swagger API documentation route, typically contains a `desc` field. The default description is "Swagger compatible API description".
409
+
410
+ ```ruby
411
+ add_swagger_documentation \
412
+ api_documentation: { desc: 'Reticulated splines API swagger-compatible documentation.' }
413
+ ```
414
+
415
+ #### specific_api_documentation
416
+
417
+ Customize the Swagger API specific documentation route, typically contains a `desc` field. The default description is "Swagger compatible API description for specific API".
418
+
419
+ ```ruby
420
+ add_swagger_documentation \
421
+ specific_api_documentation: { desc: 'Reticulated splines API swagger-compatible endpoint documentation.' }
422
+ ```
423
+
424
+ ## Routes Configuration <a name="routes"></a>
398
425
 
399
426
  * [Swagger Header Parameters](#headers)
400
427
  * [Hiding an Endpoint](#hiding)
401
428
  * [Overriding Auto-Generated Nicknames](#overriding-auto-generated-nicknames)
402
429
  * [Specify endpoint details](#details)
403
430
  * [Overriding the route summary](#summary)
404
- * [Overriding the tags](#tags)
431
+ * [Overriding the tags](#overriding_the_tags)
405
432
  * [Deprecating routes](#deprecating-routes)
406
433
  * [Overriding the name of the body parameter](#body-param)
407
434
  * [Defining an endpoint as an array](#array)
@@ -420,7 +447,7 @@ metadata: {"name": "Asset Tag", "value": "654321"}
420
447
  * [Response examples documentation](#response-examples)
421
448
  * [Response headers documentation](#response-headers)
422
449
 
423
- #### Swagger Header Parameters <a name="headers" />
450
+ #### Swagger Header Parameters <a name="headers"></a>
424
451
 
425
452
  Swagger also supports the documentation of parameters passed in the header. Since grape's ```params[]``` doesn't return header parameters we can specify header parameters seperately in a block after the description.
426
453
 
@@ -440,7 +467,7 @@ desc "Return super-secret information", {
440
467
  ```
441
468
 
442
469
 
443
- #### Hiding an Endpoint <a name="hiding" />
470
+ #### Hiding an Endpoint <a name="hiding"></a>
444
471
 
445
472
  You can hide an endpoint by adding ```hidden: true``` in the description of the endpoint:
446
473
 
@@ -469,16 +496,16 @@ desc 'Conditionally hide this endpoint', hidden: lambda { ENV['EXPERIMENTAL'] !=
469
496
  ```
470
497
 
471
498
 
472
- #### Overriding Auto-Generated Nicknames <a name="overriding-auto-generated-nicknames" />
499
+ #### Overriding Auto-Generated Nicknames <a name="overriding-auto-generated-nicknames"></a>
473
500
 
474
- You can specify a swagger nickname to use instead of the auto generated name by adding `:nickname 'string'``` in the description of the endpoint.
501
+ You can specify a swagger nickname to use instead of the auto generated name by adding `:nickname 'string'` in the description of the endpoint.
475
502
 
476
503
  ```ruby
477
504
  desc 'Get a full list of pets', nickname: 'getAllPets'
478
505
  ```
479
506
 
480
507
 
481
- #### Specify endpoint details <a name="details" />
508
+ #### Specify endpoint details <a name="details"></a>
482
509
 
483
510
  To specify further details for an endpoint, use the `detail` option within a block passed to `desc`:
484
511
 
@@ -490,7 +517,7 @@ get '/kittens' do
490
517
  ```
491
518
 
492
519
 
493
- #### Overriding the route summary <a name="summary" />
520
+ #### Overriding the route summary <a name="summary"></a>
494
521
 
495
522
  To override the summary, add `summary: '[string]'` after the description.
496
523
 
@@ -505,7 +532,7 @@ end
505
532
  ```
506
533
 
507
534
 
508
- #### Overriding the tags <a name="tags" />
535
+ #### Overriding the tags <a name="overriding_the_tags"></a>
509
536
 
510
537
  Tags are used for logical grouping of operations by resources or any other qualifier. To override the
511
538
  tags array, add `tags: ['tag1', 'tag2']` after the description.
@@ -520,7 +547,7 @@ end
520
547
  ```
521
548
 
522
549
 
523
- #### Deprecating routes <a name="deprecating-routes" />
550
+ #### Deprecating routes <a name="deprecating-routes"></a>
524
551
 
525
552
  To deprecate a route add `deprecated: true` after the description.
526
553
 
@@ -534,7 +561,7 @@ end
534
561
  ```
535
562
 
536
563
 
537
- #### Overriding the name of the body parameter <a name="body-param" />
564
+ #### Overriding the name of the body parameter <a name="body-param"></a>
538
565
 
539
566
  By default, body parameters have a generated name based on the operation. For
540
567
  deeply nested resources, this name can get very long. To override the name of
@@ -550,7 +577,7 @@ end
550
577
  ```
551
578
 
552
579
 
553
- #### Defining an endpoint as an array <a name="array" />
580
+ #### Defining an endpoint as an array <a name="array"></a>
554
581
 
555
582
  You can define an endpoint as an array by adding `is_array` in the description:
556
583
 
@@ -559,7 +586,7 @@ desc 'Get a full list of pets', is_array: true
559
586
  ```
560
587
 
561
588
 
562
- #### Using an options hash <a name="options" />
589
+ #### Using an options hash <a name="options"></a>
563
590
 
564
591
  The Grape DSL supports either an options hash or a restricted block to pass settings. Passing the `nickname`, `hidden` and `is_array` options together with response codes is only possible when passing an options hash.
565
592
  Since the syntax differs you'll need to adjust it accordingly:
@@ -579,7 +606,7 @@ get '/kittens' do
579
606
  ```
580
607
 
581
608
 
582
- #### Overriding parameter type <a name="overriding-param-type" />
609
+ #### Overriding parameter type <a name="overriding-param-type"></a>
583
610
 
584
611
  You can override paramType, using the documentation hash. See [parameter object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object) for available types.
585
612
 
@@ -593,7 +620,7 @@ end
593
620
  ```
594
621
 
595
622
 
596
- #### Overriding data type of the parameter <a name="overriding-type-of-param" />
623
+ #### Overriding data type of the parameter <a name="overriding-type-of-param"></a>
597
624
 
598
625
  You can override type, using the documentation hash.
599
626
 
@@ -617,7 +644,7 @@ end
617
644
  ```
618
645
 
619
646
 
620
- #### Multiple types <a name="multiple-types" />
647
+ #### Multiple types <a name="multiple-types"></a>
621
648
 
622
649
  By default when you set multiple types, the first type is selected as swagger type
623
650
 
@@ -640,7 +667,7 @@ end
640
667
  ```
641
668
 
642
669
 
643
- #### Array of data type <a name="array-type" />
670
+ #### Array of data type <a name="array-type"></a>
644
671
 
645
672
  Array types are also supported.
646
673
 
@@ -666,7 +693,7 @@ end
666
693
  ```
667
694
 
668
695
 
669
- #### Collection format of arrays <a name="collection-format" />
696
+ #### Collection format of arrays <a name="collection-format"></a>
670
697
 
671
698
  You can set the collection format of an array, using the documentation hash.
672
699
 
@@ -700,7 +727,7 @@ end
700
727
  ```
701
728
 
702
729
 
703
- #### Hiding parameters <a name="hiding-parameters" />
730
+ #### Hiding parameters <a name="hiding-parameters"></a>
704
731
 
705
732
  Exclude single optional parameter from the documentation
706
733
 
@@ -715,7 +742,7 @@ end
715
742
  ```
716
743
 
717
744
 
718
- #### Setting a Swagger default value <a name="default-value" />
745
+ #### Setting a Swagger default value <a name="default-value"></a>
719
746
 
720
747
  Grape allows for an additional documentation hash to be passed to a parameter.
721
748
 
@@ -785,7 +812,7 @@ end
785
812
  ```
786
813
 
787
814
 
788
- #### Response documentation <a name="response" />
815
+ #### Response documentation <a name="response"></a>
789
816
 
790
817
  You can also document the HTTP status codes with a description and a specified model, as ref in the schema to the definitions, that your API returns with one of the following syntax.
791
818
 
@@ -794,7 +821,7 @@ In the following cases, the schema ref would be taken from route.
794
821
  ```ruby
795
822
  desc 'thing', failure: [ { code: 400, message: 'Invalid parameter entry' } ]
796
823
  get '/thing' do
797
- ...
824
+ # ...
798
825
  end
799
826
  ```
800
827
 
@@ -804,7 +831,7 @@ desc 'thing' do
804
831
  failure [ { code: 400, message: 'Invalid parameter entry' } ]
805
832
  end
806
833
  get '/thing' do
807
- ...
834
+ # ...
808
835
  end
809
836
  ```
810
837
 
@@ -813,7 +840,7 @@ get '/thing', failure: [
813
840
  { code: 400, message: 'Invalid parameter entry' },
814
841
  { code: 404, message: 'Not authorized' },
815
842
  ] do
816
- ...
843
+ # ...
817
844
  end
818
845
  ```
819
846
 
@@ -823,7 +850,7 @@ get '/thing', failure: [
823
850
  { code: 400, message: 'General error' },
824
851
  { code: 422, message: 'Invalid parameter entry', model: Entities::ApiError }
825
852
  ] do
826
- ...
853
+ # ...
827
854
  end
828
855
  ```
829
856
  If no status code is defined [defaults](/lib/grape-swagger/endpoint.rb#L210) would be taken.
@@ -848,7 +875,7 @@ The result is then something like following:
848
875
  ```
849
876
 
850
877
 
851
- #### Changing default status codes <a name="change-status" />
878
+ #### Changing default status codes <a name="change-status"></a>
852
879
 
853
880
  The default status codes, one could be found (-> [status codes](lib/grape-swagger/doc_methods/status_codes.rb)) can be changed to your specific needs, to achive it, you have to change it for grape itself and for the documentation.
854
881
 
@@ -859,7 +886,6 @@ get do
859
886
  status 202
860
887
  # your code comes here
861
888
  end
862
-
863
889
  ```
864
890
 
865
891
  ```json
@@ -874,16 +900,16 @@ end
874
900
  ```
875
901
 
876
902
 
877
- #### File response <a name="file-response" />
903
+ #### File response <a name="file-response"></a>
904
+
905
+ Setting `success` to `File` sets a default `produces` of `application/octet-stream`.
878
906
 
879
- Set `success` to `File` and sets also produces. If produces wasn't set, it defaults to `application/octet-stream`.
880
907
  ```ruby
881
908
  desc 'Get a file',
882
909
  success: File
883
910
  get do
884
- # your file reponse
911
+ # your file response
885
912
  end
886
-
887
913
  ```
888
914
 
889
915
  ```json
@@ -901,10 +927,11 @@ end
901
927
  ```
902
928
 
903
929
 
904
- #### Extensions <a name="extensions" />
930
+ #### Extensions <a name="extensions"></a>
905
931
 
906
932
  Swagger spec2.0 supports extensions on different levels, for the moment,
907
933
  the documentation on the root level object and the `info`, `verb`, `path` and `definition` levels are supported.
934
+
908
935
  The documented key would be generated from the `x` + `-` + key of the submitted hash,
909
936
  for possibilities refer to the [extensions spec](spec/lib/extensions_spec.rb).
910
937
  To get an overview *how* the extensions would be defined on grape level, see the following examples:
@@ -1004,7 +1031,7 @@ route_setting :x_def, [{ for: 422, other: 'stuff' }, { for: 200, some: 'stuff' }
1004
1031
  ```
1005
1032
 
1006
1033
 
1007
- #### Response examples documentation <a name="response-examples" />
1034
+ #### Response examples documentation <a name="response-examples"></a>
1008
1035
 
1009
1036
  You can also add examples to your responses by using the `desc` DSL with block syntax.
1010
1037
 
@@ -1058,7 +1085,7 @@ The result will look like following:
1058
1085
 
1059
1086
  Failure information can be passed as an array of arrays or an array of hashes.
1060
1087
 
1061
- #### Response headers documentation <a name="response-headers" />
1088
+ #### Response headers documentation <a name="response-headers"></a>
1062
1089
 
1063
1090
  You can also add header information to your responses by using the `desc` DSL with block syntax.
1064
1091
 
@@ -1113,7 +1140,7 @@ The result will look like following:
1113
1140
 
1114
1141
  Failure information can be passed as an array of arrays or an array of hashes.
1115
1142
 
1116
- ## Using Grape Entities <a name="grape-entity" />
1143
+ ## Using Grape Entities <a name="grape-entity"></a>
1117
1144
 
1118
1145
  Add the [grape-entity](https://github.com/ruby-grape/grape-entity) and [grape-swagger-entity](https://github.com/ruby-grape/grape-swagger-entity) gem to your Gemfile.
1119
1146
 
@@ -1234,7 +1261,7 @@ end
1234
1261
 
1235
1262
 
1236
1263
 
1237
- ## Securing the Swagger UI <a name="oauth" />
1264
+ ## Securing the Swagger UI <a name="oauth"></a>
1238
1265
 
1239
1266
  The Swagger UI on Grape could be secured from unauthorized access using any middleware, which provides certain methods:
1240
1267
 
@@ -1304,7 +1331,7 @@ role - only admins can see this endpoint.
1304
1331
 
1305
1332
 
1306
1333
 
1307
- ## Example <a name="example" />
1334
+ ## Example <a name="example"></a>
1308
1335
 
1309
1336
  Go into example directory and run it: `$ bundle exec rackup`
1310
1337
  go to: `http://localhost:9292/swagger_doc` to get it
@@ -1349,7 +1376,7 @@ end
1349
1376
 
1350
1377
 
1351
1378
 
1352
- ## Rake Tasks <a name="rake" />
1379
+ ## Rake Tasks <a name="rake"></a>
1353
1380
 
1354
1381
  Add these lines to your Rakefile, and initialize the Task class with your Api class – be sure your Api class is available.
1355
1382
 
@@ -1,6 +1,6 @@
1
1
  # Releasing Grape-Swagger
2
2
 
3
- There're no particular rules about when to release grape-swagger. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
3
+ There are no particular rules about when to release grape-swagger. Any co-maintainer is encouraged to release bug fixes frequently, features not so frequently and breaking API changes rarely.
4
4
 
5
5
  ### Release
6
6
 
@@ -13,18 +13,13 @@ rake
13
13
 
14
14
  Check that the last build succeeded in [Travis CI](https://travis-ci.org/ruby-grape/grape-swagger) for all supported platforms.
15
15
 
16
- Increment the version, modify [lib/grape-swagger/version.rb](lib/grape-swagger/version.rb).
17
-
18
- * Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.7.1` to `0.7.2`).
19
- * Increment the second number if the release contains major features or breaking API changes (eg. change `0.7.1` to `0.8.0`).
20
-
21
- Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
16
+ Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
22
17
 
23
18
  ```
24
19
  ### 0.7.2 (February 6, 2014)
25
20
  ```
26
21
 
27
- Remove the line with "Your contribution here.", since there will be no more contributions to this release.
22
+ Remove the lines with "Your contribution here.", since there will be no more contributions to this release.
28
23
 
29
24
  Commit your changes.
30
25
 
@@ -47,11 +42,18 @@ Pushed grape-swagger 0.7.2 to rubygems.org.
47
42
 
48
43
  ### Prepare for the Next Version
49
44
 
45
+ Increment the minor version, the third number, modify [lib/grape-swagger/version.rb](lib/grape-swagger/version.rb). For example, change `0.7.1` to `0.7.2`. Major versions are incremented in pull requests that require it.
46
+
50
47
  Add the next release to [CHANGELOG.md](CHANGELOG.md).
51
48
 
52
49
  ```
53
- Next Release
54
- ============
50
+ ### 0.7.3 (Next)
51
+
52
+ #### Features
53
+
54
+ * Your contribution here.
55
+
56
+ #### Fixes
55
57
 
56
58
  * Your contribution here.
57
59
  ```
@@ -59,8 +61,8 @@ Next Release
59
61
  Commit your changes.
60
62
 
61
63
  ```
62
- git add CHANGELOG.md
63
- git commit -m "Preparing for next release."
64
+ git add CHANGELOG.md lib/grape-swagger/version.rb
65
+ git commit -m "Preparing for next developer iteration, 0.7.3."
64
66
  git push origin master
65
67
  ```
66
68
 
@@ -64,12 +64,15 @@ module Grape
64
64
  route_path = route.path
65
65
  route_match = route_path.split(/^.*?#{route.prefix.to_s}/).last
66
66
  next unless route_match
67
+
67
68
  route_match = route_match.match('\/([\w|-]*?)[\.\/\(]') || route_match.match('\/([\w|-]*)$')
68
69
  next unless route_match
70
+
69
71
  resource = route_match.captures.first
70
72
  resource = '/' if resource.empty?
71
73
  @target_class.combined_routes[resource] ||= []
72
74
  next if doc_klass.hide_documentation_path && route.path.match(/#{doc_klass.mount_path}($|\/|\(\.)/)
75
+
73
76
  @target_class.combined_routes[resource].unshift route
74
77
  end
75
78
  end
@@ -131,6 +134,7 @@ module Grape
131
134
  def extract_parent_route(name)
132
135
  route_name = name.match(%r{^/?([^/]*).*$})[1]
133
136
  return route_name unless route_name.include? ':'
137
+
134
138
  matches = name.match(/\/[a-z]+/)
135
139
  matches.nil? ? route_name : matches[0].delete('/')
136
140
  end
@@ -32,6 +32,8 @@ module GrapeSwagger
32
32
  target_class = options[:target_class]
33
33
  guard = options[:swagger_endpoint_guard]
34
34
  formatter = options[:format]
35
+ api_doc = options[:api_documentation].dup
36
+ specific_api_doc = options[:specific_api_documentation].dup
35
37
 
36
38
  class_variables_from(options)
37
39
 
@@ -41,6 +43,8 @@ module GrapeSwagger
41
43
  end
42
44
  end
43
45
 
46
+ desc api_doc.delete(:desc), api_doc
47
+
44
48
  instance_eval(guard) unless guard.nil?
45
49
 
46
50
  output_path_definitions = proc do |combi_routes, endpoint|
@@ -67,10 +71,14 @@ module GrapeSwagger
67
71
  output_path_definitions.call(target_class.combined_namespace_routes, self)
68
72
  end
69
73
 
74
+ desc specific_api_doc.delete(:desc), { params:
75
+ specific_api_doc.delete(:params) || {} }.merge(specific_api_doc)
76
+
70
77
  params do
71
78
  requires :name, type: String, desc: 'Resource name of mounted API'
72
79
  optional :locale, type: Symbol, desc: 'Locale of API documentation'
73
80
  end
81
+
74
82
  get "#{mount_path}/:name" do
75
83
  I18n.locale = params[:locale] || I18n.default_locale
76
84
 
@@ -44,8 +44,8 @@ module GrapeSwagger
44
44
  end
45
45
 
46
46
  def deprecated_workflow_for(gem_name)
47
- warn "DEPRECATED: You using old #{gem_name} version, wich not provides" \
48
- "required attributes, to solve this problem please update #{gem_name}"
47
+ warn "DEPRECATED: You are using old #{gem_name} version, which doesn't provide " \
48
+ "required attributes. To solve this problem, please update #{gem_name}"
49
49
  end
50
50
  end
51
51
  end
@@ -44,6 +44,7 @@ module GrapeSwagger
44
44
 
45
45
  def setup_definition(def_extension, path, definitions)
46
46
  return unless def_extension.key?(:for)
47
+
47
48
  status = def_extension[:for]
48
49
 
49
50
  definition = find_definition(status, path)
@@ -60,6 +61,7 @@ module GrapeSwagger
60
61
 
61
62
  def add_extension_to(part, extensions)
62
63
  return if part.nil?
64
+
63
65
  concatenate(extensions).each do |key, value|
64
66
  part[key] = value unless key.start_with?('x-for')
65
67
  end
@@ -94,6 +94,7 @@ module GrapeSwagger
94
94
  property_keys.each_with_object({}) do |x, memo|
95
95
  value = param[x]
96
96
  next if value.blank?
97
+
97
98
  if x == :type && @definitions[value].present?
98
99
  memo['$ref'] = "#/definitions/#{value}"
99
100
  else
@@ -207,7 +208,7 @@ module GrapeSwagger
207
208
  end
208
209
 
209
210
  def property_keys
210
- %i[type format description minimum maximum items enum]
211
+ %i[type format description minimum maximum items enum default]
211
212
  end
212
213
 
213
214
  def deletable?(param)
@@ -7,6 +7,7 @@ module GrapeSwagger
7
7
  def build(key, options, request = nil)
8
8
  if options[key]
9
9
  return evaluate(key, options, request) if options[key].is_a?(Proc)
10
+
10
11
  options[key]
11
12
  else
12
13
  request.send(default_values[key])
@@ -6,6 +6,7 @@ module GrapeSwagger
6
6
  class << self
7
7
  def call(*args)
8
8
  return ['application/json'] unless args.flatten.present?
9
+
9
10
  args.flatten.map { |x| Grape::ContentTypes::CONTENT_TYPES[x] || x }.uniq
10
11
  end
11
12
  end
@@ -172,6 +172,7 @@ module Grape
172
172
 
173
173
  def consumes_object(route, format)
174
174
  return unless SUPPORTS_CONSUMES.include?(route.request_method.downcase.to_sym)
175
+
175
176
  GrapeSwagger::DocMethods::ProducesConsumes.call(route.settings.dig(:description, :consumes) || format)
176
177
  end
177
178
 
@@ -321,6 +322,7 @@ module Grape
321
322
  model_name = model_name(model)
322
323
 
323
324
  return model_name if @definitions.key?(model_name)
325
+
324
326
  @definitions[model_name] = nil
325
327
 
326
328
  parser = GrapeSwagger.model_parsers.find(model)
@@ -345,6 +347,7 @@ module Grape
345
347
  route_hidden = route.settings.try(:[], :swagger).try(:[], :hidden)
346
348
  route_hidden = route.options[:hidden] if route.options.key?(:hidden)
347
349
  return route_hidden unless route_hidden.is_a?(Proc)
350
+
348
351
  options[:token_owner] ? route_hidden.call(send(options[:token_owner].to_sym)) : route_hidden.call
349
352
  end
350
353
  end
@@ -51,8 +51,10 @@ module GrapeSwagger
51
51
  def param_type_is_array?(param_type)
52
52
  return false unless param_type
53
53
  return true if param_type == 'Array'
54
+
54
55
  param_types = param_type.match(/\[(.*)\]$/)
55
56
  return false unless param_types
57
+
56
58
  param_types = param_types[0].split(',') if param_types
57
59
  param_types.size == 1
58
60
  end
@@ -64,6 +66,7 @@ module GrapeSwagger
64
66
  def public_parameter?(param)
65
67
  param_options = param.last
66
68
  return true unless param_options.key?(:documentation) && !param_options[:required]
69
+
67
70
  param_hidden = param_options[:documentation].fetch(:hidden, false)
68
71
  param_hidden = param_hidden.call if param_hidden.is_a?(Proc)
69
72
  !param_hidden
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeSwagger
4
- VERSION = '0.31.0'
4
+ VERSION = '0.31.1'
5
5
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'API with additional options' do
6
+ let(:api) do
7
+ Class.new(Grape::API) do
8
+ add_swagger_documentation \
9
+ api_documentation: { desc: 'Swagger compatible API description' },
10
+ specific_api_documentation: { desc: 'Swagger compatible API description for specific API' }
11
+ end
12
+ end
13
+
14
+ subject do
15
+ api.routes.map do |route|
16
+ route.settings[:description]
17
+ end
18
+ end
19
+
20
+ it 'documents api' do
21
+ expect(subject).to eq(
22
+ [
23
+ { description: 'Swagger compatible API description' },
24
+ {
25
+ description: 'Swagger compatible API description for specific API',
26
+ params: {
27
+ 'locale' => {
28
+ desc: 'Locale of API documentation',
29
+ required: false,
30
+ type: 'Symbol'
31
+ },
32
+ 'name' => {
33
+ desc: 'Resource name of mounted API',
34
+ required: true,
35
+ type: 'String'
36
+ }
37
+ }
38
+ }
39
+ ]
40
+ )
41
+ end
42
+ end
@@ -41,7 +41,7 @@ describe 'format, content_type' do
41
41
  { 'declared_params' => declared(params) }
42
42
  end
43
43
 
44
- desc 'This uses produces for produces',
44
+ desc 'This uses consumes for consumes',
45
45
  failure: [{ code: 400, model: Entities::ApiError }],
46
46
  consumes: ['application/www_url_encoded'],
47
47
  entity: Entities::UseResponse
@@ -28,6 +28,7 @@ class SampleAuth < Grape::Middleware::Base
28
28
  context.protected_endpoint = context.options[:route_options][:auth].present?
29
29
 
30
30
  return unless context.protected_endpoint?
31
+
31
32
  scopes = context.options[:route_options][:auth][:scopes]
32
33
  authorize!(*scopes) unless scopes.include? false
33
34
  context.access_token = env['HTTP_AUTHORIZATION']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.31.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Vandecasteele
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-22 00:00:00.000000000 Z
11
+ date: 2018-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -115,6 +115,7 @@ files:
115
115
  - spec/support/model_parsers/representable_parser.rb
116
116
  - spec/support/namespace_tags.rb
117
117
  - spec/support/the_paths_definitions.rb
118
+ - spec/swagger_v2/api_documentation_spec.rb
118
119
  - spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb
119
120
  - spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb
120
121
  - spec/swagger_v2/api_swagger_v2_detail_spec.rb
@@ -148,7 +149,7 @@ files:
148
149
  - spec/swagger_v2/grape-swagger_spec.rb
149
150
  - spec/swagger_v2/guarded_endpoint_spec.rb
150
151
  - spec/swagger_v2/hide_api_spec.rb
151
- - spec/swagger_v2/host.rb
152
+ - spec/swagger_v2/host_spec.rb
152
153
  - spec/swagger_v2/mount_override_api_spec.rb
153
154
  - spec/swagger_v2/mounted_target_class_spec.rb
154
155
  - spec/swagger_v2/namespace_tags_prefix_spec.rb
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
189
  version: '0'
189
190
  requirements: []
190
191
  rubyforge_project:
191
- rubygems_version: 2.7.7
192
+ rubygems_version: 2.7.6
192
193
  signing_key:
193
194
  specification_version: 4
194
195
  summary: Add auto generated documentation to your Grape API that can be displayed
@@ -234,6 +235,7 @@ test_files:
234
235
  - spec/support/model_parsers/representable_parser.rb
235
236
  - spec/support/namespace_tags.rb
236
237
  - spec/support/the_paths_definitions.rb
238
+ - spec/swagger_v2/api_documentation_spec.rb
237
239
  - spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb
238
240
  - spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb
239
241
  - spec/swagger_v2/api_swagger_v2_detail_spec.rb
@@ -267,7 +269,7 @@ test_files:
267
269
  - spec/swagger_v2/grape-swagger_spec.rb
268
270
  - spec/swagger_v2/guarded_endpoint_spec.rb
269
271
  - spec/swagger_v2/hide_api_spec.rb
270
- - spec/swagger_v2/host.rb
272
+ - spec/swagger_v2/host_spec.rb
271
273
  - spec/swagger_v2/mount_override_api_spec.rb
272
274
  - spec/swagger_v2/mounted_target_class_spec.rb
273
275
  - spec/swagger_v2/namespace_tags_prefix_spec.rb