apiboard/php-openapi
Composer 安装命令:
composer require apiboard/php-openapi
包简介
OpenAPI Specification library for PHP 8. Supports both OAS 3.0 and 3.1.
README 文档
README
OpenAPI Specification parser for PHP 8. Supports both OAS 3.0 and 3.1.
Features
- Parse OpenAPI files into a PHP object to interact with in code
- Validate OpenAPI files against the official JSON-schema descriptions
- Resolve external and internal references
Installation
composer require apiboard/php-openapi
Usage
You can interact with this library through the OpenAPI::class directly.
$openAPI = new OpenAPI();
This class optionally accepts an implementation of Apiboard\OpenAPI\Contents\Retriever::class which will be used to retrieve the file contents. By default the local filesystem will be used to retrieve file contents.
Parse
You can parse the contents of a file by passing its path to parse(). This will attempt to retrieve the file's contents and resolve any external references.
It returns a PHP object that represents the OAS document structure that can be used in code.
$document = $openAPI->parse('/path/to/my-oas.json'); $document->openapi(); // 3.1.0
Validate
You can directly validate the contents of a file against the official OpenAPI JSON-schema descriptions. It returns an array of possible errors that occured during the validation.
$errors = $openAPI->validate('/path/to/my-oas.yaml');
⚠️ Validation for OAS 3.1 does not check any JSON Schemas in your OpenAPI document because it allows you to use any JSON Schema dialect you choose!
Resolve
You can resolve external and internal references. It returns a PHP object with the resolved contents.
$contents = $openAPI->resolve('/path/to/my-oas.json'); $document = new Apiboard\OpenAPI\Structure\Document($contents);
When resolving references the contents will be retrieved from the local fileystem by default. You can override the way file contents is retrieved by passing a custom class that implements the Apiboard\OpenAPI\Contents\Retriever interface.
$customRetriever = new MyCustomRetriever(); $openAPI = new OpenAPI($customRetriever); $openAPI->resolve('/path/to/my-oas.json');
Circular references are resolved as an internal reference after recursing twice, this is to prevent infinite recursion.
License
The MIT License (MIT). Please see License File for more information.
apiboard/php-openapi 适用场景与选型建议
apiboard/php-openapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 420 次下载、GitHub Stars 达 6, 最近一次更新时间为 2023 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 apiboard/php-openapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 apiboard/php-openapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 420
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 13
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-31