1. Go to this page and download the library: Download tochka-developers/openrpc library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Tochka\JsonRpc\Annotations\ApiIgnore;
use Tochka\JsonRpc\Annotations\ApiValueExample;
use Tochka\JsonRpc\Annotations\ApiArrayShape;
/**
* @ApiIgnore()
*/
class TestDTO
{
/**
* @ApiValueExample(examples={1, 5, 6})
*/
public ?int $int;
/**
* @ApiArrayShape(shape={"test": "string", "foo": "int", "bar": "array", "object": FooObject::class})
*/
public array $testShape;
}
use Tochka\JsonRpc\Annotations\ApiIgnore;
use Tochka\JsonRpc\Annotations\ApiValueExample;
use Tochka\JsonRpc\Annotations\ApiArrayShape;
#[ApiIgnore]
class TestDTO
{
#[ApiValueExample(examples: [1, 5, 6])]
public ?int $int;
#[ApiArrayShape(shape: ['test' => 'string', 'foo' => 'int', 'bar' => 'array', 'object' => FooObject::class])]
public array $testShape;
}
'description' => '$views/docs/description.md'
/** Адрес endpoint для текущего сервера */
'endpoint' => '/api/v1/public/jsonrpc',
/** Базовая информация о сервере/точки входа */
'summary' => 'Основная точка входа',
/** Расширенное описание сервера/точки входа */
'description' => 'Основная точка входа',
/**
* @param array<MyType> $foo Описание параметра FOO
* @param string[] $bar Описание параметра BAR
* @return Result[]
*/
public function myMethod(array $foo, array $bar): array
{
// ...
}
class TestDTO
{
/** @var array<int> */
public array $field;
/** @var MyObject[] */
public array $objects;
}
use Tochka\JsonRpc\Annotations\ApiValueExample;
class TestDTO
{
#[ApiValueExample(examples: [1, 3, 5])]
public int $field;
/**
* @ApiValueExample(examples={"foo", "bar"}}
*/
public string $foo;
}
use Tochka\JsonRpc\Annotations\ApiExpectedValues;
class TestDTO
{
#[ApiExpectedValues(values: [1, 3, 5])]
public int $field;
/**
* @ApiExpectedValues(values={"foo", "bar"}}
*/
public string $foo;
}
use Tochka\JsonRpc\Annotations\ApiArrayShape;
class TestDTO
{
#[ApiArrayShape(shape: ['test' => 'string', 'foo' => 'int', 'bar' => 'array', 'object' => FooObject::class])]
public int $field;
/**
* @ApiArrayShape(shape={"test": "string", "foo": "int", "bar": "array", "object": FooObject::class}}
*/
public string $foo;
}
class TestDTO
{
/**
* Это будет summary
* А вот это будет description
*/
public int $someField;
/**
* Это будет summary
* $views/docs/description.md // содержимое этого файла будет description
*/
public string $foo;
}
use Tochka\JsonRpc\Annotations\ApiArrayShape;
class TestController
{
#[ApiArrayShape(shape: ['test' => 'string', 'foo' => 'int', 'bar' => 'array', 'object' => FooObject::class])]
public function someMethod(): array
{
return [];
}
/**
* @ApiArrayShape(shape={"test": "string", "foo": "int", "bar": "array", "object": FooObject::class}}
*/
public function fooMethod(): array
{
return [];
}
}
use Tochka\JsonRpc\Annotations\ApiArrayShape;
/**
* @ApiArrayShape(shape={"test": "string", "foo": "int", "bar": "array", "object": FooObject::class})
*/
class MyResultClass
{
//...
}
use Tochka\JsonRpc\Annotations\ApiArrayShape;
class MyResultClass
{
#[ApiArrayShape(shape: ['test' => 'string', 'foo' => 'int', 'bar' => 'array', 'object' => FooObject::class])]
public SomeClass $property;
}