jk icon indicating copy to clipboard operation
jk copied to clipboard

input validation paterns

Open errordeveloper opened this issue 6 years ago • 2 comments

If I read e.g. a JSON file as input, or some -p variables, what is the best way for me to validate what I have and produce meaningful errors to the user? I suppose I can just write it myself and throw exceptions, but it would tedious and I wish I didn't have to write too much code, or if there was a documented patter that I could copy instead of having to invent something.

errordeveloper avatar Dec 20 '19 12:12 errordeveloper

It is Javascript so you could use for instance:

  • superstruct
  • typescript-is
  • yup
  • ajv

brandonkal avatar Jan 07 '20 13:01 brandonkal

I guess to me it's be handy if I could declare parameters with a schema of some sort, and get validation from just calling param.String("foo", "bar", "(bar|foo)").

Another thing that does trip me up right now is that when I read YAML or JSON in TypeScript, I cannot assert it agains a particular type and non-optional fields come out as undefined.

errordeveloper avatar Apr 24 '20 16:04 errordeveloper