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

KeywordStatusNotes
typeSupportedstring, integer/int, number, boolean/bool, array, object, null
requiredSupported
propertiesSupportedNested validation
additionalPropertiesSupportedBoolean or schema
itemsSupportedArray item validation
minItems / maxItemsSupported
uniqueItemsSupported
minLength / maxLengthSupported
patternSupportedRegex patterns
minimum / maximumSupportedInclusive bounds
exclusiveMinimum / exclusiveMaximumSupportedExclusive bounds
enumSupported
constSupported
allOf / anyOf / oneOfSupportedComposition
notSupported
minProperties / maxPropertiesSupported
formatPartialSee supported formats below

Supported format values

FormatDescription
emailEmail address (RFC 5322 subset)
uriURI with scheme
urlHTTP/HTTPS URL
uuidUUID (any version, case-insensitive)
ipv4IPv4 address
ipv6IPv6 address
date-timeISO 8601 date-time (requires timezone)
dateISO 8601 date (YYYY-MM-DD)
timeISO 8601 time (HH:MM:SS)

Unknown format values are silently ignored (not validated).

Intentionally unsupported

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.