magp / yii2-json-schema-validator
一个为JSON Schema验证提供验证器类的Yii2扩展。
dev-master
2019-07-01 09:21 UTC
Requires
- swaggest/json-schema: *
- yiisoft/yii2: 2.*
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-29 05:22:00 UTC
README
一个提供封装JSON Schema for PHP验证类的Yii 2扩展。
安装
$ composer require magp/yii2-json-schema-validator
用法
模型类示例
<?php namespace app\models; use magp\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', */ ], ]; } }
有关如何描述JSON schema的详细信息,请参阅 json-schema。