describe 'Blogs API' do
path '/blogs' do
post 'Creates a blog' do
response 422, 'invalid request' do
**schema** '$ref' => '#/definitions/errors_object'
...
end
上面代码中的关键字模式对我们有什么好处?真实的反应与此相比吗?如果不匹配,引发错误?
describe 'Blogs API' do
path '/blogs' do
post 'Creates a blog' do
response 422, 'invalid request' do
**schema** '$ref' => '#/definitions/errors_object'
...
end
上面代码中的关键字模式对我们有什么好处?真实的反应与此相比吗?如果不匹配,引发错误?
是的,rswag 将验证您的 API 响应是否与您在运行测试时指定的架构相匹配。它还将模式输出为生成的 swagger 文档中的“模型”。
在您给出的示例中,它将errors_object
在您的config.swagger_docs
. rswag 文档向您展示了如何定义它:
config.swagger_docs = {
'v1/swagger.json' => {
swagger: '2.0',
info: {
title: 'API V1'
},
definitions: {
errors_object: {
type: 'object',
properties: {
errors: { '$ref' => '#/definitions/errors_map' }
}
},
errors_map: {
type: 'object',
additionalProperties: {
type: 'array',
items: { type: 'string' }
}
}
}
}
}