Convenient API Schema Validation and Error Tracking
What's the most convenient way to have an API return a schema and then further validate such schema and keep track of errors?
For example, I have an API that brings me back an object with a bunch of properties typed as string. I then need to check if some of those properties pass a certain branded type validation. If such, I then need to insert those at db (which only accept such branded types) and if false I need to log the ones that haven't passed the validation.
I know how to code such a thing. I don't know what's the most conveniente way to accomplish this, given that it's a little bit cumbersome to work with a "refinement".
Let's say I have a couple of properties that need to be refined I thought of the following alternatives:
- define a refinement that check those two properties
- define a schema and then compose the one coming from the API to the one I need
Either ways I have some cumbersome things to do:
- if I go for the refinement, and maybe use that with
- if I go for the schema compose, I need to create a schema that's only slighlty different than an existing one, somehow refined, How?
For example, I have an API that brings me back an object with a bunch of properties typed as string. I then need to check if some of those properties pass a certain branded type validation. If such, I then need to insert those at db (which only accept such branded types) and if false I need to log the ones that haven't passed the validation.
I know how to code such a thing. I don't know what's the most conveniente way to accomplish this, given that it's a little bit cumbersome to work with a "refinement".
Let's say I have a couple of properties that need to be refined I thought of the following alternatives:
- define a refinement that check those two properties
- define a schema and then compose the one coming from the API to the one I need
Either ways I have some cumbersome things to do:
- if I go for the refinement, and maybe use that with
Array.partition I get typing hell, since the input type is unknown, then I need to create a propertly typed refinement, which can't conveniently be typed fromwhat I write, but I need to pay attention to what type I write.- if I go for the schema compose, I need to create a schema that's only slighlty different than an existing one, somehow refined, How?
