litmus
litmus copied to clipboard
Recursive Schemas?
Hello, this is a very interesting library. I like that it has the ability to coerce data.
I am wondering though, as I don't see an example of doing so, does it support recursive schemas? Eg. giving a schema as the type for properties?
I think that could make sense for certain types. The only one that comes immediately to mind is Litmus.Type.List
. E.g. if you wanted to validate a list of strings that should be a certain length. Something like:
schema = %{
"passcodes" => %Litmus.Type.List{
max_length: 3,
type: %Litmus.Type.String{
min_length: 3,
max_length: 32
}
}
}
Is that what you have in mind?
Yes, something like that. Personally, I'm not using litmus yet, so no pressure from me, just a feature suggestion.
I think it could also make sense where we have a nested map in params, for example:
{
"id": "psc_12345",
"resource": "postcard",
"to": {
"name": "Customer 1",
"line1": "185 BERRY ST STE 6100",
"city": "SAN FRANCISCO",
"state": "CA",
"zip": "94107",
"country": "UNITED STATES"
},
"from": {
"name": "Customer 2",
"line1": "185 BERRY ST STE 6600",
"city": "SAN FRANCISCO",
"state": "CA",
"zip": "94107",
"country": "UNITED STATES"
}
}
In this case both the to
and from
params could have nested Litmus schemas. Maps and lists might be the only two cases I can think of for which recursive/nested schemas could be useful. I'd like to try implementing this at some point, since it could be a good feature!