OzMcp.Structs.EnumOptions (OzMcp v0.9.0)

Copy Markdown View Source

Helper module shared by OzMcp.Structs.EnumSchema and OzMcp.Structs.MultiSelectEnumSchema.

An option is a string ("red"), a {value, title} tuple, or a map with the keys :const / "const" and :title / "title". A list where no option has a title is rendered as enum; as soon as one option has a title, the list is rendered as {const, title} pairs (a missing title defaults to the value).

Summary

Functions

Normalizes the options to a list of {value, title | nil}. Raises ArgumentError when the list is empty, an option is invalid, or a value is repeated.

Renders normalized options: {:enum, values} or {:titled, [%{const:, title:}]}.

The values of normalized options.

Types

option()

@type option() :: String.t() | {String.t(), String.t()} | map()

Functions

normalize(options)

@spec normalize(term()) :: [{String.t(), String.t() | nil}]

Normalizes the options to a list of {value, title | nil}. Raises ArgumentError when the list is empty, an option is invalid, or a value is repeated.

render(options)

@spec render([{String.t(), String.t() | nil}]) ::
  {:enum, [String.t()]} | {:titled, [map()]}

Renders normalized options: {:enum, values} or {:titled, [%{const:, title:}]}.

values(options)

@spec values([{String.t(), String.t() | nil}]) :: [String.t()]

The values of normalized options.