grape-swagger 0.33.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -7
  3. data/.rubocop_todo.yml +0 -6
  4. data/.travis.yml +11 -10
  5. data/CHANGELOG.md +75 -5
  6. data/Gemfile +5 -5
  7. data/README.md +73 -5
  8. data/grape-swagger.gemspec +1 -1
  9. data/lib/grape-swagger/doc_methods/build_model_definition.rb +0 -17
  10. data/lib/grape-swagger/doc_methods/data_type.rb +1 -1
  11. data/lib/grape-swagger/doc_methods/extensions.rb +6 -1
  12. data/lib/grape-swagger/doc_methods/format_data.rb +51 -0
  13. data/lib/grape-swagger/doc_methods/move_params.rb +22 -49
  14. data/lib/grape-swagger/doc_methods/parse_params.rb +6 -0
  15. data/lib/grape-swagger/doc_methods.rb +2 -0
  16. data/lib/grape-swagger/endpoint/params_parser.rb +22 -22
  17. data/lib/grape-swagger/endpoint.rb +33 -14
  18. data/lib/grape-swagger/version.rb +1 -1
  19. data/lib/grape-swagger.rb +1 -1
  20. data/spec/issues/751_deeply_nested_objects_spec.rb +190 -0
  21. data/spec/lib/data_type_spec.rb +2 -2
  22. data/spec/lib/endpoint/params_parser_spec.rb +46 -21
  23. data/spec/lib/endpoint_spec.rb +4 -4
  24. data/spec/lib/extensions_spec.rb +10 -0
  25. data/spec/lib/format_data_spec.rb +91 -0
  26. data/spec/lib/move_params_spec.rb +4 -266
  27. data/spec/lib/optional_object_spec.rb +0 -1
  28. data/spec/spec_helper.rb +1 -1
  29. data/spec/support/model_parsers/entity_parser.rb +1 -1
  30. data/spec/support/model_parsers/representable_parser.rb +1 -1
  31. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +3 -1
  32. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +14 -3
  33. data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +153 -0
  34. data/spec/swagger_v2/boolean_params_spec.rb +1 -1
  35. data/spec/swagger_v2/description_not_initialized_spec.rb +39 -0
  36. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +33 -0
  37. data/spec/swagger_v2/mounted_target_class_spec.rb +1 -1
  38. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +15 -1
  39. data/spec/swagger_v2/params_array_spec.rb +2 -2
  40. data/spec/swagger_v2/parent_less_namespace_spec.rb +32 -0
  41. data/spec/swagger_v2/{reference_entity.rb → reference_entity_spec.rb} +17 -10
  42. metadata +20 -13
  43. data/spec/swagger_v2/description_not_initialized.rb +0 -39
  44. data/spec/swagger_v2/parent_less_namespace.rb +0 -49
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'response with root' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+
8
+ before :all do
9
+ module TheApi
10
+ class ResponseApiWithRoot < Grape::API
11
+ format :json
12
+
13
+ desc 'This returns something',
14
+ http_codes: [{ code: 200, model: Entities::Something }]
15
+ get '/ordinary_response' do
16
+ { 'declared_params' => declared(params) }
17
+ end
18
+
19
+ desc 'This returns something',
20
+ is_array: true,
21
+ http_codes: [{ code: 200, model: Entities::Something }]
22
+ get '/response_with_array' do
23
+ { 'declared_params' => declared(params) }
24
+ end
25
+
26
+ route_setting :swagger, root: true
27
+ desc 'This returns something',
28
+ http_codes: [{ code: 200, model: Entities::Something }]
29
+ get '/response_with_root' do
30
+ { 'declared_params' => declared(params) }
31
+ end
32
+
33
+ route_setting :swagger, root: true
34
+ desc 'This returns underscored root',
35
+ http_codes: [{ code: 200, model: Entities::ApiError }]
36
+ get '/response_with_root_underscore' do
37
+ { 'declared_params' => declared(params) }
38
+ end
39
+
40
+ route_setting :swagger, root: true
41
+ desc 'This returns something',
42
+ is_array: true,
43
+ http_codes: [{ code: 200, model: Entities::Something }]
44
+ get '/response_with_array_and_root' do
45
+ { 'declared_params' => declared(params) }
46
+ end
47
+
48
+ route_setting :swagger, root: 'custom_root'
49
+ desc 'This returns something',
50
+ http_codes: [{ code: 200, model: Entities::Something }]
51
+ get '/response_with_custom_root' do
52
+ { 'declared_params' => declared(params) }
53
+ end
54
+
55
+ add_swagger_documentation
56
+ end
57
+ end
58
+ end
59
+
60
+ def app
61
+ TheApi::ResponseApiWithRoot
62
+ end
63
+
64
+ describe 'GET /ordinary_response' do
65
+ subject do
66
+ get '/swagger_doc/ordinary_response'
67
+ JSON.parse(last_response.body)
68
+ end
69
+
70
+ it 'does not add root or array' do
71
+ schema = subject.dig('paths', '/ordinary_response', 'get', 'responses', '200', 'schema')
72
+ expect(schema).to eq(
73
+ '$ref' => '#/definitions/Something'
74
+ )
75
+ end
76
+ end
77
+
78
+ describe 'GET /response_with_array' do
79
+ subject do
80
+ get '/swagger_doc/response_with_array'
81
+ JSON.parse(last_response.body)
82
+ end
83
+
84
+ it 'adds array to the response' do
85
+ schema = subject.dig('paths', '/response_with_array', 'get', 'responses', '200', 'schema')
86
+ expect(schema).to eq(
87
+ 'type' => 'array', 'items' => { '$ref' => '#/definitions/Something' }
88
+ )
89
+ end
90
+ end
91
+
92
+ describe 'GET /response_with_root' do
93
+ subject do
94
+ get '/swagger_doc/response_with_root'
95
+ JSON.parse(last_response.body)
96
+ end
97
+
98
+ it 'adds root to the response' do
99
+ schema = subject.dig('paths', '/response_with_root', 'get', 'responses', '200', 'schema')
100
+ expect(schema).to eq(
101
+ 'type' => 'object',
102
+ 'properties' => { 'something' => { '$ref' => '#/definitions/Something' } }
103
+ )
104
+ end
105
+ end
106
+
107
+ describe 'GET /response_with_root_underscore' do
108
+ subject do
109
+ get '/swagger_doc/response_with_root_underscore'
110
+ JSON.parse(last_response.body)
111
+ end
112
+
113
+ it 'adds root to the response' do
114
+ schema = subject.dig('paths', '/response_with_root_underscore', 'get', 'responses', '200', 'schema')
115
+ expect(schema).to eq(
116
+ 'type' => 'object',
117
+ 'properties' => { 'api_error' => { '$ref' => '#/definitions/ApiError' } }
118
+ )
119
+ end
120
+ end
121
+
122
+ describe 'GET /response_with_array_and_root' do
123
+ subject do
124
+ get '/swagger_doc/response_with_array_and_root'
125
+ JSON.parse(last_response.body)
126
+ end
127
+
128
+ it 'adds root and array to the response' do
129
+ schema = subject.dig('paths', '/response_with_array_and_root', 'get', 'responses', '200', 'schema')
130
+ expect(schema).to eq(
131
+ 'type' => 'object',
132
+ 'properties' => {
133
+ 'somethings' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/Something' } }
134
+ }
135
+ )
136
+ end
137
+ end
138
+
139
+ describe 'GET /response_with_custom_root' do
140
+ subject do
141
+ get '/swagger_doc/response_with_custom_root'
142
+ JSON.parse(last_response.body)
143
+ end
144
+
145
+ it 'adds root to the response' do
146
+ schema = subject.dig('paths', '/response_with_custom_root', 'get', 'responses', '200', 'schema')
147
+ expect(schema).to eq(
148
+ 'type' => 'object',
149
+ 'properties' => { 'custom_root' => { '$ref' => '#/definitions/Something' } }
150
+ )
151
+ end
152
+ end
153
+ end
@@ -8,7 +8,7 @@ describe 'Boolean Params' do
8
8
  format :json
9
9
 
10
10
  params do
11
- requires :a_boolean, type: Virtus::Attribute::Boolean
11
+ requires :a_boolean, type: Grape::API::Boolean
12
12
  end
13
13
  post :splines do
14
14
  end
@@ -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,29 +1,29 @@
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: 1.0.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-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.16.2
19
+ version: 1.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.16.2
26
+ version: 1.3.0
27
27
  description:
28
28
  email:
29
29
  - tim.vandecasteele@gmail.com
@@ -59,6 +59,7 @@ files:
59
59
  - lib/grape-swagger/doc_methods/build_model_definition.rb
60
60
  - lib/grape-swagger/doc_methods/data_type.rb
61
61
  - lib/grape-swagger/doc_methods/extensions.rb
62
+ - lib/grape-swagger/doc_methods/format_data.rb
62
63
  - lib/grape-swagger/doc_methods/headers.rb
63
64
  - lib/grape-swagger/doc_methods/move_params.rb
64
65
  - lib/grape-swagger/doc_methods/operation_id.rb
@@ -93,10 +94,12 @@ files:
93
94
  - spec/issues/605_root_route_documentation_spec.rb
94
95
  - spec/issues/650_params_array_spec.rb
95
96
  - spec/issues/680_keep_204_error_schemas_spec.rb
97
+ - spec/issues/751_deeply_nested_objects_spec.rb
96
98
  - spec/lib/data_type_spec.rb
97
99
  - spec/lib/endpoint/params_parser_spec.rb
98
100
  - spec/lib/endpoint_spec.rb
99
101
  - spec/lib/extensions_spec.rb
102
+ - spec/lib/format_data_spec.rb
100
103
  - spec/lib/model_parsers_spec.rb
101
104
  - spec/lib/move_params_spec.rb
102
105
  - spec/lib/oapi_tasks_spec.rb
@@ -136,13 +139,14 @@ files:
136
139
  - spec/swagger_v2/api_swagger_v2_response_spec.rb
137
140
  - spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
138
141
  - spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
142
+ - spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb
139
143
  - spec/swagger_v2/api_swagger_v2_spec.rb
140
144
  - spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
141
145
  - spec/swagger_v2/api_swagger_v2_type-format_spec.rb
142
146
  - spec/swagger_v2/boolean_params_spec.rb
143
147
  - spec/swagger_v2/default_api_spec.rb
144
148
  - spec/swagger_v2/deprecated_field_spec.rb
145
- - spec/swagger_v2/description_not_initialized.rb
149
+ - spec/swagger_v2/description_not_initialized_spec.rb
146
150
  - spec/swagger_v2/endpoint_versioned_path_spec.rb
147
151
  - spec/swagger_v2/errors_spec.rb
148
152
  - spec/swagger_v2/float_api_spec.rb
@@ -165,8 +169,8 @@ files:
165
169
  - spec/swagger_v2/params_array_spec.rb
166
170
  - spec/swagger_v2/params_hash_spec.rb
167
171
  - spec/swagger_v2/params_nested_spec.rb
168
- - spec/swagger_v2/parent_less_namespace.rb
169
- - spec/swagger_v2/reference_entity.rb
172
+ - spec/swagger_v2/parent_less_namespace_spec.rb
173
+ - spec/swagger_v2/reference_entity_spec.rb
170
174
  - spec/swagger_v2/security_requirement_spec.rb
171
175
  - spec/swagger_v2/simple_mounted_api_spec.rb
172
176
  - spec/version_spec.rb
@@ -189,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
193
  - !ruby/object:Gem::Version
190
194
  version: '0'
191
195
  requirements: []
192
- rubygems_version: 3.0.3
196
+ rubygems_version: 3.1.2
193
197
  signing_key:
194
198
  specification_version: 4
195
199
  summary: Add auto generated documentation to your Grape API that can be displayed
@@ -212,10 +216,12 @@ test_files:
212
216
  - spec/issues/605_root_route_documentation_spec.rb
213
217
  - spec/issues/650_params_array_spec.rb
214
218
  - spec/issues/680_keep_204_error_schemas_spec.rb
219
+ - spec/issues/751_deeply_nested_objects_spec.rb
215
220
  - spec/lib/data_type_spec.rb
216
221
  - spec/lib/endpoint/params_parser_spec.rb
217
222
  - spec/lib/endpoint_spec.rb
218
223
  - spec/lib/extensions_spec.rb
224
+ - spec/lib/format_data_spec.rb
219
225
  - spec/lib/model_parsers_spec.rb
220
226
  - spec/lib/move_params_spec.rb
221
227
  - spec/lib/oapi_tasks_spec.rb
@@ -255,13 +261,14 @@ test_files:
255
261
  - spec/swagger_v2/api_swagger_v2_response_spec.rb
256
262
  - spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
257
263
  - spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
264
+ - spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb
258
265
  - spec/swagger_v2/api_swagger_v2_spec.rb
259
266
  - spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
260
267
  - spec/swagger_v2/api_swagger_v2_type-format_spec.rb
261
268
  - spec/swagger_v2/boolean_params_spec.rb
262
269
  - spec/swagger_v2/default_api_spec.rb
263
270
  - spec/swagger_v2/deprecated_field_spec.rb
264
- - spec/swagger_v2/description_not_initialized.rb
271
+ - spec/swagger_v2/description_not_initialized_spec.rb
265
272
  - spec/swagger_v2/endpoint_versioned_path_spec.rb
266
273
  - spec/swagger_v2/errors_spec.rb
267
274
  - spec/swagger_v2/float_api_spec.rb
@@ -284,8 +291,8 @@ test_files:
284
291
  - spec/swagger_v2/params_array_spec.rb
285
292
  - spec/swagger_v2/params_hash_spec.rb
286
293
  - spec/swagger_v2/params_nested_spec.rb
287
- - spec/swagger_v2/parent_less_namespace.rb
288
- - spec/swagger_v2/reference_entity.rb
294
+ - spec/swagger_v2/parent_less_namespace_spec.rb
295
+ - spec/swagger_v2/reference_entity_spec.rb
289
296
  - spec/swagger_v2/security_requirement_spec.rb
290
297
  - spec/swagger_v2/simple_mounted_api_spec.rb
291
298
  - 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