Is it possible to validate date from param is less than date to param in Grape API (Ruby)?

209 Views Asked by At

If I have the following params setup in a Grape API endpoint, is there a way to validate that :date_from is less than :date_to?

params do
  requires :date_from, type: Date,
                       description: "The date from in YYYY-MM-DD format",
                       coerce_with: Date.method(:iso8601),
                       allow_blank: false
  requires :date_to, type: Date,
                      description: "The date to in YYYY-MM-DD format",
                      coerce_with: Date.method(:iso8601),
                      allow_blank: false
end

I can probably do something in an after_validation block but curious to see if there is a way to do it using Grape's standard validations, which doesn't seem the case looking at the docs.

0

There are 0 best solutions below