grape-swagger 1.3.0 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) 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 +10 -2
  8. data/.rubocop_todo.yml +1 -1
  9. data/CHANGELOG.md +39 -0
  10. data/Gemfile +3 -3
  11. data/README.md +113 -2
  12. data/UPGRADING.md +8 -0
  13. data/grape-swagger.gemspec +3 -3
  14. data/lib/grape-swagger/doc_methods/format_data.rb +3 -1
  15. data/lib/grape-swagger/doc_methods/move_params.rb +6 -7
  16. data/lib/grape-swagger/doc_methods/parse_params.rb +37 -5
  17. data/lib/grape-swagger/endpoint.rb +45 -6
  18. data/lib/grape-swagger/errors.rb +2 -0
  19. data/lib/grape-swagger/model_parsers.rb +2 -2
  20. data/lib/grape-swagger/rake/oapi_tasks.rb +1 -1
  21. data/lib/grape-swagger/version.rb +1 -1
  22. data/lib/grape-swagger.rb +5 -2
  23. data/spec/issues/537_enum_values_spec.rb +1 -0
  24. data/spec/issues/776_multiple_presents_spec.rb +59 -0
  25. data/spec/issues/809_utf8_routes_spec.rb +55 -0
  26. data/spec/issues/832_array_hash_float_decimal_spec.rb +111 -0
  27. data/spec/lib/format_data_spec.rb +24 -0
  28. data/spec/spec_helper.rb +1 -1
  29. data/spec/support/empty_model_parser.rb +2 -0
  30. data/spec/support/model_parsers/mock_parser.rb +16 -0
  31. data/spec/support/namespace_tags.rb +3 -0
  32. data/spec/support/the_paths_definitions.rb +4 -4
  33. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +83 -0
  34. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +1 -0
  35. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +73 -1
  36. data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +4 -2
  37. data/spec/swagger_v2/api_swagger_v2_spec.rb +1 -0
  38. data/spec/swagger_v2/boolean_params_spec.rb +4 -1
  39. data/spec/swagger_v2/float_api_spec.rb +1 -0
  40. data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +1 -0
  41. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +1 -0
  42. data/spec/swagger_v2/param_multi_type_spec.rb +2 -0
  43. data/spec/swagger_v2/param_type_spec.rb +3 -0
  44. data/spec/swagger_v2/param_values_spec.rb +6 -0
  45. data/spec/swagger_v2/{params_array_collection_fromat_spec.rb → params_array_collection_format_spec.rb} +0 -0
  46. data/spec/swagger_v2/params_example_spec.rb +40 -0
  47. data/spec/swagger_v2/simple_mounted_api_spec.rb +3 -0
  48. metadata +21 -7
  49. data/.travis.yml +0 -40
@@ -16,6 +16,7 @@ describe 'Params Multi Types' do
16
16
  requires :another_input, type: [String, Integer]
17
17
  end
18
18
  post :action do
19
+ { message: 'hi' }
19
20
  end
20
21
 
21
22
  add_swagger_documentation
@@ -61,6 +62,7 @@ describe 'Params Multi Types' do
61
62
  requires :another_input, type: [String, Integer]
62
63
  end
63
64
  post :action do
65
+ { message: 'hi' }
64
66
  end
65
67
 
66
68
  add_swagger_documentation
@@ -11,12 +11,14 @@ describe 'Params Types' do
11
11
  requires :input, type: String
12
12
  end
13
13
  post :action do
14
+ { message: 'hi' }
14
15
  end
15
16
 
16
17
  params do
17
18
  requires :input, type: String, default: '14', documentation: { type: 'email', default: '42' }
18
19
  end
19
20
  post :action_with_doc do
21
+ { message: 'hi' }
20
22
  end
21
23
 
22
24
  add_swagger_documentation
@@ -49,6 +51,7 @@ describe 'Params Types' do
49
51
  requires :input, type: String
50
52
  end
51
53
  post :action do
54
+ { message: 'hi' }
52
55
  end
53
56
 
54
57
  add_swagger_documentation
@@ -12,24 +12,28 @@ describe 'Convert values to enum or Range' do
12
12
  requires :letter, type: String, values: %w[a b c]
13
13
  end
14
14
  post :plain_array do
15
+ { message: 'hi' }
15
16
  end
16
17
 
17
18
  params do
18
19
  requires :letter, type: String, values: proc { %w[d e f] }
19
20
  end
20
21
  post :array_in_proc do
22
+ { message: 'hi' }
21
23
  end
22
24
 
23
25
  params do
24
26
  requires :letter, type: String, values: 'a'..'z'
25
27
  end
26
28
  post :range_letter do
29
+ { message: 'hi' }
27
30
  end
28
31
 
29
32
  params do
30
33
  requires :integer, type: Integer, values: -5..5
31
34
  end
32
35
  post :range_integer do
36
+ { message: 'hi' }
33
37
  end
34
38
 
35
39
  add_swagger_documentation
@@ -107,12 +111,14 @@ describe 'Convert values to enum for float range and not arrays inside a proc',
107
111
  requires :letter, type: String, values: proc { 'string' }
108
112
  end
109
113
  post :non_array_in_proc do
114
+ { message: 'hi' }
110
115
  end
111
116
 
112
117
  params do
113
118
  requires :float, type: Float, values: -5.0..5.0
114
119
  end
115
120
  post :range_float do
121
+ { message: 'hi' }
116
122
  end
117
123
 
118
124
  add_swagger_documentation
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Param example' do
6
+ def app
7
+ Class.new(Grape::API) do
8
+ format :json
9
+
10
+ params do
11
+ requires :id, type: Integer, documentation: { example: 123 }
12
+ optional :name, type: String, documentation: { example: 'Person' }
13
+ optional :obj, type: 'Object', documentation: { example: { 'foo' => 'bar' } }
14
+ end
15
+
16
+ get '/endpoint_with_examples' do
17
+ { 'declared_params' => declared(params) }
18
+ end
19
+
20
+ add_swagger_documentation
21
+ end
22
+ end
23
+
24
+ describe 'documentation with parameter examples' do
25
+ subject do
26
+ get '/swagger_doc/endpoint_with_examples'
27
+ JSON.parse(last_response.body)
28
+ end
29
+
30
+ specify do
31
+ expect(subject['paths']['/endpoint_with_examples']['get']['parameters']).to eql(
32
+ [
33
+ { 'in' => 'query', 'name' => 'id', 'type' => 'integer', 'example' => 123, 'format' => 'int32', 'required' => true },
34
+ { 'in' => 'query', 'name' => 'name', 'type' => 'string', 'example' => 'Person', 'required' => false },
35
+ { 'in' => 'query', 'name' => 'obj', 'type' => 'Object', 'example' => { 'foo' => 'bar' }, 'required' => false }
36
+ ]
37
+ )
38
+ end
39
+ end
40
+ end
@@ -4,11 +4,14 @@ require 'spec_helper'
4
4
 
5
5
  describe 'a simple mounted api' do
6
6
  before :all do
7
+ # rubocop:disable Lint/EmptyClass
7
8
  class CustomType; end
9
+ # rubocop:enable Lint/EmptyClass
8
10
 
9
11
  class SimpleMountedApi < Grape::API
10
12
  desc 'Document root'
11
13
  get do
14
+ { message: 'hi' }
12
15
  end
13
16
 
14
17
  desc 'This gets something.',
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
+ - LeFnord
7
8
  - Tim Vandecasteele
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-09-04 00:00:00.000000000 Z
12
+ date: 2021-10-22 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: grape
@@ -26,18 +27,21 @@ dependencies:
26
27
  version: '1.3'
27
28
  description:
28
29
  email:
30
+ - pscholz.le@gmail.com
29
31
  - tim.vandecasteele@gmail.com
30
32
  executables: []
31
33
  extensions: []
32
34
  extra_rdoc_files: []
33
35
  files:
34
36
  - ".coveralls.yml"
37
+ - ".github/dependabot.yml"
38
+ - ".github/workflows/rubocop.yml"
39
+ - ".github/workflows/ruby.yml"
35
40
  - ".gitignore"
36
41
  - ".rspec"
37
42
  - ".rubocop.yml"
38
43
  - ".rubocop_todo.yml"
39
44
  - ".ruby-gemset"
40
- - ".travis.yml"
41
45
  - CHANGELOG.md
42
46
  - CONTRIBUTING.md
43
47
  - Dangerfile
@@ -95,7 +99,10 @@ files:
95
99
  - spec/issues/650_params_array_spec.rb
96
100
  - spec/issues/680_keep_204_error_schemas_spec.rb
97
101
  - spec/issues/751_deeply_nested_objects_spec.rb
102
+ - spec/issues/776_multiple_presents_spec.rb
98
103
  - spec/issues/784_extensions_on_params_spec.rb
104
+ - spec/issues/809_utf8_routes_spec.rb
105
+ - spec/issues/832_array_hash_float_decimal_spec.rb
99
106
  - spec/lib/data_type_spec.rb
100
107
  - spec/lib/endpoint/params_parser_spec.rb
101
108
  - spec/lib/endpoint_spec.rb
@@ -121,6 +128,7 @@ files:
121
128
  - spec/support/namespace_tags.rb
122
129
  - spec/support/the_paths_definitions.rb
123
130
  - spec/swagger_v2/api_documentation_spec.rb
131
+ - spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb
124
132
  - spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb
125
133
  - spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb
126
134
  - spec/swagger_v2/api_swagger_v2_detail_spec.rb
@@ -168,8 +176,9 @@ files:
168
176
  - spec/swagger_v2/param_multi_type_spec.rb
169
177
  - spec/swagger_v2/param_type_spec.rb
170
178
  - spec/swagger_v2/param_values_spec.rb
171
- - spec/swagger_v2/params_array_collection_fromat_spec.rb
179
+ - spec/swagger_v2/params_array_collection_format_spec.rb
172
180
  - spec/swagger_v2/params_array_spec.rb
181
+ - spec/swagger_v2/params_example_spec.rb
173
182
  - spec/swagger_v2/params_hash_spec.rb
174
183
  - spec/swagger_v2/params_nested_spec.rb
175
184
  - spec/swagger_v2/parent_less_namespace_spec.rb
@@ -189,14 +198,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
198
  requirements:
190
199
  - - ">="
191
200
  - !ruby/object:Gem::Version
192
- version: '2.4'
201
+ version: '2.5'
193
202
  required_rubygems_version: !ruby/object:Gem::Requirement
194
203
  requirements:
195
204
  - - ">="
196
205
  - !ruby/object:Gem::Version
197
206
  version: '0'
198
207
  requirements: []
199
- rubygems_version: 3.1.4
208
+ rubygems_version: 3.2.22
200
209
  signing_key:
201
210
  specification_version: 4
202
211
  summary: Add auto generated documentation to your Grape API that can be displayed
@@ -220,7 +229,10 @@ test_files:
220
229
  - spec/issues/650_params_array_spec.rb
221
230
  - spec/issues/680_keep_204_error_schemas_spec.rb
222
231
  - spec/issues/751_deeply_nested_objects_spec.rb
232
+ - spec/issues/776_multiple_presents_spec.rb
223
233
  - spec/issues/784_extensions_on_params_spec.rb
234
+ - spec/issues/809_utf8_routes_spec.rb
235
+ - spec/issues/832_array_hash_float_decimal_spec.rb
224
236
  - spec/lib/data_type_spec.rb
225
237
  - spec/lib/endpoint/params_parser_spec.rb
226
238
  - spec/lib/endpoint_spec.rb
@@ -246,6 +258,7 @@ test_files:
246
258
  - spec/support/namespace_tags.rb
247
259
  - spec/support/the_paths_definitions.rb
248
260
  - spec/swagger_v2/api_documentation_spec.rb
261
+ - spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb
249
262
  - spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb
250
263
  - spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb
251
264
  - spec/swagger_v2/api_swagger_v2_detail_spec.rb
@@ -293,8 +306,9 @@ test_files:
293
306
  - spec/swagger_v2/param_multi_type_spec.rb
294
307
  - spec/swagger_v2/param_type_spec.rb
295
308
  - spec/swagger_v2/param_values_spec.rb
296
- - spec/swagger_v2/params_array_collection_fromat_spec.rb
309
+ - spec/swagger_v2/params_array_collection_format_spec.rb
297
310
  - spec/swagger_v2/params_array_spec.rb
311
+ - spec/swagger_v2/params_example_spec.rb
298
312
  - spec/swagger_v2/params_hash_spec.rb
299
313
  - spec/swagger_v2/params_nested_spec.rb
300
314
  - spec/swagger_v2/parent_less_namespace_spec.rb
data/.travis.yml DELETED
@@ -1,40 +0,0 @@
1
- language: ruby
2
-
3
- os: linux
4
-
5
- before_install:
6
- - gem install bundler
7
-
8
- after_success:
9
- - bundle exec danger
10
-
11
- rvm:
12
- - 2.5.8
13
- - 2.6.6
14
- - 2.7.1
15
- env:
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
21
-
22
- jobs:
23
- fast_finish: true
24
-
25
- include:
26
- - rvm: 2.4.10
27
- env:
28
- - rvm: ruby-head
29
- env:
30
- - rvm: jruby-head
31
- env:
32
- - rvm: truffleruby-head
33
- env:
34
- script: bundle exec rake spec
35
-
36
- allow_failures:
37
- - rvm: 2.4.10
38
- - rvm: ruby-head
39
- - rvm: jruby-head
40
- - rvm: truffleruby-head