如何解决在 Rails 中使用 rswag - 索引响应数组的语法是什么?
不幸的是,rswag 的“文档”似乎非常缺乏,并且没有给出如何实现索引操作的示例。我的“创建”规范在 Swagger UI 中显示架构和示例值,但我的“索引”方法未在 UI 中显示其中任何一个。
我需要在这里更改什么?我已经根据我发现的有限示例尝试了它,但它们似乎都不起作用。
path '/api/v1/users' do
get('list users') do
tags 'Users'
response(200,'successful') do
schema type: :array,properties: {
id: { type: :integer },title: { type: :string },created_at: { type: :datetime},updated_at: { type: :datetime}
}
after do |example|
example.Metadata[:response][:content] = {
'application/json' => {
example: JSON.parse(response.body,symbolize_names: true)
}
}
end
run_test!
end
end
post('create user') do
tags 'Users'
consumes 'application/json'
parameter name: :user,in: :body,schema: {
type: :object,properties: {
title: { type: :string }
},required: [ 'title','description' ]
}
response(200,'successful') do
after do |example|
example.Metadata[:response][:content] = {
'application/json' => {
example: JSON.parse(response.body,symbolize_names: true)
}
}
end
run_test!
end
end
end
根据我发现的另一个示例,我也尝试像这样格式化架构,它也没有做任何事情(架构/示例只是没有显示):-
schema type: :object,properties: {
collection: {
type: :array,items: {
type: :object,properties: {
id: { type: :integer },updated_at: { type: :datetime}
}
}
}
}
解决方法
检查您的 swagger_helper
文件。如果您按照文档进行操作,则可能是这样的:
RSpec.configure do |config|
config.swagger_root = Rails.root.to_s + '/swagger'
config.swagger_docs = {
'v1/swagger.json' => {
openapi: '3.0.1',info: {
title: 'API V1',version: 'v1',description: 'This is the first version of my API'
},servers: [
{
url: 'https://{defaultHost}',variables: {
defaultHost: {
default: 'www.example.com'
}
}
}
]
}
}
end
只需将 opeanapi: '3.0.1'
替换为 swagger: '2.0'
。我遇到了同样的问题,这是我目前找到的唯一解决方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。