23andMe / Yamale

A schema and validator for YAML.
MIT License
680 stars 89 forks source link

Typo in lists example in README #90

Closed ImmanuelHaffner closed 4 years ago

ImmanuelHaffner commented 4 years ago

In the README example on lists, the schema has

question:
  choices: list(include('choices'))
  questions: list(include('question'), required=False)

and the example data has

questions:
  - choices:
      - id: 'id_str'
      - id: 'id_str1'
    questions:
      - choices:
        - id: 'id_str'
        - id: 'id_str1'

I'm not very familiar with YAML syntax, but i think there is a typo (singular vs plural). Either question: in the schema should be questions: or the outer questions: in the data should be question:.

mildebrandt commented 4 years ago

Hi, thanks for your interest in Yamale.

Here's the full data file we want to validate:

list_with_two_types:
  - 'some'
  - rsid: 'rs123'
    name: 'some SNP'
  - 'thing'
  - rsid: 'rs312'
    name: 'another SNP'
questions:
  - choices:
      - id: 'id_str'
      - id: 'id_str1'
    questions:
      - choices:
        - id: 'id_str'
        - id: 'id_str1'

Let's take a look at the referenced schema in parts. At the top, we have:

list_with_two_types: list(str(), include('variant'))
questions: list(include('question'))

The list_with_two_types and questions match the two top level attributes in the data. Great! We see that the attribute questions is a list of question type. I think that's where the confusion is. The questions attribute has a type of question.

Just to continue, we look later in the schema for that type:

question:
  choices: list(include('choices'))
  questions: list(include('question'), required=False)

Here we see that each element in the list is a map made up of choices and questions. Looking at the data, that's exactly what we have.

Let me know if you have any other questions.

ImmanuelHaffner commented 4 years ago

Oh cool, thanks for the fast response. Makes perfectly sense now.

And great tool, keep up the good work 😁