Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to require an Array param, which have string or null elements #1316

Closed
chicaco opened this issue Mar 11, 2016 · 2 comments
Closed

How to require an Array param, which have string or null elements #1316

chicaco opened this issue Mar 11, 2016 · 2 comments
Labels

Comments

@chicaco
Copy link

chicaco commented Mar 11, 2016

I have a validation like so:
requires :names, type: Array[String]

and I also want to accept a null element.
e.g. [null], [null, "name"]

but would not work.
requires :names, type: Array[String]
and
requires :names, type: Array[String], coerce_with: ->(val) { val.compact if val.is_a?(Array) }

How can I accept array including String and null?

@chicaco chicaco changed the title How to require an Array param, which have string or elements How to require an Array param, which have string or null elements Mar 11, 2016
@dblock
Copy link
Member

dblock commented Mar 12, 2016

It's a good question.

For a POST request with a type that clearly delineates nil vs. an empty value vs. something else, like JSON, I think you can "just do it".

For a GET request I don't think you can because there's no way to distinguish nil and an empty string in a query. How would you make an HTTP request with an array containing nils in, say, curl?

@dblock
Copy link
Member

dblock commented Mar 12, 2016

I'll close this, you should bring it up on the mailing list, http://groups.google.com/group/ruby-grape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants