## AttributeTemplateValidator


Transient validator for a raw attribute definition supplied via the builder API.


Usage

``` python
AttributeTemplateValidator()
```


This model is used **only** during builder operations to validate and coerce the dict-style attribute definitions that users pass to [add_properties()](ResourceTemplateBuilder.md#recap.ResourceTemplateBuilder.add_properties) and similar methods before they are written to the database. It is not persisted.

Example input accepted by [add_properties()](ResourceTemplateBuilder.md#recap.ResourceTemplateBuilder.add_properties)::

    {"name": "volume", "type": "float", "default": 10.0, "unit": "uL",
     "metadata": {"min": 0, "max": 20.0}}

Attributes: name: Attribute name (may contain spaces). type: One of the `TypeName` literals. unit: Physical unit string. Defaults to an empty string. default: Default value, coerced to the Python type for *type* by [coerce_default()](AttributeTemplateValidator.md#recap.AttributeTemplateValidator.coerce_default). metadata: Optional validation hints (`min`, `max`, `choices`).


## Methods

| Name | Description |
|----|----|
| [coerce_default()](#coerce_default) | Coerce *default* to the Python type declared by *type*. |
| [enforce_enum_choices()](#enforce_enum_choices) | Ensure `enum` attributes declare choices and that *default* is valid. |

------------------------------------------------------------------------


#### coerce_default()


Coerce *default* to the Python type declared by *type*.


Usage

``` python
coerce_default(v, info)
```


Looks up a converter function for the declared type and applies it to *v*. For `enum` types the result is additionally cast to `str`.

## Raises

`ValueError`  
If `type` is not yet resolved, is unsupported, or if *v* cannot be coerced.


------------------------------------------------------------------------


#### enforce_enum_choices()


Ensure `enum` attributes declare choices and that *default* is valid.


Usage

``` python
enforce_enum_choices()
```


## Raises

`ValueError`  
If `type` is `"enum"` and `metadata.choices` is absent, empty, or does not contain the declared *default*.
