grape-swagger 0.33.0 → 0.34.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -7
  3. data/.rubocop_todo.yml +0 -6
  4. data/.travis.yml +10 -11
  5. data/CHANGELOG.md +72 -6
  6. data/Gemfile +4 -5
  7. data/README.md +68 -4
  8. data/grape-swagger.gemspec +2 -1
  9. data/lib/grape-swagger/doc_methods/build_model_definition.rb +0 -17
  10. data/lib/grape-swagger/doc_methods/extensions.rb +6 -1
  11. data/lib/grape-swagger/doc_methods/format_data.rb +51 -0
  12. data/lib/grape-swagger/doc_methods/move_params.rb +22 -49
  13. data/lib/grape-swagger/doc_methods/parse_params.rb +6 -0
  14. data/lib/grape-swagger/doc_methods.rb +2 -0
  15. data/lib/grape-swagger/endpoint/params_parser.rb +10 -17
  16. data/lib/grape-swagger/endpoint.rb +32 -13
  17. data/lib/grape-swagger/version.rb +1 -1
  18. data/lib/grape-swagger.rb +1 -1
  19. data/spec/issues/751_deeply_nested_objects_spec.rb +190 -0
  20. data/spec/lib/endpoint/params_parser_spec.rb +44 -20
  21. data/spec/lib/endpoint_spec.rb +3 -3
  22. data/spec/lib/extensions_spec.rb +10 -0
  23. data/spec/lib/format_data_spec.rb +91 -0
  24. data/spec/lib/move_params_spec.rb +4 -266
  25. data/spec/lib/optional_object_spec.rb +0 -1
  26. data/spec/spec_helper.rb +1 -1
  27. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +3 -1
  28. data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +153 -0
  29. data/spec/swagger_v2/description_not_initialized_spec.rb +39 -0
  30. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +33 -0
  31. data/spec/swagger_v2/mounted_target_class_spec.rb +1 -1
  32. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +15 -1
  33. data/spec/swagger_v2/params_array_spec.rb +2 -2
  34. data/spec/swagger_v2/parent_less_namespace_spec.rb +32 -0
  35. data/spec/swagger_v2/{reference_entity.rb → reference_entity_spec.rb} +17 -10
  36. metadata +36 -9
  37. data/spec/swagger_v2/description_not_initialized.rb +0 -39
  38. data/spec/swagger_v2/parent_less_namespace.rb +0 -49
@@ -29,12 +29,25 @@ describe 'namespace tags check while using prefix and version' do
29
29
  end
30
30
  end
31
31
  end
32
+
33
+ class NestedPrefixApi < Grape::API
34
+ version :v1
35
+ prefix 'nested_prefix/api'
36
+
37
+ namespace :deep_namespace do
38
+ desc 'This gets something within a deeply nested resource'
39
+ get '/deep' do
40
+ { bla: 'something' }
41
+ end
42
+ end
43
+ end
32
44
  end
33
45
 
34
46
  class TagApi < Grape::API
35
47
  prefix :api
36
48
  mount TheApi::CascadingVersionApi
37
49
  mount TheApi::NamespaceApi
50
+ mount TheApi::NestedPrefixApi
38
51
  add_swagger_documentation
39
52
  end
40
53
  end
@@ -55,7 +68,8 @@ describe 'namespace tags check while using prefix and version' do
55
68
  { 'name' => 'hudson', 'description' => 'Operations about hudsons' },
56
69
  { 'name' => 'colorado', 'description' => 'Operations about colorados' },
57
70
  { 'name' => 'thames', 'description' => 'Operations about thames' },
58
- { 'name' => 'niles', 'description' => 'Operations about niles' }
71
+ { 'name' => 'niles', 'description' => 'Operations about niles' },
72
+ { 'name' => 'deep_namespace', 'description' => 'Operations about deep_namespaces' }
59
73
  ]
60
74
  )
61
75
 
@@ -123,10 +123,10 @@ describe 'Group Params as Array' do
123
123
  'type' => 'object',
124
124
  'properties' => {
125
125
  'array_of_string' => {
126
- 'type' => 'string', 'description' => 'nested array of strings'
126
+ 'items' => { 'type' => 'string' }, 'type' => 'array', 'description' => 'nested array of strings'
127
127
  },
128
128
  'array_of_integer' => {
129
- 'type' => 'integer', 'format' => 'int32', 'description' => 'nested array of integers'
129
+ 'items' => { 'type' => 'integer', 'format' => 'int32' }, 'type' => 'array', 'description' => 'nested array of integers'
130
130
  }
131
131
  },
132
132
  'required' => %w[array_of_string array_of_integer]
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'a parent less namespace' do
6
+ include_context 'namespace example'
7
+
8
+ before :all do
9
+ class ParentLessApi < Grape::API
10
+ prefix :api
11
+ mount TheApi::ParentLessNamespaceApi
12
+ add_swagger_documentation version: 'v1'
13
+ end
14
+ end
15
+
16
+ def app
17
+ ParentLessApi
18
+ end
19
+
20
+ describe 'retrieves swagger-documentation on /swagger_doc' do
21
+ let(:route_name) { ':animal/:breed/queues/:queue_id/reservations' }
22
+ subject do
23
+ get '/api/swagger_doc.json'
24
+ JSON.parse(last_response.body)
25
+ end
26
+
27
+ specify do
28
+ expect(subject['paths']['/api/{animal}/{breed}/queues/{queue_id}/reservations']['get']['operationId'])
29
+ .to eql('getApiAnimalBreedQueuesQueueIdReservations')
30
+ end
31
+ end
32
+ end
@@ -58,20 +58,27 @@ describe 'referenceEntity' do
58
58
  expect(subject['paths']['/kind']['get']['parameters']).to eq [{
59
59
  'in' => 'query',
60
60
  'name' => 'something',
61
- 'description' => 'something as parameter',
62
- 'type' => 'string',
63
- 'required' => false,
64
- 'allowMultiple' => false
61
+ 'description' => 'Something interesting.',
62
+ 'type' => 'SomethingCustom',
63
+ 'required' => false
65
64
  }]
66
65
 
67
- expect(subject['definitions'].keys).to include 'Something'
68
- expect(subject['definitions']['Something']).to eq(
69
- 'type' => 'object', 'properties' => { 'text' => { 'type' => 'string' } }
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.' } }
70
69
  )
71
70
 
72
- expect(subject['definitions'].keys).to include 'Kind'
73
- expect(subject['definitions']['Kind']).to eq(
74
- 'properties' => { 'something' => { '$ref' => '#/definitions/Something' } }
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'
75
82
  )
76
83
  end
77
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.0
4
+ version: 0.34.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Vandecasteele
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-21 00:00:00.000000000 Z
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.16.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 1.3.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,23 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.16.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rack
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 2.0.8
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.8
27
47
  description:
28
48
  email:
29
49
  - tim.vandecasteele@gmail.com
@@ -59,6 +79,7 @@ files:
59
79
  - lib/grape-swagger/doc_methods/build_model_definition.rb
60
80
  - lib/grape-swagger/doc_methods/data_type.rb
61
81
  - lib/grape-swagger/doc_methods/extensions.rb
82
+ - lib/grape-swagger/doc_methods/format_data.rb
62
83
  - lib/grape-swagger/doc_methods/headers.rb
63
84
  - lib/grape-swagger/doc_methods/move_params.rb
64
85
  - lib/grape-swagger/doc_methods/operation_id.rb
@@ -93,10 +114,12 @@ files:
93
114
  - spec/issues/605_root_route_documentation_spec.rb
94
115
  - spec/issues/650_params_array_spec.rb
95
116
  - spec/issues/680_keep_204_error_schemas_spec.rb
117
+ - spec/issues/751_deeply_nested_objects_spec.rb
96
118
  - spec/lib/data_type_spec.rb
97
119
  - spec/lib/endpoint/params_parser_spec.rb
98
120
  - spec/lib/endpoint_spec.rb
99
121
  - spec/lib/extensions_spec.rb
122
+ - spec/lib/format_data_spec.rb
100
123
  - spec/lib/model_parsers_spec.rb
101
124
  - spec/lib/move_params_spec.rb
102
125
  - spec/lib/oapi_tasks_spec.rb
@@ -136,13 +159,14 @@ files:
136
159
  - spec/swagger_v2/api_swagger_v2_response_spec.rb
137
160
  - spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
138
161
  - spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
162
+ - spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb
139
163
  - spec/swagger_v2/api_swagger_v2_spec.rb
140
164
  - spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
141
165
  - spec/swagger_v2/api_swagger_v2_type-format_spec.rb
142
166
  - spec/swagger_v2/boolean_params_spec.rb
143
167
  - spec/swagger_v2/default_api_spec.rb
144
168
  - spec/swagger_v2/deprecated_field_spec.rb
145
- - spec/swagger_v2/description_not_initialized.rb
169
+ - spec/swagger_v2/description_not_initialized_spec.rb
146
170
  - spec/swagger_v2/endpoint_versioned_path_spec.rb
147
171
  - spec/swagger_v2/errors_spec.rb
148
172
  - spec/swagger_v2/float_api_spec.rb
@@ -165,8 +189,8 @@ files:
165
189
  - spec/swagger_v2/params_array_spec.rb
166
190
  - spec/swagger_v2/params_hash_spec.rb
167
191
  - spec/swagger_v2/params_nested_spec.rb
168
- - spec/swagger_v2/parent_less_namespace.rb
169
- - spec/swagger_v2/reference_entity.rb
192
+ - spec/swagger_v2/parent_less_namespace_spec.rb
193
+ - spec/swagger_v2/reference_entity_spec.rb
170
194
  - spec/swagger_v2/security_requirement_spec.rb
171
195
  - spec/swagger_v2/simple_mounted_api_spec.rb
172
196
  - spec/version_spec.rb
@@ -189,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
213
  - !ruby/object:Gem::Version
190
214
  version: '0'
191
215
  requirements: []
192
- rubygems_version: 3.0.3
216
+ rubygems_version: 3.1.2
193
217
  signing_key:
194
218
  specification_version: 4
195
219
  summary: Add auto generated documentation to your Grape API that can be displayed
@@ -212,10 +236,12 @@ test_files:
212
236
  - spec/issues/605_root_route_documentation_spec.rb
213
237
  - spec/issues/650_params_array_spec.rb
214
238
  - spec/issues/680_keep_204_error_schemas_spec.rb
239
+ - spec/issues/751_deeply_nested_objects_spec.rb
215
240
  - spec/lib/data_type_spec.rb
216
241
  - spec/lib/endpoint/params_parser_spec.rb
217
242
  - spec/lib/endpoint_spec.rb
218
243
  - spec/lib/extensions_spec.rb
244
+ - spec/lib/format_data_spec.rb
219
245
  - spec/lib/model_parsers_spec.rb
220
246
  - spec/lib/move_params_spec.rb
221
247
  - spec/lib/oapi_tasks_spec.rb
@@ -255,13 +281,14 @@ test_files:
255
281
  - spec/swagger_v2/api_swagger_v2_response_spec.rb
256
282
  - spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
257
283
  - spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
284
+ - spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb
258
285
  - spec/swagger_v2/api_swagger_v2_spec.rb
259
286
  - spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
260
287
  - spec/swagger_v2/api_swagger_v2_type-format_spec.rb
261
288
  - spec/swagger_v2/boolean_params_spec.rb
262
289
  - spec/swagger_v2/default_api_spec.rb
263
290
  - spec/swagger_v2/deprecated_field_spec.rb
264
- - spec/swagger_v2/description_not_initialized.rb
291
+ - spec/swagger_v2/description_not_initialized_spec.rb
265
292
  - spec/swagger_v2/endpoint_versioned_path_spec.rb
266
293
  - spec/swagger_v2/errors_spec.rb
267
294
  - spec/swagger_v2/float_api_spec.rb
@@ -284,8 +311,8 @@ test_files:
284
311
  - spec/swagger_v2/params_array_spec.rb
285
312
  - spec/swagger_v2/params_hash_spec.rb
286
313
  - spec/swagger_v2/params_nested_spec.rb
287
- - spec/swagger_v2/parent_less_namespace.rb
288
- - spec/swagger_v2/reference_entity.rb
314
+ - spec/swagger_v2/parent_less_namespace_spec.rb
315
+ - spec/swagger_v2/reference_entity_spec.rb
289
316
  - spec/swagger_v2/security_requirement_spec.rb
290
317
  - spec/swagger_v2/simple_mounted_api_spec.rb
291
318
  - spec/version_spec.rb
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'details' do
6
- describe 'has no description, if details or description are nil' do
7
- before :all do
8
- module TheApi
9
- class GfmRcDetailApi < Grape::API
10
- format :json
11
-
12
- desc nil,
13
- detail: nil,
14
- entity: Entities::UseResponse,
15
- failure: [{ code: 400, model: Entities::ApiError }]
16
- get '/use_gfm_rc_detail' do
17
- { 'declared_params' => declared(params) }
18
- end
19
-
20
- add_swagger_documentation markdown: GrapeSwagger::Markdown::RedcarpetAdapter.new
21
- end
22
- end
23
- end
24
-
25
- def app
26
- TheApi::GfmRcDetailApi
27
- end
28
-
29
- subject do
30
- get '/swagger_doc'
31
- JSON.parse(last_response.body)
32
- end
33
-
34
- specify do
35
- expect(subject['paths']['/use_gfm_rc_detail']['get']).not_to include('description')
36
- expect(subject['paths']['/use_gfm_rc_detail']['get']['description']).to eql(nil)
37
- end
38
- end
39
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'a parent less namespace' do
6
- include_context 'namespace example'
7
-
8
- before :all do
9
- class ParentLessApi < Grape::API
10
- prefix :api
11
- mount TheApi::ParentLessNamespaceApi
12
- add_swagger_documentation version: 'v1'
13
- end
14
- end
15
-
16
- def app
17
- ParentLessApi
18
- end
19
-
20
- describe 'retrieves swagger-documentation on /swagger_doc' do
21
- let(:route_name) { ':animal/:breed/queues/:queue_id/reservations' }
22
- subject do
23
- get '/api/swagger_doc.json'
24
- JSON.parse(last_response.body)
25
- end
26
-
27
- context 'not raises error' do
28
- specify do
29
- expect(subject['tags']).to eql([{ 'name' => 'queues', 'description' => 'Operations about queues' }])
30
- expect(subject['paths']['/api/{animal}/{breed}/queues/{queue_id}/reservations']['get']['operationId'])
31
- .to eql('getApiAnimalBreedQueuesQueueIdReservations')
32
- end
33
- end
34
-
35
- context 'raises error' do
36
- specify do
37
- allow_any_instance_of(ParentLessApi)
38
- .to receive(:extract_parent_route).with(route_name).and_return(':animal') # BUT IT'S NOT STUBBING, CAUSE IT'S A PRIVATE METHODS
39
- expect { subject }.to raise_error NoMethodError
40
- end
41
- end
42
-
43
- context 'ParentLessApi.extract_parent_route' do
44
- specify do
45
- expect(ParentLessApi.send(:extract_parent_route, route_name)).to eq('queues')
46
- end
47
- end
48
- end
49
- end