grape-swagger 0.34.0 → 1.2.0

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: 5cba1006ac7becc6885cd6c7fdc8b41cd8929cedb2911391a88e2fb72bb4ea16
4
- data.tar.gz: 412d3cf615993037226e68ae3e84bb5a00087e852b4b8e70d7108589fe68e6a3
3
+ metadata.gz: eae164875a188218b1eb4e0e3a53039f8e661f3dd115b4cc9a6f415b3a92e64b
4
+ data.tar.gz: 6962782ea370ff7b4f84c62ed77f2fe1e7232332f3a238bce4c5af5b62eb1534
5
5
  SHA512:
6
- metadata.gz: '08371ae2468afd4549c02114ba8f5891bdec9109e234e7879d76def080324411f3ccc4ca0c4e389364029238db5f420db99fcabe11a82cb18537e9ad35e8611b'
7
- data.tar.gz: e00dde947780905ebb27cb2b45ee444a5d0dffbb8e6bf51795b90cb1420c03abaf12d013f3aaa53945a70a8c526279e59709c4412d184eab70ec88086cff028c
6
+ metadata.gz: 8b56b026ba97a2308579737c43daf0e9f619df0c91c511e424b533f99105faec83f9ddbcb3dd2f3d98866bffdbdecb13e652f302424f54ec4095c4605405319c
7
+ data.tar.gz: 2e88c630ade44d4c9395a18e690cad717f5a6ba6e6daae81624d0b7e6347f06c9d7d07ce85f16b5eb99ea25c1a716127cd8aac17c1367823ded3bd84151dbc47
@@ -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,25 @@ 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/MixedRegexpCaptureTypes:
34
+ Enabled: true
35
+
36
+ Lint/RaiseException:
37
+ Enabled: true
38
+
39
+ Lint/StructNewOverride:
40
+ Enabled: true
41
+
42
+ # Metrics stuff
43
+ #
20
44
  Metrics/BlockLength:
21
45
  Exclude:
22
46
  - spec/**/*
@@ -24,12 +48,43 @@ Metrics/BlockLength:
24
48
  Metrics/ClassLength:
25
49
  Max: 300
26
50
 
51
+ Metrics/CyclomaticComplexity:
52
+ Max: 17
53
+
27
54
  Metrics/MethodLength:
28
55
  Exclude:
29
56
  - spec/**/*
30
57
 
58
+ # Naming stuff
59
+ #
31
60
  Naming:
32
61
  Enabled: false
33
62
 
63
+ # Style stuff
64
+ #
65
+ Style/ExponentialNotation:
66
+ Enabled: true
67
+
68
+ Style/HashEachMethods:
69
+ Enabled: true
70
+
71
+ Style/HashTransformKeys:
72
+ Enabled: true
73
+
74
+ Style/HashTransformValues:
75
+ Enabled: true
76
+
34
77
  Style/RegexpLiteral:
35
78
  Enabled: false
79
+
80
+ Style/RedundantFetchBlock:
81
+ Enabled: true
82
+
83
+ Style/RedundantRegexpCharacterClass:
84
+ Enabled: true
85
+
86
+ Style/RedundantRegexpEscape:
87
+ Enabled: true
88
+
89
+ Style/SlicingWithRange:
90
+ Enabled: false
@@ -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,20 +9,20 @@ 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.0 MODEL_PARSER=grape-swagger-entity
17
+ - GRAPE_VERSION=1.3.0 MODEL_PARSER=grape-swagger-representable
18
+ - GRAPE_VERSION=1.3.0
19
+ - GRAPE_VERSION=HEAD
18
20
 
19
- matrix:
21
+ jobs:
20
22
  fast_finish: true
21
23
 
22
24
  include:
23
- - rvm: 2.4.9
25
+ - rvm: 2.4.10
24
26
  env:
25
27
  - rvm: ruby-head
26
28
  env:
@@ -28,6 +30,8 @@ matrix:
28
30
  env:
29
31
 
30
32
  allow_failures:
31
- - rvm: 2.4.9
33
+ - rvm: 2.4.10
32
34
  - rvm: ruby-head
33
35
  - rvm: jruby-head
36
+
37
+ - env: GRAPE_VERSION=HEAD
@@ -9,6 +9,43 @@
9
9
  * Your contribution here.
10
10
 
11
11
 
12
+ ### 1.2.0 (July 1, 2020)
13
+
14
+ #### Features
15
+
16
+ * [#794](https://github.com/ruby-grape/grape-swagger/pull/794): Allow `entity_name` to be inherited, fixes issue #659 - [@urkle](https://github.com/urkle).
17
+ * [#793](https://github.com/ruby-grape/grape-swagger/pull/793): Features/inheritance and discriminator - [@MaximeRDY](https://github.com/MaximeRDY).
18
+
19
+ #### Fixes
20
+
21
+ * [#798](https://github.com/ruby-grape/grape-swagger/pull/798): Modify full entity name separator - [@GarrettB71](https://github.com/GarrettB71).
22
+ * [#796](https://github.com/ruby-grape/grape-swagger/pull/796): Support grape 1.4.0 - [@thedanielhanke](https://github.com/thedanielhanke).
23
+
24
+
25
+ ### 1.1.0 (April 20, 2020)
26
+
27
+ #### Features
28
+
29
+ * [#785](https://github.com/ruby-grape/grape-swagger/pull/785): Add extensions for params - [@MaximeRDY](https://github.com/MaximeRDY).
30
+ * [#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).
31
+ * [#786](https://github.com/ruby-grape/grape-swagger/pull/786): Use full entity name as a default - [@mrexox](https://github.com/mrexox).
32
+
33
+
34
+ ### 1.0.0 (February 10, 2020)
35
+
36
+ #### Features
37
+
38
+ * [#777](https://github.com/ruby-grape/grape-swagger/pull/777): Make usage of grape >= 1.3, rack >= 2.1 - [@LeFnord](https://github.com/LeFnord).
39
+ * [#775](https://github.com/ruby-grape/grape-swagger/pull/775): Add in token_owner support to param hidden procs - [@urkle](https://github.com/urkle).
40
+
41
+
42
+ ### 0.34.2 (January 20, 2020)
43
+
44
+ #### Fixes
45
+
46
+ * [#773](https://github.com/ruby-grape/grape-swagger/pull/773): Freeze rack version to 2.0.8 - [@LeFnord](https://github.com/LeFnord).
47
+
48
+
12
49
  ### 0.34.0 (January 11, 2020)
13
50
 
14
51
  #### Features
@@ -34,10 +71,6 @@
34
71
  * [#743](https://github.com/ruby-grape/grape-swagger/pull/743): CI: use 2.4.6, 2.5.5 - [@olleolleolle](https://github.com/olleolleolle).
35
72
  * [#737](https://github.com/ruby-grape/grape-swagger/pull/737): Add swagger endpoint guard to both doc endpoints - [@urkle](https://github.com/urkle).
36
73
 
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
74
 
42
75
  ### 0.32.1 (December 7, 2018)
43
76
 
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.2'
9
+ gem 'grape', case version = ENV['GRAPE_VERSION'] || '>= 1.3.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.2'
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.85', 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,14 +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 |
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 |
54
56
 
55
57
 
56
58
  ## Swagger-Spec <a name="swagger-spec"></a>
@@ -742,9 +744,12 @@ end
742
744
  Exclude single optional parameter from the documentation
743
745
 
744
746
  ```ruby
747
+ not_admins = lambda { |token_owner = nil| token_owner.nil? || !token_owner.admin? }
748
+
745
749
  params do
746
750
  optional :one, documentation: { hidden: true }
747
- optional :two, documentation: { hidden: -> { true } }
751
+ optional :two, documentation: { hidden: -> { |t=nil| true } }
752
+ optional :three, documentation: { hidden: not_admins }
748
753
  end
749
754
  post :act do
750
755
  ...
@@ -1079,6 +1084,20 @@ or, for more definitions:
1079
1084
  route_setting :x_def, [{ for: 422, other: 'stuff' }, { for: 200, some: 'stuff' }]
1080
1085
  ```
1081
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
+ ```
1082
1101
 
1083
1102
  #### Response examples documentation <a name="response-examples"></a>
1084
1103
 
@@ -1362,6 +1381,94 @@ module API
1362
1381
  end
1363
1382
  ```
1364
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
+
1365
1472
 
1366
1473
 
1367
1474
  ## Securing the Swagger UI <a name="oauth"></a>
@@ -1481,13 +1588,19 @@ end
1481
1588
 
1482
1589
  ## Rake Tasks <a name="rake"></a>
1483
1590
 
1484
- 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.
1485
1592
 
1486
1593
  ```ruby
1487
1594
  require 'grape-swagger/rake/oapi_tasks'
1488
1595
  GrapeSwagger::Rake::OapiTasks.new(::Api::Base)
1489
1596
  ```
1490
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
+
1491
1604
  #### OpenApi/Swagger Documentation
1492
1605
 
1493
1606
  ```
@@ -1,5 +1,35 @@
1
1
  ## Upgrading Grape-swagger
2
2
 
3
+ ### Upgrading to >= 1.2.0
4
+
5
+ - The entity_name class method is now called on parent classes for inherited entities. Now you can do this
6
+
7
+ ```ruby
8
+ module Some::Long::Module
9
+ class Base < Grape::Entity
10
+ # ... other shared logic
11
+ def self.entity_name
12
+ "V2::#{self.to_s.demodulize}"
13
+ end
14
+ end
15
+
16
+ def MyEntity < Base
17
+ # ....
18
+ end
19
+
20
+ def OtherEntity < Base
21
+ # revert back to the default behavior by hiding the method
22
+ private_class_method :entity_name
23
+ end
24
+ end
25
+ ```
26
+
27
+ - Full class name is modified to use `_` separator (e.g. `A_B_C` instead of `A::B::C`).
28
+
29
+ ### Upgrading to >= 1.1.0
30
+
31
+ Full class name is used for referencing entity by default (e.g. `A::B::C` instead of just `C`). `Entity` and `Entities` suffixes and prefixes are omitted (e.g. if entity name is `Entities::SomeScope::MyFavourite::Entity` only `SomeScope::MyFavourite` will be used).
32
+
3
33
  ### Upgrading to >= 0.26.1
4
34
 
5
35
  The format can now be specified,