nette-schema
БесплатноБез исполняемых скриптовНе проверенProvides Nette Schema for data validation and normalization. Use when validating configuration, API inputs, or any data structures with Expect class. Covers…
Об этом скилле
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.
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
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
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
// Array of strings
Expect::arrayOf('string')
Expect::arrayOf(Expect::string())
// Array with string keys
Expect::arrayOf('string', 'string')
// List (indexed array)
Expect::listOf('string')
Expect::listOf('email', wrap: true) // since 1.4: a single value becomes a one-item list
// Tuple (fixed positions, since 1.4); Expect::array([...]) is a structure-like array with keys
Expect::tuple([
Expect::int(),
Expect::string(),
Expect::bool(),
])
On the 1.x line '?int[]' means an array of nullable ints; 2.0 reads it as phpDoc does (a
nullable array). Write Expect::arrayOf(Expect::int()->nullable()), which means the same in both.
Structures
$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
// One of specific values
Expect::anyOf('small', 'medium', 'large')
// One of values or schemas
Expect::anyOf(
Expect::string(),
Expect::int(),
null
)
// First is default
Expect::anyOf('small', 'medium', 'large')->firstIsDefault()
// Backed enum (since 1.4): accepts the value or the case, always gives the case
Expect::enum(Mode::class)->default(Mode::Production)
Expect::type(Mode::class) is different: like any class name, it accepts only the case itself.
Constraints
// Required field
Expect::string()->required()
// Nullable (accepts null)
Expect::string()->nullable()
// Default value
Expect::string()->default('hello')
Expect::string('hello') // shorthand
// Length/count limits
Expect::string()->min(3)->max(100)
Expect::array()->min(1)->max(10)
// Numeric range
Expect::int()->min(0)->max(100)
// Pattern
Expect::string()->pattern('\d{5}') // regex for entire value
// Description, also exported to JSON Schema (since 1.4)
Expect::int(3306)->description('Port the server listens on')
Since 1.4 pattern() on a number or an array, and min()/max() on a union such as
Expect::type('int|string'), raise E_USER_DEPRECATED; put the limits on each anyOf() variant.
Assertions
// Custom validation
Expect::string()->assert(fn($s) => strlen($s) % 2 === 0, 'Must be even length')
// Built-in validators
Expect::string()->assert('is_file')
Expect::string()->assert('ctype_alpha')
Transformations
// Transform value after validation
Expect::string()->transform(fn($s) => strtoupper($s))
// Chain transformations
Expect::string()
->assert('ctype_lower', 'Must be lowercase')
->transform(fn($s) => strtoupper($s))
// Transform with validation
Expect::string()->transform(function ($s, $context) {
if (!ctype_alpha($s)) {
// $code is REQUIRED – a single-argument call is an ArgumentCountError
$context->addError('Must be letters only', Nette\Schema\Message::FailedAssertion);
return null;
}
return strtoupper($s);
})
Casting
// Cast to type
Expect::scalar()->castTo('string')
Expect::scalar()->castTo('int')
Expect::scalar()->castTo('bool')
//
Установить nette-schema в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл nette-schema?
Provides Nette Schema for data validation and normalization. Use when validating configuration, API inputs, or any data structures with Expect class. Covers Expect::structure(), Expect::from(), anyOf, enum, tuple, arrayOf, listOf, assert, transform, castTo, otherItems, merging layers (processMultiple, mergeMode), exporting a schema to JSON Schema, and Processor. This is about nette/schema – not Nette Forms validation (addRule), not Nette\Utils\Validators, and not validating against a JSON Schema.
Как установить скилл nette-schema?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл nette-schema запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic