# `Spark.Options.Validator`
[🔗](https://github.com/ash-project/spark/blob/v2.7.0/lib/spark/options/validator.ex#L5)

Defines a validator module for an option schema.

Validators create structs with keys for each option in their schema,
and an optimized `validate`, and `validate!` function on that struct.

## Upgrading from options lists

You can pass the option `define_deprecated_access?: true` to `use Spark.Options.Validator`,
which will make it such that `options[:foo]` will still work, but will emit a deprecation warning.
This cane help with smoother upgrades.

## Example

Given a module like the following:

```elixir
defmodule MyOptions do
  use Spark.Options.Validator, schema: [
    foo: [
      type: :string,
      required: true
    ],
    bar: [
      type: :string
    ],
    baz: [
      type: :integer,
      default: 10
    ]
  ]
end
```

You can use it like so:

```elixir
@doc """
Does a thing

## Options

#{MyOptions.docs()}
"""
@doc spark_opts: [{1, MyOptions.schema()}]
def your_function(arg, opts \\ []) do
  options = MyOptions.validate!(opts)

  options.foo
  options.bar
end
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
