Apipie 接收整数参数作为字符串 [英] Apipie receiving integer param as String
问题描述
我有以下 RSpec 测试:
I have the following RSpec test:
it 'should not list alerts, since I do not have access to this model' do
get :index, params: { model_id: @model2.id, workspace_id: @workspace.id }, as: :json
expect(response).to have_http_status(:forbidden)
end
并且它失败了,因为 Apipie 抱怨 workspace_id
是一个字符串,而实际上不是,它是一个整数.我调试了调用,检查了 @workspace
和 id
绝对是一个整数.
and it is failing because Apipie is complaining the workspace_id
is a String when it is actually not, it is an Integer. I debugged the call, inspected @workspace
and id
is definitely an Integer.
现在我正在将应用程序迁移到 Rails 5.2.0(以前是 Rails 4),因此我看到了这个问题.
I'm seeing this issue now that I'm migrating the application to Rails 5.2.0 (previously Rails 4).
有人见过这样的吗?
推荐答案
GET
请求不包含正文,而您正在尝试发送一些有效负载.在 GET
请求的情况下,所有参数都作为 url 查询传递(例如 /index?model_id=1&workspace_id=1
)并且所有参数都是字符串.
The GET
request doesn't contains body, while you're trying to send some payload. In the case of GET
request all params passed as url query (e.g. /index?model_id=1&workspace_id=1
) and all params are string.
这里有两个选择:
- 将
GET
改为POST
,这样就允许请求带有正文. - 在动作中将字符串转换为整数.
- Change
GET
toPOST
, it will allow request with body. - Convert string to integer in the action.
这篇关于Apipie 接收整数参数作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!