grape-swagger 0.34.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +83 -0
  3. data/.travis.yml +15 -12
  4. data/CHANGELOG.md +44 -4
  5. data/Gemfile +9 -4
  6. data/README.md +123 -11
  7. data/UPGRADING.md +30 -0
  8. data/grape-swagger.gemspec +1 -1
  9. data/lib/grape-swagger.rb +2 -2
  10. data/lib/grape-swagger/doc_methods/build_model_definition.rb +53 -2
  11. data/lib/grape-swagger/doc_methods/data_type.rb +6 -6
  12. data/lib/grape-swagger/doc_methods/operation_id.rb +2 -2
  13. data/lib/grape-swagger/doc_methods/parse_params.rb +19 -4
  14. data/lib/grape-swagger/endpoint.rb +28 -18
  15. data/lib/grape-swagger/endpoint/params_parser.rb +12 -5
  16. data/lib/grape-swagger/rake/oapi_tasks.rb +10 -2
  17. data/lib/grape-swagger/version.rb +1 -1
  18. data/spec/issues/427_entity_as_string_spec.rb +1 -1
  19. data/spec/issues/430_entity_definitions_spec.rb +7 -5
  20. data/spec/issues/784_extensions_on_params_spec.rb +38 -0
  21. data/spec/lib/data_type_spec.rb +14 -2
  22. data/spec/lib/endpoint/params_parser_spec.rb +2 -1
  23. data/spec/lib/endpoint_spec.rb +1 -1
  24. data/spec/lib/oapi_tasks_spec.rb +15 -5
  25. data/spec/support/empty_model_parser.rb +1 -2
  26. data/spec/support/mock_parser.rb +1 -2
  27. data/spec/support/model_parsers/entity_parser.rb +1 -1
  28. data/spec/support/model_parsers/representable_parser.rb +1 -1
  29. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +14 -3
  30. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +2 -2
  31. data/spec/swagger_v2/boolean_params_spec.rb +1 -1
  32. data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +56 -0
  33. data/spec/swagger_v2/reference_entity_spec.rb +74 -29
  34. data/spec/swagger_v2/security_requirement_spec.rb +2 -2
  35. metadata +15 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 946447e92174e1d9911af39aef0c6d740d103dbe41f79e8250e79c408e2a179e
4
- data.tar.gz: 7b7701dd1623cd93208a9ab093c41ea6f3152eda42331ee81d81d2d206343121
3
+ metadata.gz: 8ced0e59624b64b14e517815c13c6761c970da13cfd7e6d5c82493b1bb49c815
4
+ data.tar.gz: a5891f3a10dc5e3ae96bb1f295dcf1978f0758175160b1681ba5f85f0b7cc206
5
5
  SHA512:
6
- metadata.gz: 568baf91809d39569f6f29ab7d82c99661956d01d103dc82f2dc41c8125f8dba0f0be8a4d7c33af5456f10548cd226071c966a692d9765ab6c22f30694dea46d
7
- data.tar.gz: df556918dba966953bf2e545b4fc05b20555dc30e1c7388bad82b083a67d56bc7a1aa181a1d4ec9bc16fb7d5f88a6fa8af7160c2021ed614041f6f798d57fd23
6
+ metadata.gz: 61c9297050672b095bf2ab8a6648420b6226fa5ecaa2b1b2df07e99c271dba4f1fe9547a77eae5dc4e1b5d0b29035f823e389957b57149f4fb79cf3187597ee9
7
+ data.tar.gz: 55f926c09f83bfe6e0ab15caeac329acf6f6d623d9c579b89c872fdd2f11f5ddece4e0a74259f921688bcf8e2255fecd908fce3f2eb4b2b58ed449803d3c2900
@@ -6,9 +6,14 @@ AllCops:
6
6
  - example/**/*
7
7
  TargetRubyVersion: 2.7
8
8
 
9
+ # Layout stuff
10
+ #
9
11
  Layout/EmptyLinesAroundArguments:
10
12
  Enabled: false
11
13
 
14
+ Layout/EmptyLinesAroundAttributeAccessor:
15
+ Enabled: true
16
+
12
17
  Layout/FirstHashElementIndentation:
13
18
  EnforcedStyle: consistent
14
19
 
@@ -17,6 +22,28 @@ Layout/LineLength:
17
22
  Exclude:
18
23
  - spec/**/*
19
24
 
25
+ Layout/SpaceAroundMethodCallOperator:
26
+ Enabled: true
27
+
28
+ # Lint stuff
29
+ #
30
+ Lint/DeprecatedOpenSSLConstant:
31
+ Enabled: true
32
+
33
+ Lint/DuplicateElsifCondition:
34
+ Enabled: true
35
+
36
+ Lint/MixedRegexpCaptureTypes:
37
+ Enabled: true
38
+
39
+ Lint/RaiseException:
40
+ Enabled: true
41
+
42
+ Lint/StructNewOverride:
43
+ Enabled: true
44
+
45
+ # Metrics stuff
46
+ #
20
47
  Metrics/BlockLength:
21
48
  Exclude:
22
49
  - spec/**/*
@@ -24,12 +51,68 @@ Metrics/BlockLength:
24
51
  Metrics/ClassLength:
25
52
  Max: 300
26
53
 
54
+ Metrics/CyclomaticComplexity:
55
+ Max: 17
56
+
27
57
  Metrics/MethodLength:
28
58
  Exclude:
29
59
  - spec/**/*
30
60
 
61
+ # Naming stuff
62
+ #
31
63
  Naming:
32
64
  Enabled: false
33
65
 
66
+ # Style stuff
67
+ #
68
+ Style/AccessorGrouping:
69
+ Enabled: true
70
+
71
+ Style/ArrayCoercion:
72
+ Enabled: true
73
+
74
+ Style/BisectedAttrAccessor:
75
+ Enabled: true
76
+
77
+ Style/CaseLikeIf:
78
+ Enabled: true
79
+
80
+ Style/ExponentialNotation:
81
+ Enabled: true
82
+
83
+ Style/HashAsLastArrayItem:
84
+ Enabled: true
85
+ Style/HashEachMethods:
86
+ Enabled: true
87
+
88
+ Style/HashLikeCase:
89
+ Enabled: true
90
+
91
+ Style/HashTransformKeys:
92
+ Enabled: true
93
+
94
+ Style/HashTransformValues:
95
+ Enabled: true
96
+
34
97
  Style/RegexpLiteral:
35
98
  Enabled: false
99
+
100
+ Style/RedundantAssignment:
101
+ Enabled: true
102
+
103
+ Style/RedundantFetchBlock:
104
+ Enabled: true
105
+
106
+ Style/RedundantFileExtensionInRequire:
107
+ Enabled: true
108
+
109
+ Style/RedundantRegexpCharacterClass:
110
+ Enabled: true
111
+
112
+ Style/RedundantRegexpEscape:
113
+ Enabled: true
114
+
115
+ Style/SlicingWithRange:
116
+ Enabled: false
117
+
118
+
@@ -1,5 +1,7 @@
1
1
  language: ruby
2
2
 
3
+ os: linux
4
+
3
5
  before_install:
4
6
  - gem install bundler
5
7
 
@@ -7,27 +9,28 @@ after_success:
7
9
  - bundle exec danger
8
10
 
9
11
  rvm:
10
- - 2.5.7
11
- - 2.6.5
12
- - 2.7.0
12
+ - 2.5.8
13
+ - 2.6.6
14
+ - 2.7.1
13
15
  env:
14
- - GRAPE_VERSION=1.2.5 MODEL_PARSER=grape-swagger-entity
15
- - GRAPE_VERSION=1.2.5 MODEL_PARSER=grape-swagger-representable
16
- - GRAPE_VERSION=1.0.3
17
- - GRAPE_VERSION=1.2.5
16
+ - GRAPE_VERSION=1.3.3
17
+ - GRAPE_VERSION=1.4.0 MODEL_PARSER=grape-swagger-entity
18
+ - GRAPE_VERSION=1.4.0 MODEL_PARSER=grape-swagger-representable
19
+ - GRAPE_VERSION=1.4.0
20
+ - GRAPE_VERSION=HEAD
18
21
 
19
- matrix:
22
+ jobs:
20
23
  fast_finish: true
21
24
 
22
25
  include:
23
- - rvm: 2.4.9
24
- env: GRAPE_VERSION=1.2.5
26
+ - rvm: 2.4.10
27
+ env:
25
28
  - rvm: ruby-head
26
- env: GRAPE_VERSION=HEAD
29
+ env:
27
30
  - rvm: jruby-head
28
31
  env:
29
32
 
30
33
  allow_failures:
31
- - rvm: 2.4.9
34
+ - rvm: 2.4.10
32
35
  - rvm: ruby-head
33
36
  - rvm: jruby-head
@@ -9,6 +9,50 @@
9
9
  * Your contribution here.
10
10
 
11
11
 
12
+ ### 1.2.1 (July 15, 2020)
13
+
14
+ #### Fixes
15
+
16
+ * [#801](https://github.com/ruby-grape/grape-swagger/pull/801): Fixes behaviour after grape upgrade to 1.4.0 - [@LeFnord](https://github.com/LeFnord).
17
+
18
+
19
+ ### 1.2.0 (July 1, 2020)
20
+
21
+ #### Features
22
+
23
+ * [#794](https://github.com/ruby-grape/grape-swagger/pull/794): Allow `entity_name` to be inherited, fixes issue #659 - [@urkle](https://github.com/urkle).
24
+ * [#793](https://github.com/ruby-grape/grape-swagger/pull/793): Features/inheritance and discriminator - [@MaximeRDY](https://github.com/MaximeRDY).
25
+
26
+ #### Fixes
27
+
28
+ * [#798](https://github.com/ruby-grape/grape-swagger/pull/798): Modify full entity name separator - [@GarrettB71](https://github.com/GarrettB71).
29
+ * [#796](https://github.com/ruby-grape/grape-swagger/pull/796): Support grape 1.4.0 - [@thedanielhanke](https://github.com/thedanielhanke).
30
+
31
+
32
+ ### 1.1.0 (April 20, 2020)
33
+
34
+ #### Features
35
+
36
+ * [#785](https://github.com/ruby-grape/grape-swagger/pull/785): Add extensions for params - [@MaximeRDY](https://github.com/MaximeRDY).
37
+ * [#782](https://github.com/ruby-grape/grape-swagger/pull/782): Allow passing class name as string for rake task initializer - [@misdoro](https://github.com/misdoro).
38
+ * [#786](https://github.com/ruby-grape/grape-swagger/pull/786): Use full entity name as a default - [@mrexox](https://github.com/mrexox).
39
+
40
+
41
+ ### 1.0.0 (February 10, 2020)
42
+
43
+ #### Features
44
+
45
+ * [#777](https://github.com/ruby-grape/grape-swagger/pull/777): Make usage of grape >= 1.3, rack >= 2.1 - [@LeFnord](https://github.com/LeFnord).
46
+ * [#775](https://github.com/ruby-grape/grape-swagger/pull/775): Add in token_owner support to param hidden procs - [@urkle](https://github.com/urkle).
47
+
48
+
49
+ ### 0.34.2 (January 20, 2020)
50
+
51
+ #### Fixes
52
+
53
+ * [#773](https://github.com/ruby-grape/grape-swagger/pull/773): Freeze rack version to 2.0.8 - [@LeFnord](https://github.com/LeFnord).
54
+
55
+
12
56
  ### 0.34.0 (January 11, 2020)
13
57
 
14
58
  #### Features
@@ -34,10 +78,6 @@
34
78
  * [#743](https://github.com/ruby-grape/grape-swagger/pull/743): CI: use 2.4.6, 2.5.5 - [@olleolleolle](https://github.com/olleolleolle).
35
79
  * [#737](https://github.com/ruby-grape/grape-swagger/pull/737): Add swagger endpoint guard to both doc endpoints - [@urkle](https://github.com/urkle).
36
80
 
37
- #### Changes
38
-
39
- * [#749](https://github.com/ruby-grape/grape-swagger/pull/749) Drop support for Ruby 2.3 and below - [@LeFnord](https://github.com/LeFnord).
40
-
41
81
 
42
82
  ### 0.32.1 (December 7, 2018)
43
83
 
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ ruby RUBY_VERSION
6
6
 
7
7
  gemspec
8
8
 
9
- gem 'grape', case version = ENV['GRAPE_VERSION'] || '< 1.3.0'
9
+ gem 'grape', case version = ENV['GRAPE_VERSION'] || '>= 1.4.0'
10
10
  when 'HEAD'
11
11
  { git: 'https://github.com/ruby-grape/grape' }
12
12
  else
@@ -14,24 +14,29 @@ gem 'grape', case version = ENV['GRAPE_VERSION'] || '< 1.3.0'
14
14
  end
15
15
 
16
16
  gem ENV['MODEL_PARSER'] if ENV.key?('MODEL_PARSER')
17
+
17
18
  group :development, :test do
18
19
  gem 'bundler'
19
20
  gem 'grape-entity'
20
21
  gem 'pry', platforms: [:mri]
21
22
  gem 'pry-byebug', platforms: [:mri]
22
23
 
23
- gem 'rack', '2.0.8'
24
+ gem 'rack', '~> 2.2'
24
25
  gem 'rack-cors'
25
26
  gem 'rack-test'
26
27
  gem 'rake'
27
28
  gem 'rdoc'
28
29
  gem 'rspec', '~> 3.9'
29
- gem 'rubocop', '~> 0.75', require: false
30
+ gem 'rubocop', '~> 0.88', require: false
30
31
  end
31
32
 
32
33
  group :test do
33
34
  gem 'coveralls_reborn', require: false
34
- gem 'grape-swagger-entity'
35
+
35
36
  gem 'ruby-grape-danger', '~> 0.1.1', require: false
36
37
  gem 'simplecov', require: false
38
+
39
+ unless ENV['MODEL_PARSER'] == 'grape-swagger-entity'
40
+ gem 'grape-swagger-entity', git: 'https://github.com/ruby-grape/grape-swagger-entity'
41
+ end
37
42
  end
data/README.md CHANGED
@@ -43,15 +43,16 @@ This screenshot is based on the [Hussars](https://github.com/LeFnord/hussars) sa
43
43
 
44
44
  The following versions of grape, grape-entity and grape-swagger can currently be used together.
45
45
 
46
- grape-swagger | swagger spec | grape | grape-entity | representable |
47
- --------------|--------------|-------------------------|--------------|---------------|
48
- 0.10.5 | 1.2 | >= 0.10.0 ... <= 0.14.0 | < 0.5.0 | n/a |
49
- 0.11.0 | 1.2 | >= 0.16.2 | < 0.5.0 | n/a |
50
- 0.25.2 | 2.0 | >= 0.14.0 ... <= 0.18.0 | <= 0.6.0 | >= 2.4.1 |
51
- 0.26.0 | 2.0 | >= 0.16.2 ... <= 1.1.0 | <= 0.6.1 | >= 2.4.1 |
52
- 0.27.0 | 2.0 | >= 0.16.2 ... <= 1.1.0 | >= 0.5.0 | >= 2.4.1 |
53
- 0.32.0 | 2.0 | >= 0.16.2 | >= 0.5.0 | >= 2.4.1 |
54
- 0.34.0 | 2.0 | >= 0.16.2 ... <= 1.3.0 | >= 0.5.0 | >= 2.4.1 |
46
+ | grape-swagger | swagger spec | grape | grape-entity | representable |
47
+ | ------------- | ------------ | ----------------------- | ------------ | ------------- |
48
+ | 0.10.5 | 1.2 | >= 0.10.0 ... <= 0.14.0 | < 0.5.0 | n/a |
49
+ | 0.11.0 | 1.2 | >= 0.16.2 | < 0.5.0 | n/a |
50
+ | 0.25.2 | 2.0 | >= 0.14.0 ... <= 0.18.0 | <= 0.6.0 | >= 2.4.1 |
51
+ | 0.26.0 | 2.0 | >= 0.16.2 ... <= 1.1.0 | <= 0.6.1 | >= 2.4.1 |
52
+ | 0.27.0 | 2.0 | >= 0.16.2 ... <= 1.1.0 | >= 0.5.0 | >= 2.4.1 |
53
+ | 0.32.0 | 2.0 | >= 0.16.2 | >= 0.5.0 | >= 2.4.1 |
54
+ | 0.34.0 | 2.0 | >= 0.16.2 ... < 1.3.0 | >= 0.5.0 | >= 2.4.1 |
55
+ | >= 1.0.0 | 2.0 | >= 1.3.0 | >= 0.5.0 | >= 2.4.1 |
55
56
 
56
57
 
57
58
  ## Swagger-Spec <a name="swagger-spec"></a>
@@ -743,9 +744,12 @@ end
743
744
  Exclude single optional parameter from the documentation
744
745
 
745
746
  ```ruby
747
+ not_admins = lambda { |token_owner = nil| token_owner.nil? || !token_owner.admin? }
748
+
746
749
  params do
747
750
  optional :one, documentation: { hidden: true }
748
- optional :two, documentation: { hidden: -> { true } }
751
+ optional :two, documentation: { hidden: -> { |t=nil| true } }
752
+ optional :three, documentation: { hidden: not_admins }
749
753
  end
750
754
  post :act do
751
755
  ...
@@ -1080,6 +1084,20 @@ or, for more definitions:
1080
1084
  route_setting :x_def, [{ for: 422, other: 'stuff' }, { for: 200, some: 'stuff' }]
1081
1085
  ```
1082
1086
 
1087
+ - `params` extension, add a `x` key to the `documentation` hash :
1088
+ ```ruby
1089
+ requires :foo, type: String, documentation: { x: { some: 'stuff' } }
1090
+ ```
1091
+ this would generate:
1092
+ ```json
1093
+ {
1094
+ "in": "formData",
1095
+ "name": "foo",
1096
+ "type": "string",
1097
+ "required": true,
1098
+ "x-some": "stuff"
1099
+ }
1100
+ ```
1083
1101
 
1084
1102
  #### Response examples documentation <a name="response-examples"></a>
1085
1103
 
@@ -1363,6 +1381,94 @@ module API
1363
1381
  end
1364
1382
  ```
1365
1383
 
1384
+ #### Inheritance with allOf and discriminator
1385
+ ```ruby
1386
+ module Entities
1387
+ class Pet < Grape::Entity
1388
+ expose :type, documentation: {
1389
+ type: 'string',
1390
+ is_discriminator: true,
1391
+ required: true
1392
+ }
1393
+ expose :name, documentation: {
1394
+ type: 'string',
1395
+ required: true
1396
+ }
1397
+ end
1398
+
1399
+ class Cat < Pet
1400
+ expose :huntingSkill, documentation: {
1401
+ type: 'string',
1402
+ description: 'The measured skill for hunting',
1403
+ default: 'lazy',
1404
+ values: %w[
1405
+ clueless
1406
+ lazy
1407
+ adventurous
1408
+ aggressive
1409
+ ]
1410
+ }
1411
+ end
1412
+ end
1413
+ ```
1414
+
1415
+ Should generate this definitions:
1416
+ ```JSON
1417
+ {
1418
+ "definitions": {
1419
+ "Pet": {
1420
+ "type": "object",
1421
+ "discriminator": "petType",
1422
+ "properties": {
1423
+ "name": {
1424
+ "type": "string"
1425
+ },
1426
+ "petType": {
1427
+ "type": "string"
1428
+ }
1429
+ },
1430
+ "required": [
1431
+ "name",
1432
+ "petType"
1433
+ ]
1434
+ },
1435
+ "Cat": {
1436
+ "description": "A representation of a cat",
1437
+ "allOf": [
1438
+ {
1439
+ "$ref": "#/definitions/Pet"
1440
+ },
1441
+ {
1442
+ "type": "object",
1443
+ "properties": {
1444
+ "huntingSkill": {
1445
+ "type": "string",
1446
+ "description": "The measured skill for hunting",
1447
+ "default": "lazy",
1448
+ "enum": [
1449
+ "clueless",
1450
+ "lazy",
1451
+ "adventurous",
1452
+ "aggressive"
1453
+ ]
1454
+ },
1455
+ "petType": {
1456
+ "type": "string",
1457
+ "enum": ["Cat"]
1458
+ }
1459
+ },
1460
+ "required": [
1461
+ "huntingSkill",
1462
+ "petType"
1463
+ ]
1464
+ }
1465
+ ]
1466
+ }
1467
+ }
1468
+ }
1469
+ ```
1470
+
1471
+
1366
1472
 
1367
1473
 
1368
1474
  ## Securing the Swagger UI <a name="oauth"></a>
@@ -1482,13 +1588,19 @@ end
1482
1588
 
1483
1589
  ## Rake Tasks <a name="rake"></a>
1484
1590
 
1485
- Add these lines to your Rakefile, and initialize the Task class with your Api class – be sure your Api class is available.
1591
+ Add these lines to your Rakefile, and initialize the Task class with your Api class.
1486
1592
 
1487
1593
  ```ruby
1488
1594
  require 'grape-swagger/rake/oapi_tasks'
1489
1595
  GrapeSwagger::Rake::OapiTasks.new(::Api::Base)
1490
1596
  ```
1491
1597
 
1598
+ You may initialize with the class name as a string if the class is not yet loaded at the time Rakefile is parsed:
1599
+ ```ruby
1600
+ require 'grape-swagger/rake/oapi_tasks'
1601
+ GrapeSwagger::Rake::OapiTasks.new('::Api::Base')
1602
+ ```
1603
+
1492
1604
  #### OpenApi/Swagger Documentation
1493
1605
 
1494
1606
  ```