Open avrahamshukron opened 6 years ago
This is included in our fork: https://github.com/beregond/jsonmodels/pull/120
I don't see the problem with your 1st point, since the schema is applied to field_schema["items"]
.
The 2nd point is not a responsibility of the list, if you are using sub-models each model can implement their own validation. Native types (str, int, etc) will probably not be able to be validated by the same validator. In this case you'd need to create a custom validator.
Right now the
ListField
class supports type validation on its elements, and validation agains the list itself (length etc.) But there is no easy way to specify validators that should be applied to every item in the list.For example, I might want a
ListField
ofint
s, where all the items must be in the range[0, 10]
.One might create the following validator:
While this example will work, It has some problems:
ListField
itself, which might cause conflicts.Since the type of each element of the list, and its validators actually creates one schema, I think that this feature should be implemented by the library itself, and not by custom validator.
I have no idea how to implement this cleanly without breaking the current API of
ListField
though...