list of dicts
hi, I have not found a way to have a list of dicts and validate it.
this is the config
cars:
- manufacturer: volvo
color: red
modell: typec
- manufacturer: toyota
color: blue
modell: typeb
- manufacturer: volvo
color: green
modell: typea
example of not working validation:
cars: [
{
"manufacturer": confuse.String(default=""),
"color": confuse.String(default=""),
"modell": confuse.String(default="")
}
]
}
in the end i just validated it by:
cars: list
but when i run config.dump() i get back the config in yaml but the list as an json/dict
something: value
something2: value
cars: [{"manufacturer":"volvo","color":"red","modell":"typec"},{"manufacturer":"toyota","color":"blue","modell":"typeb"},{"manufacturer":"volvo","color":"green","modell":"typea"}]
It's true; I don't think we currently have a template like that. But Confuse is extendable, so you might take inspiration from the current templates to write something like that! See MappingTemplate for inspiration: https://github.com/sampsyo/confuse/blob/f6e0981ddee1828f59734f4ccca11b5cc17ecbec/confuse.py#L1159-L1183
It's true; I don't think we currently have a template like that. But Confuse is extendable, so you might take inspiration from the current templates to write something like that! See MappingTemplate for inspiration:
Hi!
I was having this exact issue, so I've implemented a template to represent a list of similar items. Basically it takes a list as the input and uses the first item on the list as a template to validate against. I don't know, though, how to integrate it into the as_template function. If I understand correctly, right now lists in a template describe OneOf behaviour. It seems logical to me that a list should represent a list but I'm worried that if I simply change the existing functionality, something may break.