Skip to content

Commit 599a486

Browse files
committed
Allow DELETE to have a params schema definition
1 parent 262cdb9 commit 599a486

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#### Fixes
88

99
* Your contribution here.
10-
10+
* [#923](https://github.com/ruby-grape/grape-swagger/pull/923): Enabled schema definitions for body parameters in DELETE requests - [@numbata](https://github.com/numbata)
1111

1212
### 2.0.2 (Februar 2, 2024)
1313

lib/grape-swagger/doc_methods/move_params.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def deletable?(param)
197197
end
198198

199199
def move_methods
200-
[:post, :put, :patch, 'POST', 'PUT', 'PATCH']
200+
[:delete, :post, :put, :patch, 'DELETE', 'POST', 'PUT', 'PATCH']
201201
end
202202

203203
def includes_body_param?(params)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe '#923 Body params for DELETE action' do
6+
let(:app) do
7+
Class.new(Grape::API) do
8+
params do
9+
requires :post_id, type: Integer
10+
requires :query, type: String, documentation: { type: 'string', param_type: 'body' }
11+
end
12+
delete '/posts/:post_id/comments' do
13+
{ 'declared_params' => declared(params) }
14+
end
15+
add_swagger_documentation format: :json
16+
end
17+
end
18+
19+
describe 'retrieves the documentation for delete parameters as a schema defintion' do
20+
subject do
21+
get '/swagger_doc'
22+
JSON.parse(last_response.body)
23+
end
24+
25+
specify do
26+
expect(subject['paths']['/posts/{post_id}/comments']['delete']['parameters']).to match(
27+
[
28+
{
29+
'format' => 'int32',
30+
'in' => 'path',
31+
'name' => 'post_id',
32+
'type' => 'integer',
33+
'required' => true
34+
},
35+
{
36+
'name' => 'deletePostsPostIdComments',
37+
'in' => 'body',
38+
'required' => true,
39+
'schema' => { '$ref' => '#/definitions/deletePostsPostIdComments' }
40+
}
41+
]
42+
)
43+
44+
expect(subject['definitions']['deletePostsPostIdComments']).to match(
45+
'type' => 'object',
46+
'properties' => {
47+
'query' => {
48+
'type' => 'string'
49+
}
50+
},
51+
'required' => ['query']
52+
)
53+
end
54+
end
55+
end

spec/lib/move_params_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
end
3131

3232
let(:allowed_verbs) do
33-
[:post, :put, :patch, 'POST', 'PUT', 'PATCH']
33+
[:post, :put, :patch, :delete, 'POST', 'PUT', 'PATCH', 'DELETE']
3434
end
3535

3636
let(:not_allowed_verbs) do
37-
[:get, :delete, 'GET', 'DELETE']
37+
[:get, 'GET']
3838
end
3939

4040
describe 'movable params' do

spec/support/mock_parser.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'ostruct'
4+
35
module GrapeSwagger
46
class MockParser
57
attr_reader :model, :endpoint

0 commit comments

Comments
 (0)