1

My delete api takes a boolean query params /users?force=true. In my controller, I added the following for apipie documentation

param :force, [true, false], required: false, desc: "query parameter."

When I make the api call, I get

Apipie::ParamInvalid (Invalid parameter 'force' value "true": Must be one of: <code>true</code>, <code>false</code>.).

I tried passing /users?force=1, /users?force, but 1 is treated as "1" and not passing anything is treated as nil and both calls fail. How do I make the validation pass?

Note: I am aware that the api definition is not restful.

learningtocode
  • 755
  • 2
  • 13
  • 27

1 Answers1

1

The param you are passing through ends up being "true" as in string, not a boolean, that's why it's failing. Without any type casting, rails has got no idea that you're trying to pass boolean, not a string.

You should whitelist "true", "false" as strings in valid options like:

param :force, [true, false, "true", "false"], required: false, desc: "query parameter."
TomD
  • 781
  • 4
  • 17
  • Oh ok, so I could as well remove true, false and just pass in "true", "false" as theres no way to pass in boolean, correct? – learningtocode Aug 15 '17 at 17:11
  • @learningtocode - not through url params, no, although I think it's still possible to set param to boolean true elsewhere so I'd still leave it in – TomD Aug 16 '17 at 12:25