dstotijn/yii2-json-schema-validator

A Yii2 extension that provides a validator class for JSON Schema validation.

Installs: 13 596

Dependents: 0

Suggesters: 0

Security: 0

Stars: 16

Watchers: 0

Forks: 7

Open Issues: 1

Type:yii2-extension

1.0.0 2016-07-13 13:43 UTC

This package is not auto-updated.

Last update: 2021-01-22 22:23:18 UTC


README

Build Status Code Coverage

A Yii 2 extension that provides a validation class that wraps JSON Schema for PHP.

Installation

$ composer require dstotijn/yii2-json-schema-validator

Usage

Model class example:

<?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.

Please view public properties in class JsonSchemaValidator to get info about all available options.