我有一个与邮递员一起工作的Rails api。我正在使用swagger gem编写文档,并且在http://localhost:3000/api-docs/index.html
中使用ui进行测试时,尝试创建项目时,控制器未收到任何参数。
这是适用于邮递员的json
{
"title": "my projects",
"users": [{"name": "john Done", "email": "johndoe@gmail.com"}, {"name": "jane doe", "email": "janedoe@gmail.com"}],
"created_at": "2015-07-10 12:30:57.174282"
}
这是为我的ProjectController定义定义规范的方式
require 'swagger_helper'
describe 'Projects API' do
path '/api/v1/projects' do
post 'Create a project' do
tags 'Project'
consumes 'application/json'
parameter title: :project, in: :body, schema: {
type: :object,
properties: {
title: { type: :string },
users: {type: :array, items: {type: :string}},
created_at: { type: :string }
},
required: [ 'title', 'created_at', 'admins']
}
response '200', 'Project created' do
let(:project) { { project_id: '2'} }
run_test!
end
response '422', 'Invalid request' do
let(:project) { { status: 'ERROR' } }
run_test!
end
response '401', 'Unauthorized' do
let(:project) { { status: "ERROR"} }
run_test!
end
end
end
end
然后在http://localhost:3000/api-docs/index.html
中尝试下一个json
{
"title": "my projects",
"users": ["{"name": "john Done", "email": "johndoe@gmail.com"}", "{"name": "jane doe", "email": "janedoe@gmail.com"}"],
"created_at": "2015-07-10 12:30:57.174282"
}
我总是得到Error: Unprocessable Entity
,因为ProjectController根本不接受任何参数。
发生了什么事?