我有以下 rswag 测试:
response '200', 'response with array of objects' do
schema type: :array,
items: {
type: :object,
properties: {
expected_id: { type: "integer", format: "int32" },
}
}
run_test!
end
我的 API 使用 JSON 响应:
[
"invalid_key": 1,
"invalid_key": 2
]
换句话说,根据上述模式的无效响应。
但是,测试并没有失败。这是出乎意料的。
另一方面,如果我的 API 以空值数组响应:"[null]"
我得到我期望的响应:
Failure/Error: test.run
Rswag::Specs::UnexpectedResponse:
Expected response body to match schema: The property '#/0' of type null did not match the following type: object in schema 19e6c168-1da4-58a6-93fc-a33d9d91233a
所以我的测试是检查是否有一个对象数组,但不检查嵌套对象中的属性是否符合预期。我如何让它也检查属性?