Cottonwood-Technology / ValidX

Fast, powerful, and flexible validator with sane syntax.
BSD 2-Clause "Simplified" License
20 stars 4 forks source link

feature request: use different value validators selected by key validators #7

Open jremmet opened 3 years ago

jremmet commented 3 years ago

Usecase: a dict with keys where the name shows which kind of validator should be used to validate it. e.g.

{
    "val_foo": 1
    "val_bar": 2
    "str_foo: "hello"
    "str_bar": "world"
}

To validate this directly something like this would be nice:

Dict(extra=[
    (Str(pattern="val_.*"), Int()),
    (Str(pattern = "str_.*), Str())
])

I didn't find a way to avoid link the key and value validator. Splitting this up via OneOf fails if both kinds of keys are present.

kr41 commented 3 years ago

Good point! However, I would like to implement more general solution.