romaricdrigon / MetaYaml

A powerful schema validator!
MIT License
104 stars 21 forks source link

Validating a mixed type array #18

Closed AppSynergy closed 6 years ago

AppSynergy commented 6 years ago

Hello! I'm trying to write a partial to fit some of my data.

I've got things like, which handles e.g. ['foo', 'bar']

list_of_texts:
        _type: prototype
        _required: true
        _prototype:
            _type: text

Or for [['foo', 'baz'], ['der', 'dum']]

list_of_list_of_texts:
        _type: prototype
        _required: true
        _prototype:
            _type: prototype
            _required: true
            _prototype:
                _type: text

But I'm stuck on: ['foo', ['bing', 'bong']]

Can I put a _choice inside a prototype somehow?

AppSynergy commented 6 years ago

Gave myself the idea there, think I've nailed it:

list_of_mixed_lists:
        _type: prototype
        _required: true
        _prototype:
            _type: choice
            _choices:
                1:
                    _type: text
                2:
                    _type: partial
                    _partial: list_of_texts