在我的 Grape 端点中,我有一个名为 user_type
的必需参数。另一方面,我的公共(public) API 将此参数声明为 userType
,即驼峰式大小写。有办法改变这个吗?
module MyAPI
module V1
class SignUp < Grape::API
desc 'Create new user account'
params do
requires :email, type: String
requires :password, type: String
requires :user_type, type: String
end
post :sign_up do
{}
end
end
end
end
最佳答案
这有点难看,但它可以解决问题,因此您可以将它放入方法中。
def sym_to_lower_camel(sym)
sym.to_s.split('_').map{|x| x.capitalize}.join.sub(/^./, sym.to_s[0].downcase)
end
关于ruby - 如何在 Grape 参数中将 camelcase 更改为 snakecase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35436822/