Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Schema definitions for DELETE request body params #923

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* Your contribution here.
* [#922](https://github.com/ruby-grape/grape-swagger/pull/922): Force request body to be an schema object - [@numbata](https://github.com/numbata)
* [#923](https://github.com/ruby-grape/grape-swagger/pull/923): Enabled schema definitions for body parameters in DELETE requests - [@numbata](https://github.com/numbata)

### 2.0.2 (Februar 2, 2024)

Expand Down
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 @@ -186,7 +186,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/923_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 '#923 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' }
LeFnord marked this conversation as resolved.
Show resolved Hide resolved
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'
LeFnord marked this conversation as resolved.
Show resolved Hide resolved

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