2015-11-04 20:03:42 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'Group Params as Array' do
|
|
|
|
def app
|
|
|
|
Class.new(Grape::API) do
|
|
|
|
format :json
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :required_group, type: Array do
|
|
|
|
requires :required_param_1
|
|
|
|
requires :required_param_2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
post '/groups' do
|
|
|
|
{ 'declared_params' => declared(params) }
|
|
|
|
end
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :typed_group, type: Array do
|
|
|
|
requires :id, type: Integer, desc: "integer given"
|
|
|
|
requires :name, type: String, desc: "string given"
|
|
|
|
optional :email, type: String, desc: "email given"
|
|
|
|
optional :others, type: Integer, values: [1, 2, 3]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
post '/type_given' do
|
|
|
|
{ 'declared_params' => declared(params) }
|
|
|
|
end
|
|
|
|
|
|
|
|
add_swagger_documentation
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-19 01:40:53 +08:00
|
|
|
describe "retrieves the documentation for grouped parameters" do
|
|
|
|
subject do
|
|
|
|
get '/swagger_doc/groups'
|
|
|
|
JSON.parse(last_response.body)
|
|
|
|
end
|
2015-11-04 20:03:42 +08:00
|
|
|
|
2015-12-19 01:40:53 +08:00
|
|
|
specify do
|
|
|
|
expect(subject).to eql({
|
|
|
|
"info"=>{"title"=>"API title", "version"=>"v1"},
|
|
|
|
"swagger"=>"2.0",
|
|
|
|
"produces"=>["application/json"],
|
|
|
|
"host"=>"example.org",
|
2016-03-09 23:37:03 +08:00
|
|
|
"tags" => [{"name"=>"groups", "description"=>"Operations about groups"}, {"name"=>"type_given", "description"=>"Operations about type_givens"}],
|
2015-12-19 01:40:53 +08:00
|
|
|
"schemes" => ["https", "http"],
|
|
|
|
"paths"=>{
|
|
|
|
"/groups"=>{
|
|
|
|
"post"=>{
|
|
|
|
"produces"=>["application/json"],
|
2016-03-09 23:37:03 +08:00
|
|
|
"tags"=>["groups"],
|
2016-03-16 00:53:03 +08:00
|
|
|
"operationId"=>"postGroups",
|
2015-12-19 01:40:53 +08:00
|
|
|
"responses"=>{"201"=>{"description"=>"created Group"}},
|
|
|
|
"parameters"=>[
|
|
|
|
{"in"=>"formData", "name"=>"required_group[][required_param_1]", "description"=>nil, "type"=>"string", "required"=>true, "allowMultiple"=>true},
|
|
|
|
{"in"=>"formData", "name"=>"required_group[][required_param_2]", "description"=>nil, "type"=>"string", "required"=>true, "allowMultiple"=>true}
|
|
|
|
]}}}})
|
|
|
|
end
|
2015-11-04 20:03:42 +08:00
|
|
|
end
|
|
|
|
|
2015-12-19 01:40:53 +08:00
|
|
|
describe "retrieves the documentation for typed group parameters" do
|
|
|
|
subject do
|
|
|
|
get '/swagger_doc/type_given'
|
|
|
|
JSON.parse(last_response.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject).to eql({
|
|
|
|
"info"=>{"title"=>"API title", "version"=>"v1"},
|
|
|
|
"swagger"=>"2.0",
|
|
|
|
"produces"=>["application/json"],
|
|
|
|
"host"=>"example.org",
|
2016-03-09 23:37:03 +08:00
|
|
|
"tags"=>[{"name"=>"groups", "description"=>"Operations about groups"}, {"name"=>"type_given", "description"=>"Operations about type_givens"}],
|
|
|
|
"schemes"=>["https", "http"],
|
2015-12-19 01:40:53 +08:00
|
|
|
"paths"=>{
|
|
|
|
"/type_given"=>{
|
|
|
|
"post"=>{
|
|
|
|
"produces"=>["application/json"],
|
|
|
|
"parameters"=>[
|
|
|
|
{"in"=>"formData", "name"=>"typed_group[][id]", "description"=>"integer given", "type"=>"integer", "required"=>true, "allowMultiple"=>true, "format"=>"int32"},
|
|
|
|
{"in"=>"formData", "name"=>"typed_group[][name]", "description"=>"string given", "type"=>"string", "required"=>true, "allowMultiple"=>true},
|
|
|
|
{"in"=>"formData", "name"=>"typed_group[][email]", "description"=>"email given", "type"=>"string", "required"=>false, "allowMultiple"=>true},
|
2016-03-09 23:37:03 +08:00
|
|
|
{"in"=>"formData", "name"=>"typed_group[][others]", "description"=>nil, "type"=>"integer", "required"=>false, "allowMultiple"=>true, "format"=>"int32", "enum"=>[1, 2, 3]}],
|
|
|
|
"tags"=>["type_given"],
|
2016-03-16 00:53:03 +08:00
|
|
|
"operationId"=>"postTypeGiven",
|
2016-03-09 23:37:03 +08:00
|
|
|
"responses"=>{"201"=>{"description"=>"created TypeGiven"}}}}}})
|
2015-12-19 01:40:53 +08:00
|
|
|
end
|
|
|
|
end
|
2015-11-04 20:03:42 +08:00
|
|
|
end
|