不幸的是,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 },
title: { type: :string },
created_at: { type: :datetime},
updated_at: { type: :datetime}
}
}
}
}