【发布时间】:2020-05-20 11:46:52
【问题描述】:
我正在使用 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]。
谁能帮帮我?
【问题讨论】:
标签: ruby-on-rails rspec json-api rswag