Conditionally Run Schema Based on Property Value

Hello, I will like to conditionally run a schema based on a property

I have

const FilledSchema = Schema.Struct({
  name: Schema.NonEmptyString,
  email: Schema.NonEmptyString,
})

const FormSchema = Schema.Struct({
  name: Schema.String,
  email: Schema.String,
  canBeBlank: Schema.Boolean
})


When decoding using FormSchema, I want to check canBeBlank.
And conditonally run FilledSchema when canBeBlank==false.

e.g.
Schema.decodeUnknownEither(FormSchema)({name: "", email: "", canBeBlank: true}) 
is valid

Schema.decodeUnknownEither(FormSchema)({name: "", email: "", canBeBlank: false}) 
is invalid


Ideas? Thanks
Was this page helpful?