grape-swagger 1.1.0 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -0
  3. data/.github/workflows/rubocop.yml +26 -0
  4. data/.github/workflows/ruby.yml +30 -0
  5. data/.gitignore +1 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +65 -2
  8. data/.rubocop_todo.yml +1 -1
  9. data/CHANGELOG.md +66 -0
  10. data/Gemfile +9 -4
  11. data/README.md +213 -13
  12. data/UPGRADING.md +38 -0
  13. data/grape-swagger.gemspec +4 -4
  14. data/lib/grape-swagger/doc_methods/build_model_definition.rb +53 -2
  15. data/lib/grape-swagger/doc_methods/data_type.rb +4 -4
  16. data/lib/grape-swagger/doc_methods/format_data.rb +4 -2
  17. data/lib/grape-swagger/doc_methods/move_params.rb +6 -7
  18. data/lib/grape-swagger/doc_methods/operation_id.rb +2 -2
  19. data/lib/grape-swagger/doc_methods/parse_params.rb +51 -9
  20. data/lib/grape-swagger/doc_methods.rb +65 -62
  21. data/lib/grape-swagger/endpoint.rb +83 -32
  22. data/lib/grape-swagger/errors.rb +2 -0
  23. data/lib/grape-swagger/model_parsers.rb +2 -2
  24. data/lib/grape-swagger/rake/oapi_tasks.rb +3 -1
  25. data/lib/grape-swagger/version.rb +1 -1
  26. data/lib/grape-swagger.rb +7 -4
  27. data/spec/issues/427_entity_as_string_spec.rb +1 -1
  28. data/spec/issues/430_entity_definitions_spec.rb +7 -5
  29. data/spec/issues/537_enum_values_spec.rb +1 -0
  30. data/spec/issues/776_multiple_presents_spec.rb +59 -0
  31. data/spec/issues/809_utf8_routes_spec.rb +55 -0
  32. data/spec/issues/832_array_hash_float_decimal_spec.rb +111 -0
  33. data/spec/lib/data_type_spec.rb +12 -0
  34. data/spec/lib/format_data_spec.rb +24 -0
  35. data/spec/lib/move_params_spec.rb +2 -2
  36. data/spec/spec_helper.rb +1 -1
  37. data/spec/support/empty_model_parser.rb +3 -2
  38. data/spec/support/mock_parser.rb +1 -2
  39. data/spec/support/model_parsers/entity_parser.rb +8 -8
  40. data/spec/support/model_parsers/mock_parser.rb +24 -8
  41. data/spec/support/model_parsers/representable_parser.rb +8 -8
  42. data/spec/support/namespace_tags.rb +3 -0
  43. data/spec/support/the_paths_definitions.rb +4 -4
  44. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +83 -0
  45. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +1 -1
  46. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +1 -0
  47. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +73 -1
  48. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +2 -2
  49. data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +4 -2
  50. data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +53 -0
  51. data/spec/swagger_v2/api_swagger_v2_spec.rb +1 -0
  52. data/spec/swagger_v2/boolean_params_spec.rb +4 -1
  53. data/spec/swagger_v2/float_api_spec.rb +1 -0
  54. data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +57 -0
  55. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +1 -0
  56. data/spec/swagger_v2/param_multi_type_spec.rb +2 -0
  57. data/spec/swagger_v2/param_type_spec.rb +3 -0
  58. data/spec/swagger_v2/param_values_spec.rb +6 -0
  59. data/spec/swagger_v2/{params_array_collection_fromat_spec.rb → params_array_collection_format_spec.rb} +0 -0
  60. data/spec/swagger_v2/params_example_spec.rb +40 -0
  61. data/spec/swagger_v2/reference_entity_spec.rb +74 -29
  62. data/spec/swagger_v2/security_requirement_spec.rb +2 -2
  63. data/spec/swagger_v2/simple_mounted_api_spec.rb +3 -0
  64. metadata +31 -13
  65. data/.travis.yml +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: beb6baac3bba57a4fd27f01c8129fbd128c0c88426f1408784f1e77ef870c65a
4
- data.tar.gz: 88234909ace085c8b63f0534630ae8856eb15d383bee856c9fcc57079d0060a1
3
+ metadata.gz: 5d7b364d5b11e9fb35f7c67ce09c2953a7dd50da37cde1bc5b323bbdf9a3b6e4
4
+ data.tar.gz: 6c825fe6753c899c7f337253495677596acd40320e5e33f83c7c220e71e03e44
5
5
  SHA512:
6
- metadata.gz: 3b50e2b60fb3d4a1876bac4587f740c27a624c02726153746dc79e76fb1a233d04a3b1b15844bf65a337484d551ac6ea84b04c85c1537138dfc4327149cbb654
7
- data.tar.gz: 32a0e9014bf782a0f5a5417a307bf9325986d7d9df662e73174525792e9103d2a3ec3c4f8b3d7fbdc72829d7514ba299dd62adb361085020f37b104f9a29ee25
6
+ metadata.gz: d5e2a5c0d06216c3e2a474051b5986a9f8343a351714b3e255396bbef3984704d85436218fa87e39f0988fbb18b3f5227b2531d514a788f4a4b131028dc19de2
7
+ data.tar.gz: 6bd210a20332285224d0d24036b9892c729fc84c435991b3e36dd81d8d1976d4ae35c406d3e9d742a82bd90acac75903355c6a827380870e6f1deb2af0b17b7f
@@ -0,0 +1,14 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "weekly"
12
+ day: "friday"
13
+ assignees:
14
+ - "LeFnord"
@@ -0,0 +1,26 @@
1
+ name: Rubocop
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - '*'
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+
11
+ jobs:
12
+ rubocop:
13
+ name: Rubocop
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: '3.0'
20
+ - run: gem install rubocop --no-doc
21
+ - run: rubocop --format progress --format json --out rubocop.json
22
+ id: rubocop
23
+ - uses: duderman/rubocop-annotate-action@v0.1.0
24
+ with:
25
+ path: rubocop.json
26
+ if: ${{ failure() }}
@@ -0,0 +1,30 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - '*'
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+
11
+ jobs:
12
+ rspec:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby-version: ['2.6', '2.7', '3.0', 'head']
17
+ grape-version: [1.6.0, 1.5.3]
18
+ model-parser: [grape-swagger-entity, grape-swagger-representable, '']
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
24
+ with:
25
+ ruby-version: ${{ matrix.ruby-version }}
26
+ GRAPE_VERSION: ${{ matrix.grape-version }}
27
+ MODEL_PARSER: ${{ matrix.model-parser }}
28
+ bundler-cache: true
29
+ - name: Run rspec
30
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -42,3 +42,4 @@ spec/params_entity_spec.rb
42
42
  vendor/bundle/
43
43
  spec/swagger_v2/x-dummy.rb
44
44
  coverage/
45
+ .byebug_history
data/.rspec CHANGED
@@ -1 +1,3 @@
1
1
  --color
2
+ --profile
3
+ --format documentation
data/.rubocop.yml CHANGED
@@ -4,13 +4,18 @@ AllCops:
4
4
  Exclude:
5
5
  - vendor/**/*
6
6
  - example/**/*
7
- TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+ TargetRubyVersion: 3.0
9
+ SuggestExtensions: false
8
10
 
9
11
  # Layout stuff
10
12
  #
11
13
  Layout/EmptyLinesAroundArguments:
12
14
  Enabled: false
13
15
 
16
+ Layout/EmptyLinesAroundAttributeAccessor:
17
+ Enabled: true
18
+
14
19
  Layout/FirstHashElementIndentation:
15
20
  EnforcedStyle: consistent
16
21
 
@@ -24,6 +29,19 @@ Layout/SpaceAroundMethodCallOperator:
24
29
 
25
30
  # Lint stuff
26
31
  #
32
+ Lint/ConstantDefinitionInBlock:
33
+ Exclude:
34
+ - spec/**/*
35
+
36
+ Lint/DeprecatedOpenSSLConstant:
37
+ Enabled: true
38
+
39
+ Lint/DuplicateElsifCondition:
40
+ Enabled: true
41
+
42
+ Lint/MixedRegexpCaptureTypes:
43
+ Enabled: true
44
+
27
45
  Lint/RaiseException:
28
46
  Enabled: true
29
47
 
@@ -37,7 +55,10 @@ Metrics/BlockLength:
37
55
  - spec/**/*
38
56
 
39
57
  Metrics/ClassLength:
40
- Max: 300
58
+ Max: 350
59
+
60
+ Metrics/CyclomaticComplexity:
61
+ Max: 17
41
62
 
42
63
  Metrics/MethodLength:
43
64
  Exclude:
@@ -50,12 +71,36 @@ Naming:
50
71
 
51
72
  # Style stuff
52
73
  #
74
+ Style/AccessorGrouping:
75
+ Enabled: true
76
+
77
+ Style/AsciiComments:
78
+ Enabled: false
79
+
80
+ Style/ArrayCoercion:
81
+ Enabled: true
82
+
83
+ Style/BisectedAttrAccessor:
84
+ Enabled: true
85
+
86
+ Style/CaseLikeIf:
87
+ Enabled: true
88
+
53
89
  Style/ExponentialNotation:
54
90
  Enabled: true
55
91
 
92
+ Style/ExplicitBlockArgument:
93
+ Enabled: false
94
+
95
+ Style/HashAsLastArrayItem:
96
+ Enabled: true
97
+
56
98
  Style/HashEachMethods:
57
99
  Enabled: true
58
100
 
101
+ Style/HashLikeCase:
102
+ Enabled: true
103
+
59
104
  Style/HashTransformKeys:
60
105
  Enabled: true
61
106
 
@@ -64,3 +109,21 @@ Style/HashTransformValues:
64
109
 
65
110
  Style/RegexpLiteral:
66
111
  Enabled: false
112
+
113
+ Style/RedundantAssignment:
114
+ Enabled: true
115
+
116
+ Style/RedundantFetchBlock:
117
+ Enabled: true
118
+
119
+ Style/RedundantFileExtensionInRequire:
120
+ Enabled: true
121
+
122
+ Style/RedundantRegexpCharacterClass:
123
+ Enabled: true
124
+
125
+ Style/RedundantRegexpEscape:
126
+ Enabled: true
127
+
128
+ Style/SlicingWithRange:
129
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -28,7 +28,7 @@ Metrics/MethodLength:
28
28
 
29
29
  # Offense count: 7
30
30
  Metrics/PerceivedComplexity:
31
- Max: 14
31
+ Max: 16
32
32
 
33
33
  # Offense count: 3
34
34
  Style/ClassVars:
data/CHANGELOG.md CHANGED
@@ -9,6 +9,72 @@
9
9
  * Your contribution here.
10
10
 
11
11
 
12
+ ### 1.4.2 (October 22, 2021)
13
+
14
+ #### Fixes
15
+
16
+ * [#840](https://github.com/ruby-grape/grape-swagger/pull/840): Fixes documentation of `additionalProperties` field when used with array parameters, or when setting it to `false` - [@magni-](https://github.com/magni-)
17
+ * [#841](https://github.com/ruby-grape/grape-swagger/pull/839): Fixes `type` and `format` values for object fields nested in an array ([#832](https://github.com/ruby-grape/grape-swagger/issue/832)) - [@magni-](https://github.com/magni-)
18
+ * [#839](https://github.com/ruby-grape/grape-swagger/pull/839): Fixes documentation of `false` or `nil` default parameter values - [@magni-](https://github.com/magni-)
19
+
20
+
21
+ ### 1.4.1 (September 15, 2021)
22
+
23
+ #### Fixes
24
+
25
+ * [#833](https://github.com/ruby-grape/grape-swagger/pull/833): Fixes issue of examples not showing for `in: 'body'` parameters - [@stevenou](https://github.com/stevenou)
26
+
27
+
28
+ ### 1.4.0 (March 20, 2021)
29
+
30
+ #### Features
31
+
32
+ * [#818](https://github.com/ruby-grape/grape-swagger/pull/818): Adds ruby 3.0 support - [@LeFnord](https://github.com/LeFnord).
33
+ * [#815](https://github.com/ruby-grape/grape-swagger/pull/815): Add required for multiple presents - [@MaximeRDY](https://github.com/MaximeRDY).
34
+
35
+ #### Fixes
36
+
37
+ * [#822](https://github.com/ruby-grape/grape-swagger/pull/822): Corrected the related parameter lookup on request params - [@Jack12816](https://github.com/Jack12816).
38
+
39
+
40
+ ### 1.3.1 (November 1, 2020)
41
+
42
+ #### Features
43
+
44
+ * [#813](https://github.com/ruby-grape/grape-swagger/pull/813): Handle multiple presents - [@AntoineGuestin](https://github.com/AntoineGuestin).
45
+
46
+ #### Fixes
47
+
48
+ * [#811](https://github.com/ruby-grape/grape-swagger/pull/811): Fixes #809: supports utf8 route names - [@LeFnord](https://github.com/LeFnord).
49
+
50
+
51
+ ### 1.3.0 (September 3, 2020)
52
+
53
+ #### Features
54
+
55
+ * [#804](https://github.com/ruby-grape/grape-swagger/pull/804): Don't overwrite model description with the route description - [@Bhacaz](https://github.com/Bhacaz).
56
+
57
+
58
+ ### 1.2.1 (July 15, 2020)
59
+
60
+ #### Fixes
61
+
62
+ * [#801](https://github.com/ruby-grape/grape-swagger/pull/801): Fixes behaviour after grape upgrade to 1.4.0 - [@LeFnord](https://github.com/LeFnord).
63
+
64
+
65
+ ### 1.2.0 (July 1, 2020)
66
+
67
+ #### Features
68
+
69
+ * [#794](https://github.com/ruby-grape/grape-swagger/pull/794): Allow `entity_name` to be inherited, fixes issue #659 - [@urkle](https://github.com/urkle).
70
+ * [#793](https://github.com/ruby-grape/grape-swagger/pull/793): Features/inheritance and discriminator - [@MaximeRDY](https://github.com/MaximeRDY).
71
+
72
+ #### Fixes
73
+
74
+ * [#798](https://github.com/ruby-grape/grape-swagger/pull/798): Modify full entity name separator - [@GarrettB71](https://github.com/GarrettB71).
75
+ * [#796](https://github.com/ruby-grape/grape-swagger/pull/796): Support grape 1.4.0 - [@thedanielhanke](https://github.com/thedanielhanke).
76
+
77
+
12
78
  ### 1.1.0 (April 20, 2020)
13
79
 
14
80
  #### Features
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.5.0'
10
10
  when 'HEAD'
11
11
  { git: 'https://github.com/ruby-grape/grape' }
12
12
  else
@@ -14,6 +14,7 @@ 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'
@@ -26,12 +27,16 @@ group :development, :test do
26
27
  gem 'rake'
27
28
  gem 'rdoc'
28
29
  gem 'rspec', '~> 3.9'
29
- gem 'rubocop', '~> 0.82', require: false
30
+ gem 'rubocop', '~> 1.0', 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
- gem 'ruby-grape-danger', '~> 0.1.1', require: false
35
+
36
+ gem 'ruby-grape-danger', '~> 0.2.0', 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,16 +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 |
55
- >= 1.0.0 | 2.0 | >= 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 |
56
56
 
57
57
 
58
58
  ## Swagger-Spec <a name="swagger-spec"></a>
@@ -451,6 +451,8 @@ add_swagger_documentation \
451
451
  * [Collection Format](#collection-format)
452
452
  * [Hiding parameters](#hiding-parameters)
453
453
  * [Setting a Swagger default value](#default-value)
454
+ * [Setting `additionalProperties` for `object`-type parameters](#additional-properties)
455
+ * [Example parameter value](#param-example)
454
456
  * [Response documentation](#response)
455
457
  * [Changing default status codes](#change-status)
456
458
  * [File response](#file-response)
@@ -458,6 +460,7 @@ add_swagger_documentation \
458
460
  * [Response examples documentation](#response-examples)
459
461
  * [Response headers documentation](#response-headers)
460
462
  * [Adding root element to responses](#response-root)
463
+ * [Multiple present Response](#multiple-response)
461
464
 
462
465
  #### Swagger Header Parameters <a name="headers"></a>
463
466
 
@@ -768,8 +771,6 @@ params do
768
771
  end
769
772
  ```
770
773
 
771
- The example parameter will populate the Swagger UI with the example value, and can be used for optional or required parameters.
772
-
773
774
  Grape uses the option `default` to set a default value for optional parameters. This is different in that Grape will set your parameter to the provided default if the parameter is omitted, whereas the example value above will only set the value in the UI itself. This will set the Swagger `defaultValue` to the provided value. Note that the example value will override the Grape default value.
774
775
 
775
776
  ```ruby
@@ -779,6 +780,46 @@ params do
779
780
  end
780
781
  ```
781
782
 
783
+ ### Setting `additionalProperties` for `object`-type parameters <a name="additional-properties">
784
+
785
+ Use the `additional_properties` option in the `documentation` hash for `object`-type parameters to set [`additionalProperties`](https://swagger.io/specification/v2/#model-with-mapdictionary-properties).
786
+
787
+ #### Allow any additional properties
788
+ ```ruby
789
+ params do
790
+ optional :thing, type: Hash, documentation: { additional_properties: true }
791
+ end
792
+ ```
793
+
794
+ #### Allow any additional properties of a particular type
795
+ ```ruby
796
+ params do
797
+ optional :thing, type: Hash, documentation: { additional_properties: String }
798
+ end
799
+ ```
800
+
801
+ #### Allow any additional properties matching a defined schema
802
+ ```ruby
803
+ class Entity < Grape::Entity
804
+ expose :this
805
+ end
806
+
807
+ params do
808
+ optional :thing, type: Hash, documentation: { additional_properties: Entity }
809
+ end
810
+ ```
811
+
812
+
813
+ #### Example parameter value <a name="param-example"></a>
814
+
815
+ The example parameter will populate the Swagger UI with the example value, and can be used for optional or required parameters.
816
+
817
+ ```ruby
818
+ params do
819
+ requires :id, type: Integer, documentation: { example: 123 }
820
+ optional :name, type String, documentation: { example: 'Buddy Guy' }
821
+ end
822
+ ```
782
823
 
783
824
  #### Expose nested namespace as standalone route
784
825
 
@@ -859,10 +900,11 @@ get '/thing', failure: [
859
900
  end
860
901
  ```
861
902
 
862
- By adding a `model` key, e.g. this would be taken.
903
+ By adding a `model` key, e.g. this would be taken. Setting an empty string will act like an empty body.
863
904
  ```ruby
864
905
  get '/thing', failure: [
865
906
  { code: 400, message: 'General error' },
907
+ { code: 403, message: 'Forbidden error', model: '' },
866
908
  { code: 422, message: 'Invalid parameter entry', model: Entities::ApiError }
867
909
  ] do
868
910
  # ...
@@ -1261,6 +1303,76 @@ The result will look like following:
1261
1303
  }
1262
1304
  }
1263
1305
  ```
1306
+ #### Multiple present Response <a name="multiple-response"></a>
1307
+
1308
+ You can specify a custom multiple response by using the `as` key:
1309
+ ```ruby
1310
+ desc 'Multiple response',
1311
+ success: [
1312
+ { model: Entities::EnumValues, as: :gender },
1313
+ { model: Entities::Something, as: :somethings }
1314
+ ]
1315
+ end
1316
+
1317
+ get '/things' do
1318
+ ...
1319
+ end
1320
+ ```
1321
+ The result will look like following:
1322
+ ```
1323
+ "responses": {
1324
+ "200": {
1325
+ "description": "Multiple response",
1326
+ "schema":{
1327
+ "type":"object",
1328
+ "properties":{
1329
+ "gender":{
1330
+ "$ref":"#/definitions/EnumValues"
1331
+ },
1332
+ "somethings":{
1333
+ "$ref":"#/definitions/Something"
1334
+ }
1335
+ }
1336
+ }
1337
+ }
1338
+ }
1339
+ ```
1340
+ You can also specify if the response is an array, with the `is_array` key:
1341
+ ```ruby
1342
+ desc 'Multiple response with array',
1343
+ success: [
1344
+ { model: Entities::EnumValues, as: :gender },
1345
+ { model: Entities::Something, as: :somethings, is_array: true, required: true }
1346
+ ]
1347
+ end
1348
+
1349
+ get '/things' do
1350
+ ...
1351
+ end
1352
+ ```
1353
+ The result will look like following:
1354
+ ```
1355
+ "responses": {
1356
+ "200": {
1357
+ "description": "Multiple response with array",
1358
+ "schema":{
1359
+ "type":"object",
1360
+ "properties":{
1361
+ "gender":{
1362
+ "$ref":"#/definitions/EnumValues"
1363
+ },
1364
+ "somethings":{
1365
+ "type":"array",
1366
+ "items":{
1367
+ "$ref":"#/definitions/Something"
1368
+ }
1369
+ }
1370
+ },
1371
+ "required": ["somethings"]
1372
+ }
1373
+ }
1374
+ }
1375
+ ```
1264
1376
 
1265
1377
  ## Using Grape Entities <a name="grape-entity"></a>
1266
1378
 
@@ -1381,6 +1493,94 @@ module API
1381
1493
  end
1382
1494
  ```
1383
1495
 
1496
+ #### Inheritance with allOf and discriminator
1497
+ ```ruby
1498
+ module Entities
1499
+ class Pet < Grape::Entity
1500
+ expose :type, documentation: {
1501
+ type: 'string',
1502
+ is_discriminator: true,
1503
+ required: true
1504
+ }
1505
+ expose :name, documentation: {
1506
+ type: 'string',
1507
+ required: true
1508
+ }
1509
+ end
1510
+
1511
+ class Cat < Pet
1512
+ expose :huntingSkill, documentation: {
1513
+ type: 'string',
1514
+ description: 'The measured skill for hunting',
1515
+ default: 'lazy',
1516
+ values: %w[
1517
+ clueless
1518
+ lazy
1519
+ adventurous
1520
+ aggressive
1521
+ ]
1522
+ }
1523
+ end
1524
+ end
1525
+ ```
1526
+
1527
+ Should generate this definitions:
1528
+ ```JSON
1529
+ {
1530
+ "definitions": {
1531
+ "Pet": {
1532
+ "type": "object",
1533
+ "discriminator": "petType",
1534
+ "properties": {
1535
+ "name": {
1536
+ "type": "string"
1537
+ },
1538
+ "petType": {
1539
+ "type": "string"
1540
+ }
1541
+ },
1542
+ "required": [
1543
+ "name",
1544
+ "petType"
1545
+ ]
1546
+ },
1547
+ "Cat": {
1548
+ "description": "A representation of a cat",
1549
+ "allOf": [
1550
+ {
1551
+ "$ref": "#/definitions/Pet"
1552
+ },
1553
+ {
1554
+ "type": "object",
1555
+ "properties": {
1556
+ "huntingSkill": {
1557
+ "type": "string",
1558
+ "description": "The measured skill for hunting",
1559
+ "default": "lazy",
1560
+ "enum": [
1561
+ "clueless",
1562
+ "lazy",
1563
+ "adventurous",
1564
+ "aggressive"
1565
+ ]
1566
+ },
1567
+ "petType": {
1568
+ "type": "string",
1569
+ "enum": ["Cat"]
1570
+ }
1571
+ },
1572
+ "required": [
1573
+ "huntingSkill",
1574
+ "petType"
1575
+ ]
1576
+ }
1577
+ ]
1578
+ }
1579
+ }
1580
+ }
1581
+ ```
1582
+
1583
+
1384
1584
 
1385
1585
 
1386
1586
  ## Securing the Swagger UI <a name="oauth"></a>
data/UPGRADING.md CHANGED
@@ -1,5 +1,43 @@
1
1
  ## Upgrading Grape-swagger
2
2
 
3
+ ### Upgrading to >= 1.4.2
4
+
5
+ - `additionalProperties` has been deprecated and will be removed in a future version of `grape-swagger`. It has been replaced with `additional_properties`.
6
+
7
+ ### Upgrading to >= 1.4.0
8
+
9
+ - Official support for ruby < 2.5 removed, ruby 2.5 only in testing mode, but no support.
10
+
11
+ ### Upgrading to >= 1.3.0
12
+
13
+ - The model (entity) description no longer comes from the route description. It will have a default value: `<<EntityName>> model`.
14
+
15
+ ### Upgrading to >= 1.2.0
16
+
17
+ - The entity_name class method is now called on parent classes for inherited entities. Now you can do this
18
+
19
+ ```ruby
20
+ module Some::Long::Module
21
+ class Base < Grape::Entity
22
+ # ... other shared logic
23
+ def self.entity_name
24
+ "V2::#{self.to_s.demodulize}"
25
+ end
26
+ end
27
+
28
+ def MyEntity < Base
29
+ # ....
30
+ end
31
+
32
+ def OtherEntity < Base
33
+ # revert back to the default behavior by hiding the method
34
+ private_class_method :entity_name
35
+ end
36
+ end
37
+ ```
38
+
39
+ - Full class name is modified to use `_` separator (e.g. `A_B_C` instead of `A::B::C`).
40
+
3
41
  ### Upgrading to >= 1.1.0
4
42
 
5
43
  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).
@@ -7,14 +7,14 @@ Gem::Specification.new do |s|
7
7
  s.name = 'grape-swagger'
8
8
  s.version = GrapeSwagger::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
- s.authors = ['Tim Vandecasteele']
11
- s.email = ['tim.vandecasteele@gmail.com']
10
+ s.authors = ['LeFnord', 'Tim Vandecasteele']
11
+ s.email = ['pscholz.le@gmail.com', 'tim.vandecasteele@gmail.com']
12
12
  s.homepage = 'https://github.com/ruby-grape/grape-swagger'
13
13
  s.summary = 'Add auto generated documentation to your Grape API that can be displayed with Swagger.'
14
14
  s.license = 'MIT'
15
15
 
16
- s.required_ruby_version = '>= 2.4'
17
- s.add_runtime_dependency 'grape', '~> 1.3.0'
16
+ s.required_ruby_version = '>= 2.5'
17
+ s.add_runtime_dependency 'grape', '~> 1.3'
18
18
 
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = `git ls-files -- {test,spec}/*`.split("\n")