horat1us/yii2-model-schema

JSON Schema for Yii2 Model using validation rules

1.3.0 2020-07-09 10:05 UTC

This package is auto-updated.

Last update: 2024-10-16 05:29:33 UTC


README

Latest Stable Version Total Downloads Build Status codecov

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:

Contributors

License

MIT