Provides Nette Schema for data validation and normalization. Use when validating configuration, API inputs, or any data structures with Expect class.
View on GitHubnette/claude-code
nette
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/nette/claude-code/blob/main/plugins/nette/skills/nette-schema/SKILL.md -a claude-code --skill nette-schemaInstallation paths:
.claude/skills/nette-schema/## Nette Schema
A library for validating and normalizing data structures against a defined schema.
```shell
composer require nette/schema
```
### 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
Expect::bool() // boolean
Expect::null() // null only
Expect::array() // array, default []
Expect::scalar() // scalar value
Expect::type('ClassName') // instance of class
Expect::type('bool|string') // union types
```
### Arrays
```php
// Array of strings
Expect::arrayOf('string')
Expect::arrayOf(Expect::string())
// Array with string keys
Expect::arrayOf('string', 'string')
// List (indexed array)
Expect::listOf('string')
// Tuple (fixed positions)
Expect::array([
Expect::int(),
Expect::string(),
Expect::bool(),
])
```
### Structures
```php
$schema = Expect::structure([
'database' => Expect::structure([
'host' => Expect::string()->required(),
'port' => Expect::int(3306),
'user' => Expect::string()->required(),
'password' => Expect::string()->nullable(),
]),
'debug' => Expect::bool(false),
]);
```
Properties are optional by default (null). Use `required()` for mandatory fields.
### Enumeration
```php
// One of specific values
Expect::anyOf('small', 'medium', 'large')
// One of values or schemas
Expect::anyOf(
Expect::string(),
Ex