Yii 2 JSON Schema Validator
, (*1)
A Yii 2 extension that provides a validation class that wraps
JSON Schema for PHP., (*2)
Installation
$ composer require dstotijn/yii2-json-schema-validator
Usage
Model class example:, (*3)
<?php
namespace app\models;
use dstotijn\yii2jsv\JsonSchemaValidator;
use Yii;
use yii\base\Model;
class YourCustomModel extends Model
{
public $json;
public function rules()
{
return [
[
'json',
JsonSchemaValidator::className(),
'schema' => 'file://' . Yii::getAlias('@app/path/to/schema.json'),
/* or URL
'schema' => 'https://example.com/path/to/schema.json',
*/
],
];
}
}
See json-schema for details how to describe JSON schema., (*4)
Please view public properties in class
JsonSchemaValidator
to get info about all available options., (*5)