soyuka/json-schema-bundle
A Symfony bundle for JSON Schema integration, helping you generate schemas and validate JSON payloads through Symfony services. Useful for keeping API requests and responses consistent, catching invalid data early, and simplifying schema-driven validation in your application.
composer require soyuka/json-schema-bundle plus justinrainbow/json-schema if it isn't pulled transitively. This is a Symfony2-era bundle, so expect it to target Symfony 2.x constraints.app/AppKernel.php inside registerBundles() (new Soyuka\JsonSchemaBundle\JsonSchemaBundle() — verify the exact FQCN in the repo's JsonSchemaBundle.php).DependencyInjection/ extension and Resources/config/services.yml/.xml. That's where the service id and any config keys (json_schema: ...) are defined. The bundle is thin, so the whole surface is a handful of files — read them before assuming a feature exists.$validator = $this->get('json_schema.validator'); // confirm the id in services.yml
$schema = (object) ['$ref' => 'file://'.__DIR__.'/../Resources/schemas/user.json'];
$data = json_decode($request->getContent());
$validator->validate($data, $schema);
if ($validator->isValid()) {
// proceed
}
foreach ($validator->getErrors() as $error) {
// $error->getPropertyPath(), $error->getMessage(), $error->getConstraint()
}
If the bundle only registers the underlying JsonSchema\Validator, treat it as a DI convenience wrapper rather than a full validation framework.
SchemaRepository service that maps logical names (user.create) to absolute schema paths/URIs. Keeps $ref wiring out of controllers.Validator constraint, or a form/API layer — not deep in domain services. Return 400 with a normalized error list on failure.$ref resolution is I/O-heavy. Load schemas once into a JsonSchema\Uri\UriRetriever / SchemaStorage (depending on the justinrainbow version) and reuse the validator instead of re-reading files per request.ValidationError objects to {property, message, constraint} arrays once, in a service, so API responses and logs stay consistent.justinrainbow/json-schema directly (note it is itself archived/unmaintained) or a maintained alternative like opis/json-schema.$ref resolution: relative refs are the classic footgun. Use absolute file:// or http:// URIs, or set a base URI on the retriever. $ref to a schema with its own relative $refs needs an explicit base.validate() vs check(), isValid() vs getErrors() semantics, ValidationError accessors). Pin the version and confirm method names against the installed release.getErrors() returns objects; forgetting getPropertyPath() makes messages unactionable for clients.services.yml for the real id rather than guessing; missing ids fail at container compile time with a clear message.load() for defaults — silent no-ops are common when keys aren't declared under the bundle's root.DecoratorServicePass) to add metrics/logging, and wrap the URI retriever if you need to resolve schemas from a DB, S3, or bundle resources. Read the underlying justinrainbow classes — the bundle adds little, so the real documentation is upstream.$validator->getErrors() and the resolved schema URI first; 90% of failures are bad $refs or a schema loaded as an array instead of an object ((object) cast matters for properties).How can I help you explore Laravel packages today?