- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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
参数并且没有任何变化。我已经尝试了一百万种组合,结果总是一样,但我不知道发生了什么。
Controller 期望的params
是data[attributes][file]
。
谁能帮帮我?
最佳答案
parameter
block 需要指定插入的位置。有一个 example spec在那里我找到了对 :formData
的引用,结果是 必须 被设置(即你不能使用 :body
,它只是发送空请求)。
经过一番尝试后,我设法让您的示例使用表单数据中的嵌套属性:
path '/documents' do
post 'Creates a document' do
tags 'Documents'
consumes 'multipart/form-data'
produces 'application/vnd.api+json'
parameter name: 'data[attributes][file]',
description: 'Whatever',
in: :formData,
attributes: {
schema: {
type: :object,
properties: {
file: { type: :binary },
},
},
}
response '201', 'success' do
let(:"data[attributes][file]") { Rack::Test::UploadedFile.new(Rails.root.join("spec/requests/api/v1/documents_post_spec.rb")) }
end
schema "$ref": '#/definitions/post_document_responses/201'
run_test! do |_example|
# ACTUAL TEST
end
end
end
end
关于ruby-on-rails - 使用 rswag 关注 JSON Api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60060942/
我有一个项目,我在其中嵌套了对象。我试图找出嵌套数组的正确语法。这是我已经厌倦的事情(在许多其他事情中): parameter name: :measurement, in: :body, schem
我有以下 rswag 测试: response '200', 'response with array of objects' do schema type: :array,
我正在使用 rswag测试一个相当常见的 RubyOnRails JSON Api应用程序,但我想不出将文件上传到端点的常见情况。 端点需要请求正文中的常用 data 属性和包含二进制文件的 file
运行 RSpec 时,在 Controller 的 Action 中,(使用 byebug 或 pry) 请求参数中不存在特定值(例如(电子邮件或密码)), 所以测试结果失败了 有关更多详细信息,请参
我将 gem rswag 用于我的 Rails API 文档。我的 Rails API 要求所有请求都包含 headers['Content-Type']='my-fancy-content-type
我没有找到任何关于如何使用 rswag 根据 json api 生成文档的示例。 规范/集成/pets_spec.rb 需要'swagger_helper' 是否可以更改代码以生成json api的格
我正在开发一个 Rails 项目,该项目通过 rswag 和 Rspec 使用 Swagger 进行测试。代码是API,需要通过Rspec系统进行测试。我是 rswag 和 Rspec 的新手。 我的
get 'customer' do security [Token: []] parameter name: :params, in: :body, schema: {
我在使用 Rswag UI gem 测试我的 API 时遇到问题。在 param 字段中输入 token 后,似乎在 UI 中未正确设置授权 header 。尽管如此,当我在终端中运行测试时,测试本身
我在使用 Rswag UI gem 测试我的 API 时遇到问题。在 param 字段中输入 token 后,似乎在 UI 中未正确设置授权 header 。尽管如此,当我在终端中运行测试时,测试本身
我是一名优秀的程序员,十分优秀!