Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Constrained" container schema validator #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gst
Copy link

@gst gst commented Jun 10, 2018

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,

@gst gst force-pushed the add_constrained_container_schema branch 2 times, most recently from 37ee730 to 6508db4 Compare June 10, 2018 20:14
@codecov-io
Copy link

codecov-io commented Jun 10, 2018

Codecov Report

Merging #153 into master will increase coverage by 0.31%.
The diff coverage is 100%.

Impacted file tree graph

@@            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%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0dc8499...2a9fa4b. Read the comment docs.

@gst gst force-pushed the add_constrained_container_schema branch from 6508db4 to 2a9fa4b Compare June 10, 2018 20:24
@gst
Copy link
Author

gst commented Jun 11, 2018

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)..

@skorokithakis
Copy link
Collaborator

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 :/

@gst
Copy link
Author

gst commented Jun 19, 2018

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants