grape-swagger 0.11.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -1
  3. data/.rubocop.yml +3 -0
  4. data/.rubocop_todo.yml +14 -22
  5. data/.travis.yml +7 -4
  6. data/CHANGELOG.md +53 -26
  7. data/Gemfile +1 -1
  8. data/README.md +414 -327
  9. data/RELEASING.md +3 -4
  10. data/example/api/endpoints.rb +132 -0
  11. data/example/api/entities.rb +18 -0
  12. data/example/config.ru +36 -2
  13. data/example/example_requests.postman_collection +146 -0
  14. data/example/swagger-example.png +0 -0
  15. data/grape-swagger.gemspec +9 -6
  16. data/lib/grape-swagger.rb +69 -99
  17. data/lib/grape-swagger/doc_methods.rb +69 -544
  18. data/lib/grape-swagger/doc_methods/data_type.rb +77 -0
  19. data/lib/grape-swagger/doc_methods/extensions.rb +75 -0
  20. data/lib/grape-swagger/doc_methods/move_params.rb +153 -0
  21. data/lib/grape-swagger/doc_methods/operation_id.rb +27 -0
  22. data/lib/grape-swagger/doc_methods/optional_object.rb +15 -0
  23. data/lib/grape-swagger/doc_methods/parse_params.rb +113 -0
  24. data/lib/grape-swagger/doc_methods/path_string.rb +29 -0
  25. data/lib/grape-swagger/doc_methods/produces_consumes.rb +12 -0
  26. data/lib/grape-swagger/doc_methods/status_codes.rb +17 -0
  27. data/lib/grape-swagger/doc_methods/tag_name_description.rb +26 -0
  28. data/lib/grape-swagger/endpoint.rb +317 -0
  29. data/lib/grape-swagger/version.rb +1 -1
  30. data/spec/lib/data_type_spec.rb +57 -0
  31. data/spec/lib/endpoint_spec.rb +6 -0
  32. data/spec/lib/extensions_spec.rb +127 -0
  33. data/spec/lib/move_params_spec.rb +298 -0
  34. data/spec/lib/operation_id_spec.rb +24 -0
  35. data/spec/lib/optional_object_spec.rb +40 -0
  36. data/spec/lib/path_string_spec.rb +38 -0
  37. data/spec/lib/produces_consumes_spec.rb +98 -0
  38. data/spec/markdown/kramdown_adapter_spec.rb +2 -9
  39. data/spec/markdown/redcarpet_adapter_spec.rb +2 -16
  40. data/spec/spec_helper.rb +7 -13
  41. data/spec/support/api_swagger_v2_result.rb +204 -0
  42. data/spec/support/namespace_tags.rb +73 -0
  43. data/spec/support/the_api_entities.rb +52 -0
  44. data/spec/support/the_paths_definitions.rb +94 -0
  45. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +32 -0
  46. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +151 -0
  47. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +109 -0
  48. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +124 -0
  49. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +51 -0
  50. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +44 -0
  51. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +56 -0
  52. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +146 -0
  53. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +197 -0
  54. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +151 -0
  55. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +217 -0
  56. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +64 -0
  57. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +184 -0
  58. data/spec/swagger_v2/api_swagger_v2_spec.rb +207 -0
  59. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +121 -0
  60. data/spec/{boolean_params_spec.rb → swagger_v2/boolean_params_spec.rb} +2 -2
  61. data/spec/{default_api_spec.rb → swagger_v2/default_api_spec.rb} +40 -36
  62. data/spec/swagger_v2/description_not_initialized.rb +39 -0
  63. data/spec/{float_api_spec.rb → swagger_v2/float_api_spec.rb} +2 -2
  64. data/spec/{form_params_spec.rb → swagger_v2/form_params_spec.rb} +9 -9
  65. data/spec/{grape-swagger_spec.rb → swagger_v2/grape-swagger_spec.rb} +0 -0
  66. data/spec/swagger_v2/hide_api_spec.rb +131 -0
  67. data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
  68. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +84 -0
  69. data/spec/swagger_v2/namespace_tags_spec.rb +76 -0
  70. data/spec/{namespaced_api_spec.rb → swagger_v2/namespaced_api_spec.rb} +6 -26
  71. data/spec/{param_type_spec.rb → swagger_v2/param_type_spec.rb} +10 -8
  72. data/spec/{param_values_spec.rb → swagger_v2/param_values_spec.rb} +52 -22
  73. data/spec/swagger_v2/params_array_spec.rb +63 -0
  74. data/spec/swagger_v2/params_hash_spec.rb +65 -0
  75. data/spec/swagger_v2/params_nested_spec.rb +63 -0
  76. data/spec/{reference_entity.rb → swagger_v2/reference_entity.rb} +18 -23
  77. data/spec/swagger_v2/response_model_spec.rb +212 -0
  78. data/spec/swagger_v2/simple_mounted_api_spec.rb +264 -0
  79. metadata +175 -90
  80. data/example/api.rb +0 -66
  81. data/lib/grape-swagger/markdown.rb +0 -23
  82. data/spec/api_description_spec.rb +0 -43
  83. data/spec/api_global_models_spec.rb +0 -77
  84. data/spec/api_models_spec.rb +0 -364
  85. data/spec/api_paths_spec.rb +0 -128
  86. data/spec/api_root_spec.rb +0 -30
  87. data/spec/api_with_nil_types.rb +0 -50
  88. data/spec/api_with_path_versioning_spec.rb +0 -33
  89. data/spec/api_with_prefix_and_namespace_spec.rb +0 -32
  90. data/spec/api_with_standalone_namespace_spec.rb +0 -215
  91. data/spec/array_entity_spec.rb +0 -34
  92. data/spec/array_params_spec.rb +0 -85
  93. data/spec/grape-swagger_helper_spec.rb +0 -152
  94. data/spec/group_params_spec.rb +0 -31
  95. data/spec/hash_params_spec.rb +0 -30
  96. data/spec/hide_api_spec.rb +0 -124
  97. data/spec/i18n_spec.rb +0 -364
  98. data/spec/markdown/markdown_spec.rb +0 -27
  99. data/spec/mounted_target_class_spec.rb +0 -63
  100. data/spec/mutually_exclusive_spec.rb +0 -36
  101. data/spec/non_default_api_spec.rb +0 -733
  102. data/spec/response_model_spec.rb +0 -121
  103. data/spec/simple_mounted_api_spec.rb +0 -213
  104. data/spec/support/i18n_helper.rb +0 -8
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe Grape::Endpoint do
4
+ subject { described_class.new(Grape::Util::InheritableSetting.new, {path: '/', method: :get}) }
5
+
6
+ end
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+
3
+ describe GrapeSwagger::DocMethods::Extensions do
4
+ describe "#extended? and extension" do
5
+ subject { described_class }
6
+ describe "return false (default)" do
7
+ let(:part) { {foo: 'bar', bar: 'foo'} }
8
+
9
+ specify do
10
+ expect(subject.extended?(part)).to be false
11
+ expect(subject.extension(part)).to be_empty
12
+ end
13
+ end
14
+
15
+ describe "return true" do
16
+ specify do
17
+ part = { foo: 'bar', bar: 'foo', x: 'something' }
18
+ expect(subject.extended?(part)).to be true
19
+ expect(subject.extension(part)).to eql({ x: 'something' })
20
+ expect(subject.extended?(part, :x)).to be true
21
+ expect(subject.extension(part, :x)).to eql({ x: 'something' })
22
+ end
23
+
24
+ specify do
25
+ part = { foo: 'bar', bar: 'foo', x_path: 'something' }
26
+ expect(subject.extended?(part, :x_path)).to be true
27
+ expect(subject.extension(part, :x_path)).to eql({ x_path: 'something' })
28
+ end
29
+
30
+ specify do
31
+ part = { foo: 'bar', bar: 'foo', x_def: 'something' }
32
+ expect(subject.extended?(part, :x_def)).to be true
33
+ expect(subject.extension(part, :x_def)).to eql({ x_def: 'something' })
34
+ end
35
+
36
+ specify do
37
+ part = { foo: 'bar', bar: 'foo', x_path: 'something', x_def: 'something' }
38
+ expect(subject.extended?(part, :x_path)).to be true
39
+ expect(subject.extension(part, :x_path)).to eql({ x_path: 'something' })
40
+ expect(subject.extended?(part, :x_def)).to be true
41
+ expect(subject.extension(part, :x_def)).to eql({ x_def: 'something' })
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "concatenate" do
47
+ describe "not nested" do
48
+ describe "simple" do
49
+ let(:extensions) { {x: {key_1: 'foo'}} }
50
+ let(:result) { {'x-key_1' => 'foo'} }
51
+ subject { described_class.concatenate(extensions) }
52
+
53
+ specify do
54
+ expect(subject).to eql result
55
+ end
56
+ end
57
+
58
+ describe "multiple" do
59
+ let(:extensions) { {x: {key_1: 'foo', key_2: 'bar'}} }
60
+ let(:result) { {'x-key_1' => 'foo', 'x-key_2' => 'bar'} }
61
+ subject { described_class.concatenate(extensions) }
62
+
63
+ specify do
64
+ expect(subject).to eql result
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "nested" do
70
+ describe "simple" do
71
+ let(:extensions) { {x: {key_1: { key_2: 'foo'}}} }
72
+ let(:result) { {'x-key_1' => { key_2: 'foo'}} }
73
+ subject { described_class.concatenate(extensions) }
74
+
75
+ specify do
76
+ expect(subject).to eql result
77
+ end
78
+ end
79
+
80
+ describe "simple multiple" do
81
+ let(:extensions) { {x: {key_1: { key_2: 'foo', key_3: 'bar'}}} }
82
+ let(:result) { {'x-key_1' => { key_2: 'foo', key_3: 'bar'}} }
83
+ subject { described_class.concatenate(extensions) }
84
+
85
+ specify do
86
+ expect(subject).to eql result
87
+ end
88
+ end
89
+
90
+ describe "simple deeper" do
91
+ let(:extensions) { {x: {key_1: { key_2: {key_3: 'foo'}}}} }
92
+ let(:result) { {'x-key_1' => { key_2: {key_3: 'foo'}}} }
93
+ subject { described_class.concatenate(extensions) }
94
+
95
+ specify do
96
+ expect(subject).to eql result
97
+ end
98
+ end
99
+
100
+ describe "multiple" do
101
+ let(:extensions) { {x: {key_1: { key_3: 'foo'}, key_2: { key_3: 'bar' }}} }
102
+ let(:result) { {'x-key_1' => { key_3: 'foo'}, 'x-key_2' => { key_3: 'bar' }} }
103
+ subject { described_class.concatenate(extensions) }
104
+
105
+ specify do
106
+ expect(subject).to eql result
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "reale example" do
112
+ let(:extensions) { {x: {
113
+ 'amazon-apigateway-auth' => {type: 'none'},
114
+ 'amazon-apigateway-integration' => {type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get'}
115
+ }} }
116
+ let(:result) { {
117
+ 'x-amazon-apigateway-auth' => {type: 'none'},
118
+ 'x-amazon-apigateway-integration' => {type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get'}
119
+ } }
120
+ subject { described_class.concatenate(extensions) }
121
+
122
+ specify do
123
+ expect(subject).to eql result
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,298 @@
1
+ require 'spec_helper'
2
+
3
+ describe GrapeSwagger::DocMethods::MoveParams do
4
+ include_context "the api paths/defs"
5
+
6
+ subject { described_class }
7
+
8
+ it { expect(subject.to_s).to eql 'GrapeSwagger::DocMethods::MoveParams' }
9
+
10
+ describe 'find_post_put' do
11
+ let(:paths) { {} }
12
+
13
+ describe 'paths empty' do
14
+ specify { expect { |b| subject.find_post_put(paths, &b) }.not_to yield_control }
15
+ end
16
+
17
+ describe 'no post/put given' do
18
+ let(:paths) {{
19
+ :'/foo'=> { get: {}, delete: {}},
20
+ :'/bar/{key}'=> { get: {}, delete: {}},
21
+ }}
22
+ specify { expect { |b| subject.find_post_put(paths, &b) }.not_to yield_control }
23
+ end
24
+
25
+ describe 'no post/put given' do
26
+ let(:paths) {{
27
+ :'/foo'=> { get: {}, delete: {}, post: {}, put: {}, patch: {} },
28
+ :'/bar/{key}'=> { get: {}, delete: {}, post: {}, put: {}, patch: {}},
29
+ }}
30
+ let(:expected) {[
31
+ { post: {}, put: {}, patch: {}},
32
+ { post: {}, put: {}, patch: {}},
33
+ ]}
34
+ specify { expect { |b| subject.find_post_put(paths, &b) }.to yield_control.twice }
35
+ specify { expect { |b| subject.find_post_put(paths, &b) }.to yield_successive_args *expected }
36
+ end
37
+ end
38
+
39
+ describe 'find_definition_and_params' do
40
+ specify do
41
+ subject.instance_variable_set(:@definitions, definitions)
42
+ subject.find_definition_and_params(found_path)
43
+
44
+ expect(definitions.keys).to include 'InBody', 'postRequestInBody'
45
+ end
46
+ end
47
+
48
+ describe 'move_params_to_new definition' do
49
+ let(:name) { 'Foo' }
50
+ let(:definitions) {{}}
51
+
52
+ describe 'post request' do
53
+ let(:verb) { 'post' }
54
+ let(:params) { paths["/in_body"][:post][:parameters] }
55
+
56
+ specify do
57
+ subject.instance_variable_set(:@definitions, definitions)
58
+ name = subject.send(:build_definition, name, verb)
59
+ subject.move_params_to_new(name, params)
60
+
61
+ expect(definitions[name]).to eql expected_post_defs
62
+ expect(params).to be_empty
63
+ end
64
+ end
65
+
66
+ describe 'put request' do
67
+ let(:verb) { 'put' }
68
+ let(:params) { paths["/in_body/{key}"][:put][:parameters] }
69
+
70
+ specify do
71
+ subject.instance_variable_set(:@definitions, definitions)
72
+ name, definition = subject.send(:build_definition, name, verb)
73
+ subject.move_params_to_new(name, params)
74
+
75
+ expect(definitions[name]).to eql expected_put_defs
76
+ expect(params.length).to be 1
77
+ end
78
+ end
79
+ end
80
+
81
+ describe 'nested definitions related' do
82
+ describe 'prepare_nested_names' do
83
+ before do
84
+ subject.send(:prepare_nested_names, params)
85
+ end
86
+
87
+ describe 'simple' do
88
+ let(:params) {[{:in=>"body", :name=>"address[street]", :description=>"street", :type=>"string", :required=>true}]}
89
+ let(:expected) {[{:in=>"body", :name=>"street", :description=>"street", :type=>"string", :required=>true}]}
90
+ specify do
91
+ expect(params).to eql expected
92
+ end
93
+ end
94
+
95
+ describe 'nested' do
96
+ let(:params) {[{:in=>"body", :name=>"address[street][name]", :description=>"street", :type=>"string", :required=>true}]}
97
+ let(:expected) {[{:in=>"body", :name=>"street[name]", :description=>"street", :type=>"string", :required=>true}]}
98
+ specify do
99
+ expect(params).to eql expected
100
+ end
101
+ end
102
+
103
+ describe 'array' do
104
+ let(:params) {[{:in=>"body", :name=>"address[][street_lines]", :description=>"street lines", :type=>"array", :required=>true}]}
105
+ let(:expected) {[{:in=>"body", :name=>"street_lines", :description=>"street lines", :type=>"array", :required=>true}]}
106
+ specify do
107
+ expect(params).to eql expected
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ describe 'private methods' do
114
+ describe 'build_definition' do
115
+ before do
116
+ subject.instance_variable_set(:@definitions, definitions)
117
+ subject.send(:build_definition, name, verb)
118
+ end
119
+
120
+ describe 'verb given' do
121
+ let(:verb) { 'post' }
122
+ let(:name) { 'Foo' }
123
+ let(:definitions) {{}}
124
+
125
+ specify do
126
+ definition = definitions.to_a.first
127
+ expect(definition.first).to eql 'postRequestFoo'
128
+ expect(definition.last).to eql({ type: 'object', properties: {}, required: [] })
129
+ end
130
+ end
131
+
132
+ describe 'no verb given' do
133
+ let(:name) { 'FooBar' }
134
+ let(:definitions) {{}}
135
+ let(:verb) { nil }
136
+
137
+ specify do
138
+ definition = definitions.to_a.first
139
+ expect(definition.first).to eql 'FooBar'
140
+ expect(definition.last).to eql({ type: 'object', properties: {}, required: [] })
141
+ end
142
+ end
143
+ end
144
+
145
+ describe 'build_body_parameter' do
146
+ let(:response) {{ schema: { '$ref' => '#/definitions/Somewhere'} }}
147
+
148
+ describe 'no name given' do
149
+ let(:name) { nil }
150
+ let(:expected_param) {
151
+ {:name=>"Somewhere", :in=>"body", :required=>true, :schema=>{'$ref' => "#/definitions/Somewhere"}}
152
+ }
153
+ specify do
154
+ parameter = subject.send(:build_body_parameter, response)
155
+ expect(parameter).to eql expected_param
156
+ end
157
+ end
158
+
159
+ describe 'name given' do
160
+ let(:name) { 'Foo' }
161
+ let(:expected_param) {
162
+ {:name=>"Somewhere", :in=>"body", :required=>true, :schema=>{'$ref' => "#/definitions/#{name}"}}
163
+ }
164
+ specify do
165
+ parameter = subject.send(:build_body_parameter, response, name)
166
+ expect(parameter).to eql expected_param
167
+ end
168
+ end
169
+ end
170
+
171
+ describe 'parse_model' do
172
+ let(:ref) { '#/definitions/InBody' }
173
+ subject(:object) { described_class.send(:parse_model, ref) }
174
+
175
+ specify { expect(object).to eql 'InBody' }
176
+ end
177
+
178
+ describe 'movable' do
179
+ describe 'path' do
180
+ let(:param) {{ in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true }}
181
+ it { expect(subject.send(:movable?, param)).to be true }
182
+ end
183
+
184
+ describe 'body' do
185
+ let(:param) {{ in: "body", name: "in_body", description: "in_body", type: "integer", format: "int32", required: true }}
186
+ it { expect(subject.send(:movable?, param)).to be true }
187
+ end
188
+
189
+ describe 'query' do
190
+ let(:param) {{ in: "query", name: "in_query", description: "in_query", type: "integer", format: "int32", required: true }}
191
+ it { expect(subject.send(:movable?, param)).to be false }
192
+ end
193
+
194
+ describe 'header' do
195
+ let(:param) {{ in: "header", name: "in_header", description: "in_header", type: "integer", format: "int32", required: true }}
196
+ it { expect(subject.send(:movable?, param)).to be false }
197
+ end
198
+ end
199
+
200
+ describe 'deletable' do
201
+ describe 'path' do
202
+ let(:param) {{ in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true }}
203
+ it { expect(subject.send(:deletable?, param)).to be false }
204
+ end
205
+
206
+ describe 'body' do
207
+ let(:param) {{ in: "body", name: "in_body_1", description: "in_body_1", type: "integer", format: "int32", required: true }}
208
+ it { expect(subject.send(:deletable?, param)).to be true }
209
+ end
210
+
211
+ describe 'query' do
212
+ let(:param) {{ in: "query", name: "in_query_1", description: "in_query_1", type: "integer", format: "int32", required: true }}
213
+ it { expect(subject.send(:deletable?, param)).to be false }
214
+ end
215
+
216
+ describe 'header' do
217
+ let(:param) {{ in: "header", name: "in_header_1", description: "in_header_1", type: "integer", format: "int32", required: true }}
218
+ it { expect(subject.send(:deletable?, param)).to be false }
219
+ end
220
+ end
221
+
222
+ describe 'should move' do
223
+ describe 'no move' do
224
+ let(:params) {[
225
+ { in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true },
226
+ { in: "formData", name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true }
227
+ ]}
228
+ it { expect(subject.send(:should_move?, params)).to be false }
229
+ end
230
+
231
+ describe 'move' do
232
+ let(:params) {[
233
+ { in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true },
234
+ { in: "body", name: "in_bosy", description: "in_bosy", type: "integer", format: "int32", required: true },
235
+ { in: "formData", name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true }
236
+ ]}
237
+ it { expect(subject.send(:should_move?, params)).to be true }
238
+ end
239
+ end
240
+
241
+ describe 'unify' do
242
+ before do
243
+ subject.send(:unify!, params) if subject.send(:should_move?, params)
244
+ end
245
+ describe 'param type with `:in` given' do
246
+ let(:params) {[
247
+ { in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true },
248
+ { in: "body", name: "in_body", description: "in_body", type: "integer", format: "int32", required: true },
249
+ { in: "query", name: "in_query", description: "in_query", type: "integer", format: "int32", required: true },
250
+ { in: "header", name: "in_header", description: "in_header", type: "integer", format: "int32", required: true },
251
+ { in: "formData", name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true }
252
+ ]}
253
+
254
+ let(:expected_params) {[
255
+ { in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true },
256
+ { in: "body", name: "in_body", description: "in_body", type: "integer", format: "int32", required: true },
257
+ { in: "query", name: "in_query", description: "in_query", type: "integer", format: "int32", required: true },
258
+ { in: "header", name: "in_header", description: "in_header", type: "integer", format: "int32", required: true },
259
+ { in: "body", name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true }
260
+ ]}
261
+ it { expect(params).to eql expected_params }
262
+ end
263
+
264
+ describe 'let it as is' do
265
+ let(:params) {[
266
+ { in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true },
267
+ { in: "formData", name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true }
268
+ ]}
269
+
270
+ let(:expected_params) {[
271
+ { in: "path", name: "key", description: nil, type: "integer", format: "int32", required: true },
272
+ { in: "formData", name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true }
273
+ ]}
274
+ it { expect(params).to eql expected_params }
275
+
276
+ end
277
+
278
+ describe 'param type with `:param_type` given' do
279
+ let(:params) {[
280
+ { param_type: "path", name: "key", description: nil, type: "integer", format: "int32", required: true },
281
+ { param_type: "body", name: "in_body", description: "in_body", type: "integer", format: "int32", required: true },
282
+ { param_type: "query", name: "in_query", description: "in_query", type: "integer", format: "int32", required: true },
283
+ { param_type: "header", name: "in_header", description: "in_header", type: "integer", format: "int32", required: true },
284
+ { param_type: "formData", name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true }
285
+ ]}
286
+
287
+ let(:expected_params) {[
288
+ { name: "key", description: nil, type: "integer", format: "int32", required: true, in: "path" },
289
+ { name: "in_body", description: "in_body", type: "integer", format: "int32", required: true, in: "body" },
290
+ { name: "in_query", description: "in_query", type: "integer", format: "int32", required: true, in: "query" },
291
+ { name: "in_header", description: "in_header", type: "integer", format: "int32", required: true, in: "header" },
292
+ { name: "in_form_data", description: "in_form_data", type: "integer", format: "int32", required: true, in: "body" }
293
+ ]}
294
+ it { expect(params).to eql expected_params }
295
+ end
296
+ end
297
+ end
298
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe GrapeSwagger::DocMethods::OperationId do
4
+ subject { described_class }
5
+
6
+ specify { expect(subject).to eql GrapeSwagger::DocMethods::OperationId }
7
+ specify { expect(subject).to respond_to :build }
8
+
9
+ describe 'build' do
10
+ specify do
11
+ expect(subject.build('GET')).to eql 'get'
12
+ expect(subject.build('get')).to eql 'get'
13
+ expect(subject.build(:get)).to eql 'get'
14
+ expect(subject.build('GET', 'foo')).to eql 'getFoo'
15
+ expect(subject.build('GET', '/foo')).to eql 'getFoo'
16
+ expect(subject.build('GET', 'bar/foo')).to eql 'getBarFoo'
17
+ expect(subject.build('GET', 'bar/foo{id}')).to eql 'getBarFooId'
18
+ expect(subject.build('GET', '/bar_foo{id}')).to eql 'getBarFooId'
19
+ expect(subject.build('GET', '/bar-foo{id}')).to eql 'getBarFooId'
20
+ expect(subject.build('GET', '/simple_test/bar-foo{id}')).to eql 'getSimpleTestBarFooId'
21
+ end
22
+ end
23
+
24
+ end