1

I am working with apipie for my rails app API and have a parameter that needs to be conditionally required. If a user is hired, they need to have a hired_at date. For other reasons those must be 2 separate columns. I cannot just check for the presence of a hired_at date...

What I currently have is essentially the following:

param   :person,   Hash,  desc: "person information", required: true do
  param :name,     String, desc: "person name", required: true
  param :hired,    [true, false], desc: "person has been hired", required: true
  param :dates,    Array, of: Hash, desc: "important dates", required: true do
    param :hired_at,   String, desc: "date of fire", required: <if hired == true >
  end    
end

the <if hired==true> is pseudocode. That is the logic I need there but I don't know how to implement it.

duncan
  • 31,401
  • 13
  • 78
  • 99
Zack
  • 2,377
  • 4
  • 25
  • 51
  • It's not clear that Apipie supports this directly (fyi, [Grape does](https://github.com/ruby-grape/grape#dependent-parameters)). I think your best bet is probably a custom validator. – Robert Nubel Sep 09 '16 at 19:14
  • just to be clear, you're talking about documentation only, or the rails functionality? – max pleaner Sep 10 '16 at 00:00

0 Answers0