grape-swagger 1.4.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +6 -0
  3. data/.github/workflows/ci.yml +45 -0
  4. data/.rubocop.yml +8 -1
  5. data/.rubocop_todo.yml +31 -11
  6. data/CHANGELOG.md +41 -1
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile +6 -5
  9. data/README.md +73 -8
  10. data/UPGRADING.md +11 -0
  11. data/example/config.ru +2 -2
  12. data/grape-swagger.gemspec +3 -2
  13. data/lib/grape-swagger/doc_methods/build_model_definition.rb +1 -20
  14. data/lib/grape-swagger/doc_methods/move_params.rb +7 -8
  15. data/lib/grape-swagger/doc_methods/parse_params.rb +3 -1
  16. data/lib/grape-swagger/endpoint.rb +49 -6
  17. data/lib/grape-swagger/rake/oapi_tasks.rb +37 -17
  18. data/lib/grape-swagger/version.rb +1 -1
  19. data/lib/grape-swagger.rb +2 -2
  20. data/spec/issues/579_align_put_post_parameters_spec.rb +5 -5
  21. data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +100 -0
  22. data/spec/issues/751_deeply_nested_objects_spec.rb +2 -2
  23. data/spec/issues/847_route_param_options_spec.rb +37 -0
  24. data/spec/lib/move_params_spec.rb +55 -41
  25. data/spec/lib/oapi_tasks_spec.rb +17 -10
  26. data/spec/spec_helper.rb +0 -4
  27. data/spec/swagger_v2/api_documentation_spec.rb +1 -15
  28. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +1 -1
  29. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +7 -7
  30. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +7 -7
  31. data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +4 -2
  32. data/spec/swagger_v2/param_values_spec.rb +1 -1
  33. metadata +10 -114
  34. data/.github/workflows/rubocop.yml +0 -26
  35. data/.github/workflows/ruby.yml +0 -30
  36. data/.ruby-gemset +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d7b364d5b11e9fb35f7c67ce09c2953a7dd50da37cde1bc5b323bbdf9a3b6e4
4
- data.tar.gz: 6c825fe6753c899c7f337253495677596acd40320e5e33f83c7c220e71e03e44
3
+ metadata.gz: 9cff361f819d42d8c3f847c605a31190f82764da573728d043debfe312d30069
4
+ data.tar.gz: faada4385a0db1fec73606585085deec766991007a9f050df1f2c0bbd9e9e018
5
5
  SHA512:
6
- metadata.gz: d5e2a5c0d06216c3e2a474051b5986a9f8343a351714b3e255396bbef3984704d85436218fa87e39f0988fbb18b3f5227b2531d514a788f4a4b131028dc19de2
7
- data.tar.gz: 6bd210a20332285224d0d24036b9892c729fc84c435991b3e36dd81d8d1976d4ae35c406d3e9d742a82bd90acac75903355c6a827380870e6f1deb2af0b17b7f
6
+ metadata.gz: 7a86553f29d5b5a338a0ac21d049845ab609ee4adc2864940813f61384a8bcc19c8b0a644bb484f2b79533a111ab16a51c192236b23f540ed672e5e7a161fb23
7
+ data.tar.gz: 9b5bc29e3ead5f683781cbc0418e3d18f4b056368885e470224bb57ebe03f4232725a971e8589e109240c949aad565e80d5b4ecd31e31f6e5721f0c86c8aaf2f
@@ -12,3 +12,9 @@ updates:
12
12
  day: "friday"
13
13
  assignees:
14
14
  - "LeFnord"
15
+ - package-ecosystem: "github-actions"
16
+ directory: "/"
17
+ schedule:
18
+ interval: weekly
19
+ assignees:
20
+ - "LeFnord"
@@ -0,0 +1,45 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - '*'
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ rubocop:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: '3.2'
22
+ bundler-cache: true
23
+ - name: Run rubocop
24
+ run: bundle exec rubocop --parallel --format progress
25
+
26
+ rspec:
27
+ runs-on: ubuntu-latest
28
+ needs: ['rubocop']
29
+ strategy:
30
+ matrix:
31
+ ruby-version: ['3.0', '3.1', '3.2', 'head']
32
+ grape-version: [1.6.2, 1.7.0]
33
+ model-parser: [grape-swagger-entity, grape-swagger-representable, '']
34
+ steps:
35
+ - name: Check out branch
36
+ uses: actions/checkout@v3
37
+ - name: Set up Ruby
38
+ uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: ${{ matrix.ruby-version }}
41
+ GRAPE_VERSION: ${{ matrix.grape-version }}
42
+ MODEL_PARSER: ${{ matrix.model-parser }}
43
+ bundler-cache: true
44
+ - name: Run rspec rest of the suite
45
+ run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ AllCops:
5
5
  - vendor/**/*
6
6
  - example/**/*
7
7
  NewCops: enable
8
- TargetRubyVersion: 3.0
8
+ TargetRubyVersion: 3.2
9
9
  SuggestExtensions: false
10
10
 
11
11
  # Layout stuff
@@ -101,12 +101,19 @@ Style/HashEachMethods:
101
101
  Style/HashLikeCase:
102
102
  Enabled: true
103
103
 
104
+ Style/HashSyntax:
105
+ Enabled: false
106
+
104
107
  Style/HashTransformKeys:
105
108
  Enabled: true
106
109
 
107
110
  Style/HashTransformValues:
108
111
  Enabled: true
109
112
 
113
+ Style/OpenStructUse:
114
+ Exclude:
115
+ - spec/**/*
116
+
110
117
  Style/RegexpLiteral:
111
118
  Enabled: false
112
119
 
data/.rubocop_todo.yml CHANGED
@@ -1,11 +1,19 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-06-05 12:13:59 +0000 using RuboCop version 0.71.0.
3
+ # on 2022-01-14 10:22:29 UTC using RuboCop version 1.24.1.
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
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: Include.
12
+ # Include: **/*.gemspec
13
+ Gemspec/RequireMFA:
14
+ Exclude:
15
+ - 'grape-swagger.gemspec'
16
+
9
17
  # Offense count: 1
10
18
  # Configuration parameters: Include.
11
19
  # Include: **/*.gemspec
@@ -13,20 +21,18 @@ Gemspec/RequiredRubyVersion:
13
21
  Exclude:
14
22
  - 'grape-swagger.gemspec'
15
23
 
16
- # Offense count: 30
24
+ # Offense count: 31
25
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
17
26
  Metrics/AbcSize:
18
- Max: 59
19
-
20
- # Offense count: 10
21
- Metrics/CyclomaticComplexity:
22
- Max: 13
27
+ Max: 56
23
28
 
24
- # Offense count: 22
25
- # Configuration parameters: CountComments, ExcludedMethods.
29
+ # Offense count: 30
30
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
26
31
  Metrics/MethodLength:
27
- Max: 45
32
+ Max: 28
28
33
 
29
34
  # Offense count: 7
35
+ # Configuration parameters: IgnoredMethods.
30
36
  Metrics/PerceivedComplexity:
31
37
  Max: 16
32
38
 
@@ -35,6 +41,20 @@ Style/ClassVars:
35
41
  Exclude:
36
42
  - 'lib/grape-swagger/doc_methods.rb'
37
43
 
38
- # Offense count: 22
44
+ # Offense count: 23
45
+ # Configuration parameters: AllowedConstants.
39
46
  Style/Documentation:
40
47
  Enabled: false
48
+
49
+ # Offense count: 43
50
+ Style/OpenStructUse:
51
+ Exclude:
52
+ - 'spec/lib/endpoint_spec.rb'
53
+ - 'spec/lib/version_spec.rb'
54
+ - 'spec/support/mock_parser.rb'
55
+ - 'spec/support/model_parsers/mock_parser.rb'
56
+ - 'spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb'
57
+ - 'spec/swagger_v2/api_swagger_v2_mounted_spec.rb'
58
+ - 'spec/swagger_v2/api_swagger_v2_spec.rb'
59
+ - 'spec/swagger_v2/errors_spec.rb'
60
+ - 'spec/swagger_v2/reference_entity_spec.rb'
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### Next
1
+ ### next
2
2
 
3
3
  #### Features
4
4
 
@@ -9,6 +9,46 @@
9
9
  * Your contribution here.
10
10
 
11
11
 
12
+ ### 1.6.0 (March 19, 2023)
13
+
14
+ #### Features
15
+
16
+ * [#872](https://github.com/ruby-grape/grape-swagger/pull/872): Add `consumes` and `produces` options to `add_swagger_documentation` - [@spaceraccoon](https://github.com/spaceraccoon)
17
+ * [#868](https://github.com/ruby-grape/grape-swagger/pull/868): Add `default` endpoint option to specify default response - [@dhruvCW](https://github.com/dhruvCW)
18
+
19
+
20
+ ### 1.5.0 (July 28, 2022)
21
+
22
+ #### Features
23
+
24
+ * [#862](https://github.com/ruby-grape/grape-swagger/pull/862): Allow using nicknames for body definitions - [@magni-](https://github.com/magni-)
25
+
26
+ #### Fixes
27
+
28
+ * [#860](https://github.com/ruby-grape/grape-swagger/pull/860) chore: Included githubactions in the dependabot config [@naveensrinivasan](https://github.com/naveensrinivasan)
29
+ * [#843](https://github.com/ruby-grape/grape-swagger/pull/843) Syntax errors in README.md examples [@remvee](https://github.com/remvee)
30
+ * [#844](https://github.com/ruby-grape/grape-swagger/pull/844) Fixes the regexp used for parsing routes [@senhalil](https://github.com/senhalil)
31
+ * [#847](https://github.com/ruby-grape/grape-swagger/pull/847) Parse route_param type for nested endpoints [@dmoss18](https://github.com/dmoss18)
32
+ * [#856](https://github.com/ruby-grape/grape-swagger/pull/856) Remove unused methods in GrapeSwagger::DocMethods::BuildModelDefinition [@takahashim](https://github.com/takahashim)
33
+ * [#858](https://github.com/ruby-grape/grape-swagger/pull/858): Set permissions for GitHub actions [@naveensrinivasan](https://github.com/naveensrinivasan)
34
+ * [#853](https://github.com/ruby-grape/grape-swagger/pull/853): Add webrick to support Ruby 3.x [@takahashim](https://github.com/takahashim)
35
+ * [#852](https://github.com/ruby-grape/grape-swagger/pull/852): Fix example to work [@takahashim](https://github.com/takahashim)
36
+ * [#846](https://github.com/ruby-grape/grape-swagger/pull/846): Refactor oapi fetch task [@Vachman](https://github.com/Vachman)
37
+ * [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of enum to be Array [@takahashim](https://github.com/takahashim)
38
+
39
+
40
+ ### 1.4.3 (January 5, 2022)
41
+
42
+ #### Fixes
43
+
44
+ * [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of `enum` to be `Array` - [@takahashim](https://github.com/takahashim)
45
+ * [#846](https://github.com/ruby-grape/grape-swagger/pull/846): Fixes oapi rake tasks, allows generating sepcs for different API versions.
46
+ * [#852](https://github.com/ruby-grape/grape-swagger/pull/852): Fix example to work without error - [@takahashim](https://github.com/takahashim)
47
+ * [#853](https://github.com/ruby-grape/grape-swagger/pull/853): Add webrick gem so that example works in Ruby 3.x - [@takahashim](https://github.com/takahashim)
48
+ * [#844](https://github.com/ruby-grape/grape-swagger/pull/844): Fixes the regexp used for parsing routes - [@senhalil](https://github.com/senhalil)
49
+ * [#862](https://github.com/ruby-grape/grape-swagger/pull/862): Allow using nicknames for body definitions - [@magni-](https://github.com/magni-)
50
+ * Your contribution here.
51
+
12
52
  ### 1.4.2 (October 22, 2021)
13
53
 
14
54
  #### Fixes
data/CONTRIBUTING.md CHANGED
@@ -115,7 +115,7 @@ git push origin my-feature-branch -f
115
115
 
116
116
  ## Check on Your Pull Request
117
117
 
118
- Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
118
+ Go back to your pull request after a few minutes and see whether it passed muster with GitHub Actions. Everything should look green, otherwise fix issues and amend your commit as described above.
119
119
 
120
120
  ## Be Patient
121
121
 
data/Gemfile CHANGED
@@ -2,18 +2,16 @@
2
2
 
3
3
  source 'http://rubygems.org'
4
4
 
5
- ruby RUBY_VERSION
6
-
7
5
  gemspec
8
6
 
9
- gem 'grape', case version = ENV['GRAPE_VERSION'] || '>= 1.5.0'
7
+ gem 'grape', case version = ENV.fetch('GRAPE_VERSION', '~> 1.7')
10
8
  when 'HEAD'
11
9
  { git: 'https://github.com/ruby-grape/grape' }
12
10
  else
13
11
  version
14
12
  end
15
13
 
16
- gem ENV['MODEL_PARSER'] if ENV.key?('MODEL_PARSER')
14
+ gem ENV.fetch('MODEL_PARSER', nil) if ENV.key?('MODEL_PARSER')
17
15
 
18
16
  group :development, :test do
19
17
  gem 'bundler'
@@ -21,13 +19,14 @@ group :development, :test do
21
19
  gem 'pry', platforms: [:mri]
22
20
  gem 'pry-byebug', platforms: [:mri]
23
21
 
24
- gem 'rack', '~> 2.2'
22
+ gem 'rack', '~> 3.0'
25
23
  gem 'rack-cors'
26
24
  gem 'rack-test'
27
25
  gem 'rake'
28
26
  gem 'rdoc'
29
27
  gem 'rspec', '~> 3.9'
30
28
  gem 'rubocop', '~> 1.0', require: false
29
+ gem 'webrick'
31
30
  end
32
31
 
33
32
  group :test do
@@ -35,7 +34,9 @@ group :test do
35
34
 
36
35
  gem 'ruby-grape-danger', '~> 0.2.0', require: false
37
36
  gem 'simplecov', require: false
37
+ end
38
38
 
39
+ group :test, :development do
39
40
  unless ENV['MODEL_PARSER'] == 'grape-swagger-entity'
40
41
  gem 'grape-swagger-entity', git: 'https://github.com/ruby-grape/grape-swagger-entity'
41
42
  end
data/README.md CHANGED
@@ -206,6 +206,8 @@ end
206
206
  * [array_use_braces](#array_use_braces)
207
207
  * [api_documentation](#api_documentation)
208
208
  * [specific_api_documentation](#specific_api_documentation)
209
+ * [consumes](#consumes)
210
+ * [produces](#produces)
209
211
 
210
212
  You can pass a hash with optional configuration settings to ```add_swagger_documentation```.
211
213
  The examples show the default value.
@@ -432,6 +434,24 @@ add_swagger_documentation \
432
434
  specific_api_documentation: { desc: 'Reticulated splines API swagger-compatible endpoint documentation.' }
433
435
  ```
434
436
 
437
+ #### consumes
438
+
439
+ Customize the Swagger API default global `consumes` field value.
440
+
441
+ ```ruby
442
+ add_swagger_documentation \
443
+ consumes: ['application/json', 'application/x-www-form-urlencoded']
444
+ ```
445
+
446
+ #### produces
447
+
448
+ Customize the Swagger API default global `produces` field value.
449
+
450
+ ```ruby
451
+ add_swagger_documentation \
452
+ produces: ['text/plain']
453
+ ```
454
+
435
455
  ## Routes Configuration <a name="routes"></a>
436
456
 
437
457
  * [Swagger Header Parameters](#headers)
@@ -817,7 +837,7 @@ The example parameter will populate the Swagger UI with the example value, and c
817
837
  ```ruby
818
838
  params do
819
839
  requires :id, type: Integer, documentation: { example: 123 }
820
- optional :name, type String, documentation: { example: 'Buddy Guy' }
840
+ optional :name, type: String, documentation: { example: 'Buddy Guy' }
821
841
  end
822
842
  ```
823
843
 
@@ -843,7 +863,7 @@ namespace 'store/order', desc: 'Order operations within a store', swagger: { nes
843
863
  get :order_id do
844
864
  ...
845
865
  end
846
- namespace 'actions', desc: 'Order actions' do, nested: false
866
+ namespace 'actions', desc: 'Order actions', nested: false do
847
867
  get 'evaluate' do
848
868
  ...
849
869
  end
@@ -1022,6 +1042,50 @@ end
1022
1042
  }
1023
1043
  ```
1024
1044
 
1045
+ #### Default response <a name="default-response"></a>
1046
+
1047
+ By setting the `default` option you can also define a default response that is the result returned for all unspecified status codes.
1048
+ The definition supports the same syntax as `success` or `failure`.
1049
+
1050
+ In the following cases, the schema ref would be taken from route.
1051
+
1052
+ ```ruby
1053
+ desc 'thing', default: { message: 'the default response' }
1054
+ get '/thing' do
1055
+ # ...
1056
+ end
1057
+ ```
1058
+ The generated swagger section will be something like
1059
+
1060
+ ```json
1061
+ "responses": {
1062
+ "default": {
1063
+ "description": "the default response"
1064
+ }
1065
+ },
1066
+ ```
1067
+ Just like with `success` or `failure` you can also provide a `model` parameter.
1068
+
1069
+ ```ruby
1070
+ desc 'Get a list of stuff',
1071
+ default: { model: Entities::UseResponse, message: 'the default response' }
1072
+ get do
1073
+ # your code comes here
1074
+ end
1075
+ ```
1076
+ The generated swagger document will then correctly reference the model schema.
1077
+
1078
+ ```json
1079
+ "responses": {
1080
+ "default": {
1081
+ "description": "the default response",
1082
+ "schema": {
1083
+ "$ref": "#/definitions/UseResponse"
1084
+ }
1085
+ }
1086
+ },
1087
+ ```
1088
+
1025
1089
 
1026
1090
  #### Extensions <a name="extensions"></a>
1027
1091
 
@@ -1265,7 +1329,7 @@ end
1265
1329
 
1266
1330
  The result will look like following:
1267
1331
 
1268
- ```
1332
+ ```json
1269
1333
  "responses": {
1270
1334
  "200": {
1271
1335
  "description": "Get a kitten",
@@ -1292,7 +1356,7 @@ end
1292
1356
 
1293
1357
  The result will look like following:
1294
1358
 
1295
- ```
1359
+ ```json
1296
1360
  "responses": {
1297
1361
  "200": {
1298
1362
  "description": "Get kittens",
@@ -1319,7 +1383,7 @@ get '/things' do
1319
1383
  end
1320
1384
  ```
1321
1385
  The result will look like following:
1322
- ```
1386
+ ```json
1323
1387
  "responses": {
1324
1388
  "200": {
1325
1389
  "description": "Multiple response",
@@ -1351,7 +1415,7 @@ get '/things' do
1351
1415
  end
1352
1416
  ```
1353
1417
  The result will look like following:
1354
- ```
1418
+ ```json
1355
1419
  "responses": {
1356
1420
  "200": {
1357
1421
  "description": "Multiple response with array",
@@ -1525,7 +1589,7 @@ end
1525
1589
  ```
1526
1590
 
1527
1591
  Should generate this definitions:
1528
- ```JSON
1592
+ ```json
1529
1593
  {
1530
1594
  "definitions": {
1531
1595
  "Pet": {
@@ -1718,9 +1782,10 @@ GrapeSwagger::Rake::OapiTasks.new('::Api::Base')
1718
1782
  ```
1719
1783
  rake oapi:fetch
1720
1784
  params:
1721
- - store={ true | file_name } – save as JSON (optional)
1785
+ - store={ true | file_name.json } – save as JSON (optional)
1722
1786
  - resource=resource_name – get only for this one (optional)
1723
1787
  ```
1788
+ For mutliversion API it creates several files with following naming: file_name_`API_VERSION`.json
1724
1789
 
1725
1790
  #### OpenApi/Swagger Validation
1726
1791
 
data/UPGRADING.md CHANGED
@@ -1,8 +1,19 @@
1
1
  ## Upgrading Grape-swagger
2
2
 
3
+ ### Upgrading to >= 1.5.0
4
+
5
+ - The names generated for body parameter definitions and their references has changed. It'll now include the HTTP action as well as any path parameters.
6
+ - E.g, given a `PUT /things/:id` endpoint, `paths.things/{id}.put.parameters` in the generated Swaggerfile will contain the following:
7
+ - With `grape-swagger < 1.5.0`: `{ "name": "Things", ..., "schema": { "$ref": "#/definitions/putThings" } }`
8
+ - With `grape-swagger >= 1.5.0`: `{ "name": "putThingsId", ..., "schema": { "$ref": "#/definitions/putThingsId" } }`
9
+ - If you use the `nickname` option for an endpoint, that nickname will be used for both the parameter name and its definition reference.
10
+ - E.g., if the endpoint above were nicknamed `put-thing`, the generated Swaggerfile will contain `{ "name": "put-thing", ..., "schema": { "$ref": "#/definitions/put-thing" } }`
11
+
12
+
3
13
  ### Upgrading to >= 1.4.2
4
14
 
5
15
  - `additionalProperties` has been deprecated and will be removed in a future version of `grape-swagger`. It has been replaced with `additional_properties`.
16
+ - The value of the `enum` attribute is now always an Array. If it has only one value, it will be a one-element Array.
6
17
 
7
18
  ### Upgrading to >= 1.4.0
8
19
 
data/example/config.ru CHANGED
@@ -1,4 +1,5 @@
1
- require 'rack/cors'
1
+ Bundler.require ENV['RACK_ENV']
2
+
2
3
  use Rack::Cors do
3
4
  allow do
4
5
  origins '*'
@@ -12,7 +13,6 @@ require './api/endpoints'
12
13
  require './api/entities'
13
14
 
14
15
  class Base < Grape::API
15
- require 'grape-entity'
16
16
  require '../lib/grape-swagger'
17
17
  format :json
18
18
 
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
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.5'
16
+ s.metadata['rubygems_mfa_required'] = 'true'
17
+
18
+ s.required_ruby_version = '>= 2.7'
17
19
  s.add_runtime_dependency 'grape', '~> 1.3'
18
20
 
19
21
  s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
21
22
  s.require_paths = ['lib']
22
23
  end
@@ -4,14 +4,9 @@ module GrapeSwagger
4
4
  module DocMethods
5
5
  class BuildModelDefinition
6
6
  class << self
7
- def build(model, properties, required, other_def_properties = {})
7
+ def build(_model, properties, required, other_def_properties = {})
8
8
  definition = { type: 'object', properties: properties }.merge(other_def_properties)
9
9
 
10
- if required.nil?
11
- required_attrs = required_attributes(model)
12
- definition[:required] = required_attrs unless required_attrs.blank?
13
- end
14
-
15
10
  definition[:required] = required if required.is_a?(Array) && required.any?
16
11
 
17
12
  definition
@@ -67,20 +62,6 @@ module GrapeSwagger
67
62
  end
68
63
  end
69
64
  end
70
-
71
- private
72
-
73
- def required_attributes(model)
74
- parse_entity(model) || parse_representable(model)
75
- end
76
-
77
- def parse_entity(model)
78
- return unless model.respond_to?(:documentation)
79
- end
80
-
81
- def parse_representable(model)
82
- return unless model.respond_to?(:map)
83
- end
84
65
  end
85
66
  end
86
67
  end
@@ -38,15 +38,15 @@ module GrapeSwagger
38
38
  end
39
39
 
40
40
  def parent_definition_of_params(params, path, route)
41
- definition_name = OperationId.manipulate(parse_model(path))
42
- referenced_definition = build_definition(definition_name, params, route.request_method.downcase)
43
- definition = @definitions[referenced_definition]
41
+ definition_name = OperationId.build(route, path)
42
+ build_definition(definition_name, params)
43
+ definition = @definitions[definition_name]
44
44
 
45
45
  move_params_to_new(definition, params)
46
46
 
47
47
  definition[:description] = route.description if route.try(:description)
48
48
 
49
- build_body_parameter(referenced_definition, definition_name, route.options)
49
+ build_body_parameter(definition_name, route.options)
50
50
  end
51
51
 
52
52
  def move_params_to_new(definition, params)
@@ -142,17 +142,16 @@ module GrapeSwagger
142
142
  definition[:required].push(*value)
143
143
  end
144
144
 
145
- def build_body_parameter(reference, name, options)
145
+ def build_body_parameter(name, options)
146
146
  {}.tap do |x|
147
147
  x[:name] = options[:body_name] || name
148
148
  x[:in] = 'body'
149
149
  x[:required] = true
150
- x[:schema] = { '$ref' => "#/definitions/#{reference}" }
150
+ x[:schema] = { '$ref' => "#/definitions/#{name}" }
151
151
  end
152
152
  end
153
153
 
154
- def build_definition(name, params, verb = nil)
155
- name = "#{verb}#{name}" if verb
154
+ def build_definition(name, params)
156
155
  @definitions[name] = should_expose_as_array?(params) ? array_type : object_type
157
156
 
158
157
  name
@@ -163,8 +163,10 @@ module GrapeSwagger
163
163
  parse_enum_or_range_values(values.call) if values.parameters.empty?
164
164
  when Range
165
165
  parse_range_values(values) if values.first.is_a?(Integer)
166
+ when Array
167
+ { enum: values }
166
168
  else
167
- { enum: values } if values
169
+ { enum: [values] } if values
168
170
  end
169
171
  end
170
172