Skip to content

Commit

Permalink
Allow DELETE to have a params schema definition
Browse files Browse the repository at this point in the history
  • Loading branch information
numbata committed Apr 20, 2024
1 parent 262cdb9 commit 5c284c8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods/move_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def deletable?(param)
end

def move_methods
[:post, :put, :patch, 'POST', 'PUT', 'PATCH']
[:delete, :post, :put, :patch, 'DELETE', 'POST', 'PUT', 'PATCH']
end

def includes_body_param?(params)
Expand Down
55 changes: 55 additions & 0 deletions spec/issues/params_schema_definition_for_delete_action_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require 'spec_helper'

describe '#xxx Body params for DELETE action' do
let(:app) do
Class.new(Grape::API) do
params do
requires :post_id, type: Integer
requires :query, type: String, documentation: { type: 'string', param_type: 'body' }
end
delete '/posts/:post_id/comments' do
{ 'declared_params' => declared(params) }
end
add_swagger_documentation format: :json
end
end

describe 'retrieves the documentation for delete parameters as a schema defintion' do
subject do
get '/swagger_doc'
JSON.parse(last_response.body)
end

specify do
expect(subject['paths']['/posts/{post_id}/comments']['delete']['parameters']).to match(
[
{
'format' => 'int32',
'in' => 'path',
'name' => 'post_id',
'type' => 'integer',
'required' => true
},
{
'name' => 'deletePostsPostIdComments',
'in' => 'body',
'required' => true,
'schema' => { '$ref' => '#/definitions/deletePostsPostIdComments' }
}
]
)

expect(subject['definitions']['deletePostsPostIdComments']).to match(
'type' => 'object',
'properties' => {
'query' => {
'type' => 'string'
}
},
'required' => ['query']
)
end
end
end
4 changes: 2 additions & 2 deletions spec/lib/move_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
end

let(:allowed_verbs) do
[:post, :put, :patch, 'POST', 'PUT', 'PATCH']
[:post, :put, :patch, :delete, 'POST', 'PUT', 'PATCH', 'DELETE']
end

let(:not_allowed_verbs) do
[:get, :delete, 'GET', 'DELETE']
[:get, 'GET']
end

describe 'movable params' do
Expand Down
2 changes: 2 additions & 0 deletions spec/support/mock_parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'ostruct'

module GrapeSwagger
class MockParser
attr_reader :model, :endpoint
Expand Down

0 comments on commit 5c284c8

Please sign in to comment.