我正在使用rswag测试一个相当常见的 RubyOnRails JSON Api应用程序,但我无法弄清楚我将文件上传到端点的一个相当常见的情况。
端点期望data
请求正文中的常用属性具有file
包含二进制文件的属性,并且我无法使 rswag 生成具有正确参数的请求。
path '/documents' do
post 'Creates a document' do
tags 'Documents'
consumes 'multipart/form-data'
produces 'application/vnd.api+json'
parameter name: 'data',
description: 'Whatever',
attributes: {
schema: {
type: :object,
properties: {
file: { type: :binary },
},
},
}
response '201', 'success' do
let(:data) do
{
attributes: {
file: Rack::Test::UploadedFile.new($REALARGS),
},
}
end
schema "$ref": '#/definitions/post_document_responses/201'
run_test! do |_example|
# ACTUAL TEST
end
end
end
end
还有一些其他更简单的参数(例如授权)是正确生成的,我确定rswag
它被正确地钩住了。我看到的请求没有参数,我可以删除data
参数并且没有任何变化。我已经尝试了一百万种组合,总是相同的结果,我不知道发生了什么。
params
控制器期望的是data[attributes][file]
.
谁能帮我?