schema
schema copied to clipboard
Add "Constrained" container schema validator
Hi,
Made this as a POC for one my needs (replace a JSON validator that can handle array/lists with specific number of items and with specific type(s) for the items given their position).
Should work with any "container" type that can be indexed, and taking as in input a generator of the items to be collected.
Thanks to reviewers. I hope this wasn't already doable with some other way ;)
Regards,
Codecov Report
Merging #153 into master will increase coverage by
0.31%. The diff coverage is100%.
@@ Coverage Diff @@
## master #153 +/- ##
==========================================
+ Coverage 97.66% 97.97% +0.31%
==========================================
Files 1 1
Lines 214 247 +33
==========================================
+ Hits 209 242 +33
Misses 5 5
| Impacted Files | Coverage Δ | |
|---|---|---|
| schema.py | 97.97% <100%> (+0.31%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 0dc8499...2a9fa4b. Read the comment docs.
obviously that would require its own doc part in README but I'm waiting to see what reviewers might think over the idea & initial poc implementation (and tests :p)..
Thank you for your contribution! Can you explain a bit more about why this is useful? I'm not getting the exact use case from the code :/
it's to be able to define array (I've in mind list or tuple but any container type accepting an iterable would be suitable) having a well defined structure. maybe the tests should give you a better idea of the feature.. ? but basically it's to be able to restrict the accepted / validated exact structure of container (with some extent possible: additionals with min+max items). maybe the name ConstrainedContainer isn't the best one too.. (I'm not native english).