Download the PHP package beblife/schema-validation-laravel without Composer
On this page you can find all versions of the php package beblife/schema-validation-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beblife/schema-validation-laravel
More information about beblife/schema-validation-laravel
Files in beblife/schema-validation-laravel
Package schema-validation-laravel
Short Description Validate HTTP-requests using JSON-schema objects
License MIT
Informations about the package schema-validation-laravel
Schema Validation Laravel
Validate HTTP-requests using OpenAPI specification files or JSON-schema objects in Laravel.
Installation
This package can be installed through Composer:
After that can publish the configuration file with this command:
Once published you will have a config/schema-validation.php
file that looks like this:
You can define the spec path as a .env
variable or hardcode the absolute path in the configuration file itself.
The status code when a validation exception is thrown can also be customised here.
Usage
Validating Requests
This package provides a macro on the Illumnite\Http\Request::class
that will validate the request's schema.
When the validateSchema()
method is called the package will search for a matching path defined in the configured OpenAPI specification file and validate the request against the schema.
There are two possible exceptions that can occur when the validation takes place:
UnableToValidateSchema
When a path can't be found in the specification file this exception is thrown.
InvalidSchema
When the request does not match the schema defined in the specification file this exception is thrown.
This exception extends the Laravel ValidationException
which results in a 400 : Bad Request with the following format:
The package also provides a trait that can be added on a form request to validate the schema. Behind the scenes this trait hooks into the prepareForValidation()
method to start validating the request's schema. Afterwards any additional validation defined in the rules()
method will be handled by the Laravel framework.
The schema to use for validation will be resolved automatically from the configured OpenAPI specification file.
This can be overwritten by defining a schema()
on the FormRequest::class
.
Defining Schema's
By default the package will use the schema's defined the configured specification when validating requests.
There is also the option to pass a Beblife\SchemaValidation\Schema::class
to the validateSchema()
method using the provided facade:
From array
From File
From Class
License
The MIT License (MIT). Please see License File for more information.
All versions of schema-validation-laravel with dependencies
guzzlehttp/psr7 Version ^1.8 || ^2.0
league/openapi-psr7-validator Version ^0.18
spatie/laravel-package-tools Version ^1.11