codexsoft/transmission-ts-converter
Composer 安装命令:
composer require codexsoft/transmission-ts-converter
包简介
Typescript converter for CodexSoft Transmission library for building HTTP API
README 文档
README
This library provides a way to convert Transmission elements into typescript interfaces (recursively). It supports references.
Installation
composer require codexsoft/transmission-ts-converter
Extending
By default, only basic element classes can be converted: CollectionElement, JsonElement, StringElement, NumberElement, BoolElement, ScalarElement. You can add your own converters (each needs to extend CodexSoft\Transmission\Typescript\Converters\AbstractElementTsConverter)
$toTs = (new TransmissionToTypescriptConverter()); $toTs->addKnownConverter(MyElement::class => MyElementTsConverter::class);
Usage
Using this utility you can generate SDK for typescript. For given directory with controllers that implement CodexSoft\Transmission\OpenApi3\OpenApi3OperationInterface generator of whole API can be easily implemented.
// ...preparing Symfony Finder or whatever $endpointReflections = []; foreach ($finder->getIterator() as $fileInfo) { $fqnClassName = (string) 'App'.(new \Stringy\Stringy($fileInfo->getRealPath())) ->removeRight('.php') ->replace('/', "\\"); $reflectionClass = new \ReflectionClass($fqnClassName); if ($reflectionClass->isAbstract()) { continue; } if (!$reflectionClass->implementsInterface(OpenApi3OperationInterface::class)) { continue; } $endpointReflections[] = $reflectionClass; $toTs = (new TransmissionToTypescriptConverter()); /** * Set ref interface name generator */ $toTs->setCreateRefClosure(function(string $class) { $reflection = new \ReflectionClass($class); return (string) (new \Stringy\Stringy('I'.$reflection->getShortName()))->removeRight('Transformer'); }); }
Testing
php ./vendor/bin/phpunit
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-14