Is it possible to recursively call a schema?


#1

I have a dynamic json object that could be 1…infinite levels deep. Is it possible to recursively call a schema?

[
  {
    value: "1",
    options: [
      {
        value: "1.1",
        options: [
          {
            value: "1.1.1",
            options: [
              {
                value: "1.1.2",
                options: []
              }
            ]
          }
        ]
      }
    ]
  }
]

recursion_schema = Dry::Validation.Schema do
  required(:value).filled(:str?)
  required(:options).maybe { each { schema(recursion_schema) } }
end