nette-schemalisted
Install: claude install-skill nette/agent-plugins
## Nette Schema
A library for validating and normalizing data structures against a defined schema. Declare what correct data looks like, and Schema verifies and transforms input in one step.
```shell
composer require nette/schema
```
### When to Use Schema
- **Configuration validation** – validate config arrays loaded from .neon files
- **API input validation** – validate request data before processing
- **Data import/transform** – normalize external data into typed structures
- **DI extension config** – validate extension configuration in `loadConfiguration()`
Schema is complementary to Nette Forms (which handles user input with UI) and database constraints (which enforce storage-level rules). Use Schema for programmatic data validation where there's no form UI.
### Basic Usage
```php
use Nette\Schema\Expect;
use Nette\Schema\Processor;
$schema = Expect::structure([
'name' => Expect::string()->required(),
'email' => Expect::email(),
'age' => Expect::int()->min(0)->max(120),
]);
$processor = new Processor;
try {
$normalized = $processor->process($schema, $data);
// $normalized is stdClass with validated data
} catch (Nette\Schema\ValidationException $e) {
echo 'Invalid: ' . $e->getMessage();
// $e->getMessages() returns array of all errors
}
```
### Data Types
```php
Expect::string() // string, default null
Expect::string('default') // string with default value
Expect::int() // integer
Expect::float() // float