Schema Validation
Overview
The library includes a built-in JSON Schema subset validator for validating handler parameters. It is optional — normal parameter binding works without it.
Enabling schema validation
'validation' => [
'strict' => true,
'schema' => ['enabled' => true],
],
Defining schemas on handlers
Implement RpcSchemaProviderInterface:
use Lumen\JsonRpc\Validation\RpcSchemaProviderInterface;
final class Product implements RpcSchemaProviderInterface
{
public static function rpcValidationSchemas(): array
{
return [
'create' => [
'type' => 'object',
'required' => ['name', 'price'],
'properties' => [
'name' => ['type' => 'string', 'minLength' => 1],
'price' => ['type' => 'number'],
],
'additionalProperties' => false,
],
];
}
}
Supported JSON Schema keywords
| Keyword | Status | Notes |
|---|---|---|
type | Supported | string, integer/int, number, boolean/bool, array, object, null |
required | Supported | |
properties | Supported | Nested validation |
additionalProperties | Supported | Boolean or schema |
items | Supported | Array item validation |
minItems / maxItems | Supported | |
uniqueItems | Supported | |
minLength / maxLength | Supported | |
pattern | Supported | Regex patterns |
minimum / maximum | Supported | Inclusive bounds |
exclusiveMinimum / exclusiveMaximum | Supported | Exclusive bounds |
enum | Supported | |
const | Supported | |
allOf / anyOf / oneOf | Supported | Composition |
not | Supported | |
minProperties / maxProperties | Supported | |
format | Partial | See supported formats below |
Supported format values
| Format | Description |
|---|---|
email | Email address (RFC 5322 subset) |
uri | URI with scheme |
url | HTTP/HTTPS URL |
uuid | UUID (any version, case-insensitive) |
ipv4 | IPv4 address |
ipv6 | IPv6 address |
date-time | ISO 8601 date-time (requires timezone) |
date | ISO 8601 date (YYYY-MM-DD) |
time | ISO 8601 time (HH:MM:SS) |
Unknown format values are silently ignored (not validated).
Intentionally unsupported
$ref— schema referencesif/then/else— conditional schemasdependencies/dependentSchemasprefixItems/tuple validationcontentEncoding/contentMediaType- Numeric
multipleOf patternPropertiesformatvalues beyond the list above
These are omitted to keep the validator simple, deterministic, and suitable for runtime parameter validation without external dependencies.
Max depth protection
Nested schema validation is capped at 32 levels to prevent stack overflow from deeply nested schemas.