Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Specify that a field can be one of a list of options #163

Description

@eivindjahren

Lets say you have the following kind of specification:

vehicle_list:
  - spaceship:
      name: "Millenium Falcon"
      crew:
         - "Han Solo"
         - "Chewbacca"
  - time_machine:
     name: "The Dolorean"
     inventor: "Doc Brown"
  - spaceship:
     name: "The Enterprise"
     crew:
         - "Jean-Luc Picard"
         - "Data"

It would be nice to have a OneOf combinator to specify that the node matches one of a known list of schemas:

schema = {
    MK.Type: types.NamedDict,
    MK.Content: {
        "vehicles_list": {
            MK.Type: types.List,
            MK.Content: {
                MK.Item: OneOf([
                     {MK.Type: types.NamedDict, Mk.Content: {"spaceship": {}},
                     {MK.Type: types.NamedDict, Mk.Content: {"time_machine": {}},
                ])
            }
        }
    }
}

This would also be handy for specifying that a field can be either a string or a float:

OneOf([{MK.Type: types.Float}, {MK:Type: types.String}])

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions