horat1us / yii2-model-schema
JSON Schema for Yii2 Model using validation rules
1.3.0
2020-07-09 10:05 UTC
Requires
- php: >=7.4
- ext-json: *
- yiisoft/yii2: ^2.0.31
Requires (Dev)
- phpstan/phpstan: ^0.12.32
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.5
README
Create JSON Schema from Yii2 Model using validation rules and other public methods.
Installation
Using composer:
composer require horat1us/yii2-model-schema:^1.0
Usage
base\Model extensions
Additional interfaces that will be used for generating JsonSchema, when they are implemented in model.
AttributesExamples
Will be used to generate property examples
See AttributesExamplesTrait for implementation Since 1.1.0
<?php declare(strict_types=1); namespace App; use Horat1us\Yii\Model; use yii\base; $model = new class extends base\Model implements Model\AttributesExamples { use Model\AttributesExamplesTrait; public function attributesExamples(): array { return [ 'a' => [1,2], 'b' => [], ]; } }; echo $model->getAttributeExamples('a'); // [1,2] echo $model->getAttributeExamples('b'); // null echo $model->getAttributeExamples('c'); // null echo $model->getAttributeExample('a'); // 1 echo $model->getAttributeExample('b'); // null echo $model->getAttributeExample('c'); // null
TODO
Write docs: