Search documentation of bb

# BB.Parameter.Schema (bb v0.8.0)

View Source

Builds nested Spark.Options schemas from flat parameter definitions.

This module converts the flat `[{path, opts}]` format from `__bb_parameter_schema__/0` into nested keyword lists suitable for validating `start_link` options.

## Example

    iex> flat = [
    ...>   {[:motion, :max_speed], [type: :float, default: 1.0]},
    ...>   {[:motion, :acceleration], [type: :float, default: 0.5]},
    ...>   {[:debug_mode], [type: :boolean, default: false]}
    ...> ]
    iex> BB.Parameter.Schema.build_nested_schema(flat)
    [
      debug_mode: [type: :boolean],
      motion: [type: :keyword_list, keys: [
        acceleration: [type: :float],
        max_speed: [type: :float]
      ]]
    ]

# Summary

## Functions

build_nested_schema(flat_schema)

Builds a nested Spark.Options schema from flat `[{path, opts}]` list.

flatten_params(nested_params)

Flattens nested keyword params to `[{path, value}]` format.

# Functions

# build_nested_schema(flat_schema)

    @spec build_nested_schema([{[atom()], keyword()}]) :: keyword()

Builds a nested Spark.Options schema from flat `[{path, opts}]` list.

The resulting schema can be passed to `Spark.Options.validate/2` to validate nested keyword lists like `[motion: [max_speed: 2.0]]`.

All parameters are optional (no `:required` flag) since we're validating partial overrides. The `:default` key is removed from each parameter's opts since defaults are handled separately by the DSL.

# flatten_params(nested_params)

    @spec flatten_params(keyword()) :: [{[atom()], term()}]

Flattens nested keyword params to `[{path, value}]` format.

This is the inverse of the nesting - it takes validated params like `[motion: [max_speed: 2.0]]` and returns `[{[:motion, :max_speed], 2.0}]`.