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
@@ -22,6 +22,20 @@ describe 'referenceEntity' do
22
22
  expose :title, documentation: { type: 'string', desc: 'Title of the kind.' }
23
23
  expose :something, documentation: { type: Something, desc: 'Something interesting.' }
24
24
  end
25
+
26
+ class Base < Grape::Entity
27
+ def self.entity_name
28
+ parts = to_s.split('::')
29
+
30
+ "MyAPI::#{parts.last}"
31
+ end
32
+
33
+ expose :title, documentation: { type: 'string', desc: 'Title of the parent.' }
34
+ end
35
+
36
+ class Child < Base
37
+ expose :child, documentation: { type: 'string', desc: 'Child property.' }
38
+ end
25
39
  end
26
40
 
27
41
  class ResponseModelApi < Grape::API
@@ -40,6 +54,16 @@ describe 'referenceEntity' do
40
54
  present kind, with: Entities::Kind
41
55
  end
42
56
 
57
+ desc 'This returns a child entity',
58
+ entity: Entities::Child,
59
+ http_codes: [
60
+ { code: 200, message: 'OK', model: Entities::Child }
61
+ ]
62
+ get '/child' do
63
+ child = OpenStruct.new text: 'child'
64
+ present child, with: Entities::Child
65
+ end
66
+
43
67
  add_swagger_documentation # models: [MyAPI::Entities::Something, MyAPI::Entities::Kind]
44
68
  end
45
69
  end
@@ -49,36 +73,57 @@ describe 'referenceEntity' do
49
73
  MyAPI::ResponseModelApi
50
74
  end
51
75
 
52
- subject do
53
- get '/swagger_doc/kind'
54
- JSON.parse(last_response.body)
76
+ describe 'kind' do
77
+ subject do
78
+ get '/swagger_doc/kind'
79
+ JSON.parse(last_response.body)
80
+ end
81
+
82
+ it 'should document specified models' do
83
+ expect(subject['paths']['/kind']['get']['parameters']).to eq [{
84
+ 'in' => 'query',
85
+ 'name' => 'something',
86
+ 'description' => 'Something interesting.',
87
+ 'type' => 'SomethingCustom',
88
+ 'required' => false
89
+ }]
90
+
91
+ expect(subject['definitions'].keys).to include 'SomethingCustom'
92
+ expect(subject['definitions']['SomethingCustom']).to eq(
93
+ 'type' => 'object', 'properties' => { 'text' => { 'type' => 'string', 'description' => 'Content of something.' } }
94
+ )
95
+
96
+ expect(subject['definitions'].keys).to include 'KindCustom'
97
+ expect(subject['definitions']['KindCustom']).to eq(
98
+ 'type' => 'object',
99
+ 'properties' => {
100
+ 'title' => { 'type' => 'string', 'description' => 'Title of the kind.' },
101
+ 'something' => {
102
+ '$ref' => '#/definitions/SomethingCustom',
103
+ 'description' => 'Something interesting.'
104
+ }
105
+ },
106
+ 'description' => 'KindCustom model'
107
+ )
108
+ end
55
109
  end
56
110
 
57
- it 'should document specified models' do
58
- expect(subject['paths']['/kind']['get']['parameters']).to eq [{
59
- 'in' => 'query',
60
- 'name' => 'something',
61
- 'description' => 'Something interesting.',
62
- 'type' => 'SomethingCustom',
63
- 'required' => false
64
- }]
65
-
66
- expect(subject['definitions'].keys).to include 'SomethingCustom'
67
- expect(subject['definitions']['SomethingCustom']).to eq(
68
- 'type' => 'object', 'properties' => { 'text' => { 'type' => 'string', 'description' => 'Content of something.' } }
69
- )
70
-
71
- expect(subject['definitions'].keys).to include 'KindCustom'
72
- expect(subject['definitions']['KindCustom']).to eq(
73
- 'type' => 'object',
74
- 'properties' => {
75
- 'title' => { 'type' => 'string', 'description' => 'Title of the kind.' },
76
- 'something' => {
77
- '$ref' => '#/definitions/SomethingCustom',
78
- 'description' => 'Something interesting.'
79
- }
80
- },
81
- 'description' => 'This returns kind and something or an error'
82
- )
111
+ describe 'child' do
112
+ subject do
113
+ get '/swagger_doc/child'
114
+ JSON.parse(last_response.body)
115
+ end
116
+
117
+ it 'should document specified models' do
118
+ expect(subject['definitions'].keys).to include 'MyAPI::Child'
119
+ expect(subject['definitions']['MyAPI::Child']).to eq(
120
+ 'type' => 'object',
121
+ 'properties' => {
122
+ 'title' => { 'type' => 'string', 'description' => 'Title of the parent.' },
123
+ 'child' => { 'type' => 'string', 'description' => 'Child property.' }
124
+ },
125
+ 'description' => 'MyAPI::Child model'
126
+ )
127
+ end
83
128
  end
84
129
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe 'security requirement on endpoint method' do
6
6
  def app
7
7
  Class.new(Grape::API) do
8
- desc 'Endpoint with security requirement', security: [oauth_pets: ['read:pets', 'write:pets']]
8
+ desc 'Endpoint with security requirement', security: [{ oauth_pets: ['read:pets', 'write:pets'] }]
9
9
  get '/with_security' do
10
10
  { foo: 'bar' }
11
11
  end
@@ -37,7 +37,7 @@ describe 'security requirement on endpoint method' do
37
37
  end
38
38
 
39
39
  it 'defines the security requirement on the endpoint method' do
40
- expect(subject['paths']['/with_security']['get']['security']).to eql ['oauth_pets' => ['read:pets', 'write:pets']]
40
+ expect(subject['paths']['/with_security']['get']['security']).to eql [{ 'oauth_pets' => ['read:pets', 'write:pets'] }]
41
41
  end
42
42
 
43
43
  it 'defines an empty security requirement on the endpoint method' do
@@ -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.1.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
+ - LeFnord
7
8
  - Tim Vandecasteele
8
- autorequire:
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-04-20 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
@@ -16,28 +17,31 @@ dependencies:
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: 1.3.0
20
+ version: '1.3'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: 1.3.0
27
- description:
27
+ version: '1.3'
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
@@ -140,6 +148,7 @@ files:
140
148
  - spec/swagger_v2/api_swagger_v2_response_spec.rb
141
149
  - spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
142
150
  - spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
151
+ - spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb
143
152
  - spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb
144
153
  - spec/swagger_v2/api_swagger_v2_spec.rb
145
154
  - spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
@@ -156,6 +165,7 @@ files:
156
165
  - spec/swagger_v2/guarded_endpoint_spec.rb
157
166
  - spec/swagger_v2/hide_api_spec.rb
158
167
  - spec/swagger_v2/host_spec.rb
168
+ - spec/swagger_v2/inheritance_and_discriminator_spec.rb
159
169
  - spec/swagger_v2/mount_override_api_spec.rb
160
170
  - spec/swagger_v2/mounted_target_class_spec.rb
161
171
  - spec/swagger_v2/namespace_tags_prefix_spec.rb
@@ -166,8 +176,9 @@ files:
166
176
  - spec/swagger_v2/param_multi_type_spec.rb
167
177
  - spec/swagger_v2/param_type_spec.rb
168
178
  - spec/swagger_v2/param_values_spec.rb
169
- - spec/swagger_v2/params_array_collection_fromat_spec.rb
179
+ - spec/swagger_v2/params_array_collection_format_spec.rb
170
180
  - spec/swagger_v2/params_array_spec.rb
181
+ - spec/swagger_v2/params_example_spec.rb
171
182
  - spec/swagger_v2/params_hash_spec.rb
172
183
  - spec/swagger_v2/params_nested_spec.rb
173
184
  - spec/swagger_v2/parent_less_namespace_spec.rb
@@ -179,7 +190,7 @@ homepage: https://github.com/ruby-grape/grape-swagger
179
190
  licenses:
180
191
  - MIT
181
192
  metadata: {}
182
- post_install_message:
193
+ post_install_message:
183
194
  rdoc_options: []
184
195
  require_paths:
185
196
  - lib
@@ -187,15 +198,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
198
  requirements:
188
199
  - - ">="
189
200
  - !ruby/object:Gem::Version
190
- version: '2.4'
201
+ version: '2.5'
191
202
  required_rubygems_version: !ruby/object:Gem::Requirement
192
203
  requirements:
193
204
  - - ">="
194
205
  - !ruby/object:Gem::Version
195
206
  version: '0'
196
207
  requirements: []
197
- rubygems_version: 3.1.2
198
- signing_key:
208
+ rubygems_version: 3.2.22
209
+ signing_key:
199
210
  specification_version: 4
200
211
  summary: Add auto generated documentation to your Grape API that can be displayed
201
212
  with Swagger.
@@ -218,7 +229,10 @@ test_files:
218
229
  - spec/issues/650_params_array_spec.rb
219
230
  - spec/issues/680_keep_204_error_schemas_spec.rb
220
231
  - spec/issues/751_deeply_nested_objects_spec.rb
232
+ - spec/issues/776_multiple_presents_spec.rb
221
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
222
236
  - spec/lib/data_type_spec.rb
223
237
  - spec/lib/endpoint/params_parser_spec.rb
224
238
  - spec/lib/endpoint_spec.rb
@@ -244,6 +258,7 @@ test_files:
244
258
  - spec/support/namespace_tags.rb
245
259
  - spec/support/the_paths_definitions.rb
246
260
  - spec/swagger_v2/api_documentation_spec.rb
261
+ - spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb
247
262
  - spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb
248
263
  - spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb
249
264
  - spec/swagger_v2/api_swagger_v2_detail_spec.rb
@@ -263,6 +278,7 @@ test_files:
263
278
  - spec/swagger_v2/api_swagger_v2_response_spec.rb
264
279
  - spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
265
280
  - spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
281
+ - spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb
266
282
  - spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb
267
283
  - spec/swagger_v2/api_swagger_v2_spec.rb
268
284
  - spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
@@ -279,6 +295,7 @@ test_files:
279
295
  - spec/swagger_v2/guarded_endpoint_spec.rb
280
296
  - spec/swagger_v2/hide_api_spec.rb
281
297
  - spec/swagger_v2/host_spec.rb
298
+ - spec/swagger_v2/inheritance_and_discriminator_spec.rb
282
299
  - spec/swagger_v2/mount_override_api_spec.rb
283
300
  - spec/swagger_v2/mounted_target_class_spec.rb
284
301
  - spec/swagger_v2/namespace_tags_prefix_spec.rb
@@ -289,8 +306,9 @@ test_files:
289
306
  - spec/swagger_v2/param_multi_type_spec.rb
290
307
  - spec/swagger_v2/param_type_spec.rb
291
308
  - spec/swagger_v2/param_values_spec.rb
292
- - spec/swagger_v2/params_array_collection_fromat_spec.rb
309
+ - spec/swagger_v2/params_array_collection_format_spec.rb
293
310
  - spec/swagger_v2/params_array_spec.rb
311
+ - spec/swagger_v2/params_example_spec.rb
294
312
  - spec/swagger_v2/params_hash_spec.rb
295
313
  - spec/swagger_v2/params_nested_spec.rb
296
314
  - spec/swagger_v2/parent_less_namespace_spec.rb
data/.travis.yml DELETED
@@ -1,35 +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.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
20
-
21
- jobs:
22
- fast_finish: true
23
-
24
- include:
25
- - rvm: 2.4.10
26
- env:
27
- - rvm: ruby-head
28
- env:
29
- - rvm: jruby-head
30
- env:
31
-
32
- allow_failures:
33
- - rvm: 2.4.10
34
- - rvm: ruby-head
35
- - rvm: jruby-head