pccomponentes / documentation-bundle
PcComponentes 文档组件
v1.4.4
2023-12-20 10:59 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- pccomponentes/ddd: ^2.0 || ^3.0 || ^4.0
- symfony/config: ^4.4 || ^5.0 || ^6.0 || ^7.0
- symfony/dependency-injection: ^4.4 || ^5.0 || ^6.0 || ^7.0
- symfony/http-foundation: ^4.4 || ^5.0 || ^6.0 || ^7.0
- symfony/http-kernel: ^4.4 || ^5.0 || ^6.0 || ^7.0
- symfony/routing: ^4.4 || ^5.0 || ^6.0 || ^7.0
- symfony/yaml: ^4.4 || ^5.0 || ^6.0 || ^7.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-20 13:09:06 UTC
README
该文档组件管理必要的路由和模板,以便在OpenApi和AsyncApi格式中显示文档。
安装
将pccomponentes/documentation-bundle包添加到composer.json文件的要求部分。
$ composer require pccomponentes/documentation-bundle
将DocumentationBundle添加到应用程序的kernel中。
<?php public function registerBundles() { $bundles = [ // ... new PcComponentes\DocumentationBundle\DocumentationBundle(), // ... ]; ... }
根据您的安装情况,可能需要将其添加到bundles.php文件中。
<?php return [ // ... PcComponentes\DocumentationBundle\DocumentationBundle::class => ['all' => true], // ... ];
使用方法
在config.yml中配置您的YAML文件路径(两个键都是可选的)。
documentation: openapi: 'docs/openapi.yml' asyncapi: 'docs/asyncapi.yml'
在routing.yml文件中启用路径。
documentation: resource: '@DocumentationBundle/Resources/config/routing.yaml' prefix: /docs
您可以选择一个前缀,文档将在此前缀下发布。
之后,您应该在/openapi(或使用docs前缀时为/docs/openapi)上看到Swagger界面,在/asyncapi上看到AsyncApi,以及在/converters上看到您所有的事件转换器。
此外,您可以使用swagger_options键自定义SwaggerUI选项,例如
documentation: openapi: 'docs/openapi.yml' asyncapi: 'docs/asyncapi.yml' swagger_options: deepLinking: true displayOperationId: true displayRequestDuration: true asyncapi_options: schemaFetchOptions: '{"method":"GET","mode":"cors"}'
此外,您可以使用links键将自定义链接添加到主页,以下是一个示例
documentation: links: - title: 'Google' description: 'You can add some notes for each link' url: 'https://www.google.com/' - title: 'Contact PcComponentes' url: 'https://www.pccomponentes.com/soporte/contactar-con-pccomponentes'