adachsoft/open-api-reader
Composer 安装命令:
composer require adachsoft/open-api-reader
包简介
Open API reader library
README 文档
README
PHP library for reading and processing OpenAPI 3 specifications (JSON / YAML).
- PHP ">= 8.1"
- Framework‑agnostic
- Supports:
- loading OpenAPI specs from
.jsonand.yaml/.ymlfiles, - listing endpoints with pagination,
- fetching single endpoint details (parameters, request body, responses),
- reading schema definitions from
components.schemas, - searching endpoints by path and summary/description.
- loading OpenAPI specs from
Installation
composer require adachsoft/open-api-reader
Requires PHP 8.1 or higher (as defined in composer.json).
Basic usage
The recommended way to use the library is via the built‑in factory OpenApiReaderFactory:
use AdachSoft\OpenApiReader\Factory\OpenApiReaderFactory;
$factory = OpenApiReaderFactory::createDefault();
// Load specification from JSON or YAML file
$reader = $factory->createFromFile(__DIR__ . '/openapi.yaml');
// 1. List endpoints (pagination)
$summary = $reader->getEndpointsSummary(page: 1, limit: 20);
foreach ($summary as $endpointSummaryDto) {
echo $endpointSummaryDto->method . ' ' . $endpointSummaryDto->path . PHP_EOL;
}
// 2. Get details for a specific endpoint
$detail = $reader->getEndpointDetails('/users/{id}', 'GET');
// 3. Get schema definition
$schema = $reader->getSchema('User');
// 4. Search endpoints by path or description
$results = $reader->search('user');
Supported HTTP methods
When building the endpoint list (getEndpointsSummary), the following HTTP methods are taken into account:
GETPOSTPUTPATCHDELETEOPTIONSHEADTRACE
YAML support
YAML files (*.yaml / *.yml) are supported via the YamlSpecLoader class.
Default behaviour:
- If the
yaml_parse_filefunction (PECLyamlextension) is available, it is used to read and parse the YAML file. - If parsing fails or the
yamlextension is not installed, the loader:- tries to locate a neighbouring JSON file with the same name (e.g.
openapi.yaml→openapi.json), - uses
JsonSpecLoaderas a fallback mechanism.
- tries to locate a neighbouring JSON file with the same name (e.g.
- If neither the YAML file nor the JSON file can be successfully read, a
FileNotReadableExceptionis thrown.
This allows the library to work consistently both with and without the yaml extension.
You can also inject a custom YAML parser (e.g. based on another library) by passing a callback as the second argument to YamlSpecLoader.
Architecture overview
Public contract of the library:
AdachSoft\OpenApiReader\OpenApiReaderInterface
Default implementation:
AdachSoft\OpenApiReader\OpenApiReader- created via
AdachSoft\OpenApiReader\Factory\OpenApiReaderFactory
Main internal components (marked as @internal, usually not used directly by consumers):
- Specification loaders:
Loader\SpecLoaderInterfaceLoader\JsonSpecLoaderLoader\YamlSpecLoader
- Data cleaning:
Cleaner\DataCleanerInterfaceCleaner\EmptyValueDataCleaner(recursively removesnullvalues and empty arrays[])
- Builders:
Builder\EndpointBuilderInterface/Builder\EndpointBuilderBuilder\SchemaBuilderInterface/Builder\SchemaBuilder
- DTOs and collections:
Dto\EndpointSummaryDto,Dto\EndpointDetailDto,Dto\SchemaDefinitionDto,Dto\ParameterDto,Dto\RequestBodyDto,Dto\ResponseDtoCollection\EndpointSummaryCollection,Collection\ParameterCollection,Collection\ResponseCollection,Collection\OpenApiSpecDataCollection
As a consumer, you should typically use:
OpenApiReaderFactoryto create a reader instance,OpenApiReaderInterface/OpenApiReaderas the main API.
Advanced configuration
You can build a custom configuration (e.g. your own cleaner or loaders) and pass it into the factory:
use AdachSoft\OpenApiReader\Builder\EndpointBuilder;
use AdachSoft\OpenApiReader\Builder\SchemaBuilder;
use AdachSoft\OpenApiReader\Cleaner\EmptyValueDataCleaner;
use AdachSoft\OpenApiReader\Factory\OpenApiReaderFactory;
use AdachSoft\OpenApiReader\Loader\JsonSpecLoader;
use AdachSoft\OpenApiReader\Loader\YamlSpecLoader;
$dataCleaner = new EmptyValueDataCleaner();
$jsonLoader = new JsonSpecLoader();
$yamlLoader = new YamlSpecLoader($jsonLoader); // default parser uses yaml_parse_file if available
$factory = new OpenApiReaderFactory(
specLoaders: [$jsonLoader, $yamlLoader],
endpointBuilder: new EndpointBuilder($dataCleaner),
schemaBuilder: new SchemaBuilder($dataCleaner),
);
$reader = $factory->createFromFile(__DIR__ . '/openapi.yaml');
If you need full control over YAML parsing, you can inject your own parser callback:
use AdachSoft\OpenApiReader\Loader\YamlSpecLoader;
$parser = static function (string $filePath): array {
// parse YAML using your preferred library
};
$yamlLoader = new YamlSpecLoader($jsonLoader, $parser);
Tests and quality
The project includes a PHPUnit 13 test suite:
vendor/bin/phpunit
Additional tools:
PHPStan (static analysis):
composer run stanPHP CS Fixer (code style):
composer run cs:check # check only composer run cs:fix # apply fixes
License
This project is released under the MIT license (see composer.json).
adachsoft/open-api-reader 适用场景与选型建议
adachsoft/open-api-reader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「reader」 「openapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adachsoft/open-api-reader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adachsoft/open-api-reader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adachsoft/open-api-reader 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
laravel facade to read/write csv file
The following pages give you some general information on how to use our APIs.<br/>The actual API services documentation then follows further below. You can use the menu to jump between API sections.<br/><br/>This page has a built-in HTTP(S) client, so you can test the services directly from within t
Just parse YAML content to array
Simple PHP QR Code Reader / Decoder
CSS reader and writer with full CSS3 support, already supporting huge parts of the current CSS4 spec. It supports media queries, comments, value optimization and more... It offers full Unicode support and can handle also large CSS sources. Requires PHP 5.4+.
PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 35
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-03