alexanderallen / panettone
一个轻量级的PHP类型生成器,用于Open API(以前称为Swagger)
0.2.3
2024-07-25 20:34 UTC
Requires
- cebe/php-openapi: ^1.7
- loophp/collection: ^7.5
- nette/php-generator: ^4.1
- psr/log: ^3.0
- symfony/console: ^6.0
- widmogrod/php-functional: dev-master
README
图片由 @blackieshoot 在 Unsplash 提供
Panettone
Panettone 是一个 CLI 工具,用于从 Open API 架构中提取 PHP 类型。类型是通过解释 Open API 文档的 数据模型(架构)生成的。与 Api Platform 的 架构生成器不同,它不使用 路径和操作来确定类型。
2024 年 9 月更新
- 关于 在解析 Open API 源时使用函数式模式 的工作正在进行中
- 关于 0.2.4 的工作正在进行中
2024 年 7 月更新
预发布 0.2.3 引入了一组初始功能结构,未来将用于 Open API 解析。
安装
composer require alexanderallen/panettone
vendor/bin/panettone --help
由于 Panettone 不是一个 CLI 工具,也不是一个库,我建议您将其安装到项目的 tools
目录中,如下所示
mkdir -p tools
cd tools
composer require alexanderallen/panettone
cd ..
vendor/bin/panettone --help
示例
vendor/bin/panettone schema/my-saucy-schema.yaml tmp vendor/alexanderallen/panettone/test/schema/settings.ini
在上面的示例中,Panettone 将
- 源
schema/my-saucy-schema.yaml
Open Api 文件; - 将所有生成的类型输出到
tmp
目录,并; - 使用
vendor/alexanderallen/panettone/test/schema/settings.ini
中的设置来指导类型生成过程。
使用方法
vendor/bin/panettone --help
Description:
Generate PHP types from Open API sources.
Usage:
panettone <input> [<output> [<config>]]
Arguments:
input Path to Open Api source file in YAML format
output Destination for generated files
config Path to .ini configuration file [default: "settings.ini"]
Options:
-h, --help Display help for the given command. When no command is given display help for the panettone command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Help:
Generates PHP types from a Open API source.
配置
Panettone 通过在执行 Panettone 的目录中放置一个 settings.ini
来进行配置,通常在您的 composer.json
文件所在的目录。
以下是当前支持配置选项的列表。请注意,使用下面列出的选项时,需要提供 [file], [class]
段落。
; Enable detailed logging during type generation.
debug = true
[file]
; Path where to dump the generated file.
output_path = "tmp"
; Namespace for all generated files.
namespace = "Panettone"
; Comment to apply to every generated file.
comment = "Example file comments are configured in settings.ini."
[class]
nullable = true
default = null
测试
测试位于 tests
目录中。PHPUnit 是单独安装在 tools/phpunit
目录中的。
要测试,首先使用 Composer 安装 PHPUnit,然后运行测试脚本。
composer -d tools/phpunit install
. tools/phpunit/test
覆盖率
覆盖率详细信息在测试期间在 Github 和 pushed to Coveralls。