cypriss / mutations

Compose your business logic into commands that sanitize and validate input.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validate hash with mixed required attributes

M-Hagras opened this issue · comments

Is there a way to validate nested hash with attributes required and attributes optional ?

params: { a: required, X: { 'Y': required, 'Z': optional }, b: optional }

Something like

required do
    string :a
    hash :x do
      string :y
    end
  end

  optional do
    string :b
    hash :x do
      string :z
    end
   end

thanks

You can use required and optional blocks inside a hash filter:

required do
  string :a

  hash :x do
    required do
      string :y
    end

    optional do
      string :z
    end
  end
end

optional do
  string :b
end