grape-swagger 0.33.0 → 0.34.0

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 +8 -9
  5. data/CHANGELOG.md +67 -5
  6. data/Gemfile +4 -4
  7. data/README.md +66 -3
  8. data/grape-swagger.gemspec +1 -1
  9. data/lib/grape-swagger.rb +1 -1
  10. data/lib/grape-swagger/doc_methods.rb +2 -0
  11. data/lib/grape-swagger/doc_methods/build_model_definition.rb +0 -17
  12. data/lib/grape-swagger/doc_methods/extensions.rb +6 -1
  13. data/lib/grape-swagger/doc_methods/format_data.rb +51 -0
  14. data/lib/grape-swagger/doc_methods/move_params.rb +22 -49
  15. data/lib/grape-swagger/doc_methods/parse_params.rb +6 -0
  16. data/lib/grape-swagger/endpoint.rb +32 -13
  17. data/lib/grape-swagger/endpoint/params_parser.rb +10 -17
  18. data/lib/grape-swagger/version.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 +22 -9
  37. data/spec/swagger_v2/description_not_initialized.rb +0 -39
  38. data/spec/swagger_v2/parent_less_namespace.rb +0 -49
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'has no description, if details or description are nil' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+
8
+ before :all do
9
+ module TheApi
10
+ class GfmRcDetailApi < Grape::API
11
+ format :json
12
+
13
+ desc nil,
14
+ detail: nil,
15
+ entity: Entities::UseResponse,
16
+ failure: [{ code: 400, model: Entities::ApiError }]
17
+ get '/use_gfm_rc_detail' do
18
+ { 'declared_params' => declared(params) }
19
+ end
20
+
21
+ add_swagger_documentation
22
+ end
23
+ end
24
+ end
25
+
26
+ def app
27
+ TheApi::GfmRcDetailApi
28
+ end
29
+
30
+ subject do
31
+ get '/swagger_doc'
32
+ JSON.parse(last_response.body)
33
+ end
34
+
35
+ specify do
36
+ expect(subject['paths']['/use_gfm_rc_detail']['get']).not_to include('description')
37
+ expect(subject['paths']['/use_gfm_rc_detail']['get']['description']).to eql(nil)
38
+ end
39
+ end
@@ -52,6 +52,39 @@ describe 'Grape::Endpoint#path_and_definitions' do
52
52
  expect(subject.first['/v1/item'][:get][:tags]).to eq ['special-item']
53
53
  end
54
54
  end
55
+
56
+ context 'when parameter with a custom type is specified' do
57
+ let(:item) do
58
+ Class.new(Grape::API) do
59
+ Color = Struct.new(:value) do
60
+ def self.parse(value)
61
+ new(value: value)
62
+ end
63
+ end
64
+
65
+ class ColorEntity < Grape::Entity
66
+ expose :value
67
+ end
68
+
69
+ version 'v1', using: :path
70
+
71
+ resource :item do
72
+ params do
73
+ requires :root, type: Hash do
74
+ optional :color, type: Color, documentation: { type: ColorEntity }
75
+ end
76
+ end
77
+ post '/'
78
+ end
79
+ end
80
+ end
81
+
82
+ it 'creates a reference to the model instead of using the non-existent type' do
83
+ color = subject.dig(1, 'postV1Item', :properties, :root, :properties, :color)
84
+ expect(color).not_to eq(type: 'ColorEntity')
85
+ expect(color).to eq('$ref' => '#/definitions/ColorEntity')
86
+ end
87
+ end
55
88
  end
56
89
 
57
90
  context 'when mounting an API more than once', if: GrapeVersion.satisfy?('>= 1.2.0') do
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe 'docs mounted separately from api' do
5
+ xdescribe 'docs mounted separately from api' do
6
6
  before :all do
7
7
  class ActualApi < Grape::API
8
8
  desc 'Document root'
@@ -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.0
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-11 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.2.5
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.16.2
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.5
27
33
  description:
28
34
  email:
29
35
  - tim.vandecasteele@gmail.com
@@ -59,6 +65,7 @@ files:
59
65
  - lib/grape-swagger/doc_methods/build_model_definition.rb
60
66
  - lib/grape-swagger/doc_methods/data_type.rb
61
67
  - lib/grape-swagger/doc_methods/extensions.rb
68
+ - lib/grape-swagger/doc_methods/format_data.rb
62
69
  - lib/grape-swagger/doc_methods/headers.rb
63
70
  - lib/grape-swagger/doc_methods/move_params.rb
64
71
  - lib/grape-swagger/doc_methods/operation_id.rb
@@ -93,10 +100,12 @@ files:
93
100
  - spec/issues/605_root_route_documentation_spec.rb
94
101
  - spec/issues/650_params_array_spec.rb
95
102
  - spec/issues/680_keep_204_error_schemas_spec.rb
103
+ - spec/issues/751_deeply_nested_objects_spec.rb
96
104
  - spec/lib/data_type_spec.rb
97
105
  - spec/lib/endpoint/params_parser_spec.rb
98
106
  - spec/lib/endpoint_spec.rb
99
107
  - spec/lib/extensions_spec.rb
108
+ - spec/lib/format_data_spec.rb
100
109
  - spec/lib/model_parsers_spec.rb
101
110
  - spec/lib/move_params_spec.rb
102
111
  - spec/lib/oapi_tasks_spec.rb
@@ -136,13 +145,14 @@ files:
136
145
  - spec/swagger_v2/api_swagger_v2_response_spec.rb
137
146
  - spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
138
147
  - spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
148
+ - spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb
139
149
  - spec/swagger_v2/api_swagger_v2_spec.rb
140
150
  - spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
141
151
  - spec/swagger_v2/api_swagger_v2_type-format_spec.rb
142
152
  - spec/swagger_v2/boolean_params_spec.rb
143
153
  - spec/swagger_v2/default_api_spec.rb
144
154
  - spec/swagger_v2/deprecated_field_spec.rb
145
- - spec/swagger_v2/description_not_initialized.rb
155
+ - spec/swagger_v2/description_not_initialized_spec.rb
146
156
  - spec/swagger_v2/endpoint_versioned_path_spec.rb
147
157
  - spec/swagger_v2/errors_spec.rb
148
158
  - spec/swagger_v2/float_api_spec.rb
@@ -165,8 +175,8 @@ files:
165
175
  - spec/swagger_v2/params_array_spec.rb
166
176
  - spec/swagger_v2/params_hash_spec.rb
167
177
  - spec/swagger_v2/params_nested_spec.rb
168
- - spec/swagger_v2/parent_less_namespace.rb
169
- - spec/swagger_v2/reference_entity.rb
178
+ - spec/swagger_v2/parent_less_namespace_spec.rb
179
+ - spec/swagger_v2/reference_entity_spec.rb
170
180
  - spec/swagger_v2/security_requirement_spec.rb
171
181
  - spec/swagger_v2/simple_mounted_api_spec.rb
172
182
  - spec/version_spec.rb
@@ -189,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
199
  - !ruby/object:Gem::Version
190
200
  version: '0'
191
201
  requirements: []
192
- rubygems_version: 3.0.3
202
+ rubygems_version: 3.1.2
193
203
  signing_key:
194
204
  specification_version: 4
195
205
  summary: Add auto generated documentation to your Grape API that can be displayed
@@ -212,10 +222,12 @@ test_files:
212
222
  - spec/issues/605_root_route_documentation_spec.rb
213
223
  - spec/issues/650_params_array_spec.rb
214
224
  - spec/issues/680_keep_204_error_schemas_spec.rb
225
+ - spec/issues/751_deeply_nested_objects_spec.rb
215
226
  - spec/lib/data_type_spec.rb
216
227
  - spec/lib/endpoint/params_parser_spec.rb
217
228
  - spec/lib/endpoint_spec.rb
218
229
  - spec/lib/extensions_spec.rb
230
+ - spec/lib/format_data_spec.rb
219
231
  - spec/lib/model_parsers_spec.rb
220
232
  - spec/lib/move_params_spec.rb
221
233
  - spec/lib/oapi_tasks_spec.rb
@@ -255,13 +267,14 @@ test_files:
255
267
  - spec/swagger_v2/api_swagger_v2_response_spec.rb
256
268
  - spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
257
269
  - spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
270
+ - spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb
258
271
  - spec/swagger_v2/api_swagger_v2_spec.rb
259
272
  - spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
260
273
  - spec/swagger_v2/api_swagger_v2_type-format_spec.rb
261
274
  - spec/swagger_v2/boolean_params_spec.rb
262
275
  - spec/swagger_v2/default_api_spec.rb
263
276
  - spec/swagger_v2/deprecated_field_spec.rb
264
- - spec/swagger_v2/description_not_initialized.rb
277
+ - spec/swagger_v2/description_not_initialized_spec.rb
265
278
  - spec/swagger_v2/endpoint_versioned_path_spec.rb
266
279
  - spec/swagger_v2/errors_spec.rb
267
280
  - spec/swagger_v2/float_api_spec.rb
@@ -284,8 +297,8 @@ test_files:
284
297
  - spec/swagger_v2/params_array_spec.rb
285
298
  - spec/swagger_v2/params_hash_spec.rb
286
299
  - spec/swagger_v2/params_nested_spec.rb
287
- - spec/swagger_v2/parent_less_namespace.rb
288
- - spec/swagger_v2/reference_entity.rb
300
+ - spec/swagger_v2/parent_less_namespace_spec.rb
301
+ - spec/swagger_v2/reference_entity_spec.rb
289
302
  - spec/swagger_v2/security_requirement_spec.rb
290
303
  - spec/swagger_v2/simple_mounted_api_spec.rb
291
304
  - 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