alexanderallen/panettone

一个轻量级的PHP类型生成器,用于Open API(以前称为Swagger)

0.2.3 2024-07-25 20:34 UTC

This package is auto-updated.

Last update: 2024-09-27 17:51:50 UTC


README

blackieshoot-IlbJvIia9aY-unsplash

图片由 @blackieshootUnsplash 提供

GitHub Actions Workflow Status Coveralls License Version

Panettone

Panettone 是一个 CLI 工具,用于从 Open API 架构中提取 PHP 类型。类型是通过解释 Open API 文档的 数据模型(架构)生成的。与 Api Platform 的 架构生成器不同,它不使用 路径和操作来确定类型。

2024 年 9 月更新

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