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

list of dicts #41

Open
lunne opened this issue Oct 18, 2018 · 2 comments
Open

list of dicts #41

lunne opened this issue Oct 18, 2018 · 2 comments

Comments

@lunne
Copy link

lunne commented Oct 18, 2018

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"}]

@sampsyo
Copy link
Member

sampsyo commented Oct 18, 2018

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

@pupkinsen
Copy link
Contributor

pupkinsen commented Feb 1, 2019

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.

@pupkinsen pupkinsen mentioned this issue Feb 1, 2019
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

No branches or pull requests

3 participants