NimbleOptions and the :one_of operator

I was hoping to use the NimbleOptions hex to validate a data structure. A human could author the data structure in a text editor and NimbleOptions would validate it, providing errors on how to bring the structure into compliance.

The data structure, among other elements, has a “one of” element, where the element can be one of many forms. In the lingo of NimbleOptions, the “one of” field would be one of several possible :non_empty_keyword_lists.

Is there a way to achieve this with NimbleOptions? What forms can choices take in the `:one_of`` tuple?

Something like:

type: {:one_of, [option_a: ...], [option_b: ....], [option_c: ....]}

2 Likes

To provide an answer… the arguments to one_of can be any literal.

The choices shown in the NimbleOptions documentation is a list and one_of is true if choices includes the value found in the actual options.

1 Like