所以我的 :decimal 格式的 DB 字段作为字符串返回,使我的测试失败。
我有一个使用 RSwag 的请求规范,我试图通过格式检查来通过它,但它告诉我以下内容:-
Rswag::Specs::UnexpectedResponse:
Expected response body to match schema: The property '#/budget' of type string did not match the following type: number in schema
我的测试:-
path '/api/v1/jobs/{id}' do
parameter name: 'id', in: :path, type: :string, description: 'Job id'
get('show job') do
tags 'Jobs'
response(200, 'successful') do
schema type: :object,
properties: {
title: { type: :string },
description: { type: :string },
date: { type: :string, format: 'date-time', nullable: true },
budget: { type: :number, format: 'double' },
awarded: { type: :boolean },
created_at: { type: :datetime},
updated_at: { type: :datetime}
}
let(:id) { @job.id }
after do |example|
example.metadata[:response][:content] = {
'application/json' => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
run_test!
end
end
解决这个问题的最佳方法是什么?如果我必须将所有字段都设为字符串,那么在我的 API 文档中使用 Swagger 有点毫无意义。