harmbandstra/swagger-ui-bundle
Composer 安装命令:
composer require harmbandstra/swagger-ui-bundle
包简介
Exposes swagger UI inside your Symfony project through a route (eg. /docs)
README 文档
README
Swagger UI Bundle
Expose swagger-ui inside your symfony project through a route (eg. /docs), just like nelmio api docs, without the need for node.
Just add a reference to your OpenAPI Yaml or JSON specification, and enjoy swagger-ui in all it's glory.
After installation and configuration, just start your local webserver, and navigate to /docs or /docs/my_swagger_spec.yml.
Compatibility
- If you need symfony 2.3 - 2.6 support, use version 1.x.
- If you need symfony 2.7 - 3.x support, or php 5.x use version 2.x.
- For symfony 3.3 and later with PHP > 7.0 use version 3.x.
- For symfony 4.0 and later with PHP => 7.1.3 use version 4.x.
- For PHP > 8.0 user version > 4.4
NOTE Since version 3.1, support for symfony 4 on the 3.x branch has been dropped. Use the 4.x branch instead.
Installation
Install with composer in dev environment:
$ composer require harmbandstra/swagger-ui-bundle --dev
Make sure swagger-ui assets are copied to web/bundles by adding the HarmBandstra\SwaggerUiBundle\Composer\ScriptHandler::linkAssets composer hook before the Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets hook in your composer.json.
{
"scripts": {
"symfony-scripts": [
"HarmBandstra\\SwaggerUiBundle\\Composer\\ScriptHandler::linkAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets"
],
"post-install-cmd": ["@symfony-scripts"],
"post-update-cmd": ["@symfony-scripts"]
}
If the scripts section in composer.json looks like this (symfony 4):
"scripts": { "auto-scripts": { "cache:clear": "symfony-cmd", "assets:install %PUBLIC_DIR%": "symfony-cmd" }, "post-install-cmd": [ "@auto-scripts" ], "post-update-cmd": [ "@auto-scripts" ] },
Add the composer hook like this:
"scripts": { "auto-scripts": { "cache:clear": "symfony-cmd", "assets:install %PUBLIC_DIR%": "symfony-cmd" }, "post-install-cmd": [ "HarmBandstra\\SwaggerUiBundle\\Composer\\ScriptHandler::linkAssets", "@auto-scripts" ], "post-update-cmd": [ "HarmBandstra\\SwaggerUiBundle\\Composer\\ScriptHandler::linkAssets", "@auto-scripts" ] },
Enable bundle in app/AppKernel.php(Symfony 3):
<?php class AppKernel extends Kernel { public function registerBundles() { // ... if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { // ... $bundles[] = new HarmBandstra\SwaggerUiBundle\HBSwaggerUiBundle(); } // ... } }
Enable bundle in config/bundles.php(Symfony 4):
<?php return [ // ... HarmBandstra\SwaggerUiBundle\HBSwaggerUiBundle::class => ['dev' => true] ];
Add the route where swagger-ui will be available in routing_dev.yml:
_swagger-ui: resource: '@HBSwaggerUiBundle/Resources/config/routing.yml' prefix: /docs
Configuration (Symfony 3)
In your config.yml, link to the swagger spec.
Specify the directory where your swagger files reside. You can access multiple files through the endpoint like /docs/my_swagger_spec.json.
Under files you specify which files should be exposed.
The first file in the array is the default one and it will be the file the /docs endpoint will redirect to. For this file you have the option to specify an absolute path to the .json spec file ("/_swagger/swagger.json") or a URL ("https://example.com/swagger.json").
hb_swagger_ui: directory: "%kernel.root_dir%/../docs/" files: - "/_swagger/swagger.json" - "my_swagger_spec.yml" - "my_other_swagger_spec.json"
Optional: If you want to have a default configuration in place for Swagger UI, place a config.json in the same directory as the swagger files, and add it to the configuration. It will be loaded automatically by appending it as the query parameter configUrl.
hb_swagger_ui: configFile: "config.json"
Optional: If you serve your project from a different directory than the vhost root, you can overwrite the asset URL path with the assetUrlPath configuration. Be sure to add a leading and trailing slash.
hb_swagger_ui: assetUrlPath: '/my-vhost-sub-directory/bundles/hbswaggerui/'
Configuration (Symfony 4, 5 and 6)
Create a file hb_swagger_ui.yaml in config/packages. Follow the rest of the steps for configuration in Symfony 3.
harmbandstra/swagger-ui-bundle 适用场景与选型建议
harmbandstra/swagger-ui-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 884.99k 次下载、GitHub Stars 达 40, 最近一次更新时间为 2017 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「php」 「api」 「bundle」 「doc」 「swagger」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 harmbandstra/swagger-ui-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 harmbandstra/swagger-ui-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 harmbandstra/swagger-ui-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
A PSR-7 compatible library for making CRUD API endpoints
Bundle Symfony DaplosBundle
Alfabank REST API integration
Biblioteca PHP pura para pagamentos SISP/Vinti4 de Cabo Verde.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
统计信息
- 总下载量: 884.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 42
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2017-02-24