blumilksoftware/openapi-toolbox
Composer 安装命令:
composer require blumilksoftware/openapi-toolbox
包简介
OpenAPI handy toolbox for Laravel applications.
README 文档
README
🧰 openapi-toolbox
OpenAPI Toolbox is a handy package with all important documentation-related features we are using in some of @blumilksoftware projects.
Installation
Install package via Composer and publish configuration file:
composer require blumilksoftware/openapi-toolbox
php artisan vendor:publish
If you need it only for internal development (no documentation serving) you can install it with a development flag:
composer require blumilksoftware/openapi-toolbox --dev
php artisan vendor:publish
Configuration
Configuration file should be published into your application after running php artisan vendor:publish command. It should look like below:
return [ "default" => "openapi", "documentations" => [ "openapi" => [ "format" => Format::YmlToJson, "specification" => [ "path" => resource_path("openapi"), "index" => "openapi.yml", "allow_multiple_files" => false, ], "cache" => [ "enabled" => false, "driver" => "default", "key" => "openapi", ], "ui" => [ "enabled" => false, "single_source" => false, "title" => "Documentation", "routing" => [ "prefix" => "documentation", "name" => "documentation", "middlewares" => [], ], "provider" => UIProvider::Elements, ], ], ], "providers" => [ "elements" => [ "script" => [ "src" => "https://unpkg.com/@stoplight/elements@7.7.16/web-components.min.js", "sri" => "sha384-bwBnouovwwSJc5fWe7VFNxRg+T2lPHhUcHIzdf7mFfqTZkYtM3T/ehzfEr8F02yY", ], "stylesheet" => [ "href" => "https://unpkg.com/@stoplight/elements@7.7.16/styles.min.css", "sri" => "sha384-1lLf7J28IOR7k5RlItk6Y+G3hDgVB3y4RCgWNq6ZSwjYfvJXPtZAdW0uklsAZbGW", ], ], "swagger" => [ "script" => [ "src" => "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js", "sri" => "sha384-xy3YXp34ftsoHshRtcUFjOl/M22B5OEHD5S9AjtVzQokz+BxNff8vNW08msKmH46", ], "stylesheet" => [ "href" => "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css", "sri" => "sha384-pzdBB6iZwPIzBHgXle+9cgvKuMgtWNrBopXkjrWnKCi3m4uJsPPdLQ4IPMqRDirS", ], ], ], ];
Features
Multiple documentations
You can create more than one documentation by adding element to openapi_toolbox.documentations array.
return { "test" => [ "format" => Format::YmlToJson, "specification" => [ "path" => resource_path("documentation/test"), "index" => "openapi.yml", "allow_multiple_files" => false, ], "cache" => [ "enabled" => false, "driver" => "default", "key" => "openapi", ], "ui" => [ "enabled" => false, "single_source" => false, "title" => "Test documentation", "routing" => [ "prefix" => "documentation/test", "name" => "documentation.test", "middlewares" => [], ], "provider" => UIProvider::Elements, ], ], }
OpenAPI documentation UI
With configuration ui.enabled = true a documentation UI will be built from configurable path and served on configurable route. Currently, the Stoplight Elements and Swagger UI are only available UI base components configurable by ui.provider setting.
By default, it should be one documentation available under GET /documentation.
By changing configuration variable ui.single_source to true, application will serve already built single source file for GUI.
OpenAPI documentation endpoint
Serving a documentation itself can be tricky, especially if specification is built from multiple nested files. Here OpenAPI specification files will be built accordingly to configuration and by default the result should be available under GET /documentation/raw.
OpenAPI specification validation
OpenAPI specification files will be built accordingly to configuration and validated on demand by running an Artisan command:
php artisan openapi:validate {documentation}
Good example of usage would be adding this command to CI pipeline for opened pull requests.
Testing requests and responses against OpenAPI specification
Based on kirschbaum-development/laravel-openapi-validator, special trait added to selected PHPUnit test cases enables validation against application's OpenAPI specification:
use \Blumilk\OpenApiToolbox\OpenApiCompatibility\OpenApiCompatibility;
By default, the documentation will be used from openapi_toolbox.default option. You should consider to override getDocumentationName() or getDocumentationConfig() method to select documentation you want to test.
Every time any HTTP call to application would be performed during tests, additional validation will be performed and structure of requests and responses will be checked against OpenAPI specification. For special cases (e.g. testing invalid requests) this validation can be disabled by using $this->withoutRequestValidation() and $this->withoutResponseValidation().
With configuration cache.enabled = true internal builders will use cached OpenAPI specifications.
You can change the cache store by setting the cache.driver option, for example: cache.driver = redis. Make sure to use one of the cache drivers available in your Laravel application.
blumilksoftware/openapi-toolbox 适用场景与选型建议
blumilksoftware/openapi-toolbox 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.71k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「swagger」 「openapi」 「elements」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blumilksoftware/openapi-toolbox 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blumilksoftware/openapi-toolbox 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blumilksoftware/openapi-toolbox 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Swagger integration to Laravel 5
Easy Swagger endpoint using the Zend Expressive routes config
一个接口文档生成器
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
OpenAPI specification generator and Swagger UI for PHP 7.2-8.4 projects (standalone and Nette Framework)
统计信息
- 总下载量: 2.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-29