|
103 | 103 | subject.to_definition(path, params, route, definitions)
|
104 | 104 | expect(params).to eql(
|
105 | 105 | [
|
106 |
| - { name: 'InBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/postInBody' } } |
| 106 | + { name: 'postInBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/postInBody' } } |
107 | 107 | ]
|
108 | 108 | )
|
109 | 109 | expect(subject.definitions['postInBody']).not_to include :description
|
110 | 110 | expect(subject.definitions['postInBody']).to eql expected_post_defs
|
111 | 111 | end
|
| 112 | + |
| 113 | + context 'with a nickname' do |
| 114 | + let(:route_options) { { nickname: 'post-body' } } |
| 115 | + |
| 116 | + specify do |
| 117 | + subject.to_definition(path, params, route, definitions) |
| 118 | + expect(params).to eql( |
| 119 | + [ |
| 120 | + { name: 'post-body', in: 'body', required: true, schema: { '$ref' => '#/definitions/post-body' } } |
| 121 | + ] |
| 122 | + ) |
| 123 | + expect(subject.definitions['post-body']).not_to include :description |
| 124 | + expect(subject.definitions['post-body']).to eql expected_post_defs |
| 125 | + end |
| 126 | + end |
112 | 127 | end
|
113 | 128 |
|
114 |
| - describe 'POST' do |
| 129 | + describe 'PUT' do |
115 | 130 | let(:params) { paths['/in_body/{key}'][:put][:parameters] }
|
116 | 131 | let(:route) { Grape::Router::Route.new('PUT', path.dup, **route_options) }
|
117 | 132 |
|
|
120 | 135 | expect(params).to eql(
|
121 | 136 | [
|
122 | 137 | { in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true },
|
123 |
| - { name: 'InBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/putInBody' } } |
| 138 | + { name: 'putInBody', in: 'body', required: true, schema: { '$ref' => '#/definitions/putInBody' } } |
124 | 139 | ]
|
125 | 140 | )
|
126 | 141 | expect(subject.definitions['putInBody']).not_to include :description
|
127 | 142 | expect(subject.definitions['putInBody']).to eql expected_put_defs
|
128 | 143 | end
|
| 144 | + |
| 145 | + context 'with a nickname' do |
| 146 | + let(:route_options) { { nickname: 'put-body' } } |
| 147 | + |
| 148 | + specify do |
| 149 | + subject.to_definition(path, params, route, definitions) |
| 150 | + expect(params).to eql( |
| 151 | + [ |
| 152 | + { in: 'path', name: 'key', description: nil, type: 'integer', format: 'int32', required: true }, |
| 153 | + { name: 'put-body', in: 'body', required: true, schema: { '$ref' => '#/definitions/put-body' } } |
| 154 | + ] |
| 155 | + ) |
| 156 | + expect(subject.definitions['put-body']).not_to include :description |
| 157 | + expect(subject.definitions['put-body']).to eql expected_put_defs |
| 158 | + end |
| 159 | + end |
129 | 160 | end
|
130 | 161 | end
|
131 | 162 |
|
|
167 | 198 | let(:params) { [{ in: 'body', name: 'address[street][name]', description: 'street', type: 'string', required: true }] }
|
168 | 199 | before do
|
169 | 200 | subject.instance_variable_set(:@definitions, definitions)
|
170 |
| - subject.send(:build_definition, name, params, verb) |
| 201 | + subject.send(:build_definition, name, params) |
171 | 202 | end
|
172 | 203 |
|
173 |
| - describe 'verb given' do |
174 |
| - let(:verb) { 'post' } |
175 |
| - let(:name) { 'Foo' } |
176 |
| - let(:definitions) { {} } |
| 204 | + let(:name) { 'FooBar' } |
| 205 | + let(:definitions) { {} } |
177 | 206 |
|
178 |
| - specify do |
179 |
| - definition = definitions.to_a.first |
180 |
| - expect(definition.first).to eql 'postFoo' |
181 |
| - expect(definition.last).to eql(type: 'object', properties: {}) |
182 |
| - end |
183 |
| - end |
184 |
| - |
185 |
| - describe 'no verb given' do |
186 |
| - let(:name) { 'FooBar' } |
187 |
| - let(:definitions) { {} } |
188 |
| - let(:verb) { nil } |
189 |
| - |
190 |
| - specify do |
191 |
| - definition = definitions.to_a.first |
192 |
| - expect(definition.first).to eql 'FooBar' |
193 |
| - expect(definition.last).to eql(type: 'object', properties: {}) |
194 |
| - end |
| 207 | + specify do |
| 208 | + definition = definitions.to_a.first |
| 209 | + expect(definition.first).to eql 'FooBar' |
| 210 | + expect(definition.last).to eql(type: 'object', properties: {}) |
195 | 211 | end
|
196 | 212 | end
|
197 | 213 |
|
198 | 214 | describe 'build_body_parameter' do
|
199 |
| - describe 'name given' do |
200 |
| - let(:name) { 'Foo' } |
201 |
| - let(:reference) { 'Bar' } |
| 215 | + let(:name) { 'Foo' } |
| 216 | + let(:reference) { 'Bar' } |
| 217 | + let(:expected_param) do |
| 218 | + { name: name, in: 'body', required: true, schema: { '$ref' => "#/definitions/#{name}" } } |
| 219 | + end |
| 220 | + specify do |
| 221 | + parameter = subject.send(:build_body_parameter, name, {}) |
| 222 | + expect(parameter).to eql expected_param |
| 223 | + end |
| 224 | + |
| 225 | + describe 'body_name option specified' do |
| 226 | + let(:route_options) { { body_name: 'body' } } |
202 | 227 | let(:expected_param) do
|
203 |
| - { name: name, in: 'body', required: true, schema: { '$ref' => "#/definitions/#{reference}" } } |
| 228 | + { name: route_options[:body_name], in: 'body', required: true, schema: { '$ref' => "#/definitions/#{name}" } } |
204 | 229 | end
|
205 | 230 | specify do
|
206 |
| - parameter = subject.send(:build_body_parameter, reference, name, {}) |
| 231 | + parameter = subject.send(:build_body_parameter, name, route_options) |
207 | 232 | expect(parameter).to eql expected_param
|
208 | 233 | end
|
209 |
| - |
210 |
| - describe 'body_name option specified' do |
211 |
| - let(:route_options) { { body_name: 'body' } } |
212 |
| - let(:expected_param) do |
213 |
| - { name: route_options[:body_name], in: 'body', required: true, schema: { '$ref' => "#/definitions/#{reference}" } } |
214 |
| - end |
215 |
| - specify do |
216 |
| - parameter = subject.send(:build_body_parameter, reference, name, route_options) |
217 |
| - expect(parameter).to eql expected_param |
218 |
| - end |
219 |
| - end |
220 | 234 | end
|
221 | 235 | end
|
222 | 236 |
|
|
0 commit comments