ferror/asyncapi-doc-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ferror/asyncapi-doc-bundle

最新稳定版本:0.1.0-alpha.7

Composer 安装命令:

composer require ferror/asyncapi-doc-bundle

包简介

README 文档

README

The library was inspired by nelmio/api-doc-bundle; To create a code-first experience for PHP and Symfony engineers. This piece of software enables you to document events and messages via PHP built-in Attributes.

Features

  • Code-first async messages documentation
  • Built-in ability to present code powered by Async API React Component
  • Automated documentation powered by PHP Reflection

Installation

composer require ferror/asyncapi-doc-bundle
// config/bundles.php
return [
    Ferror\AsyncapiDocBundle\Symfony\Bundle::class => ['all' => true],
];
# config/packages/asyncapi_doc_bundle.yaml
ferror_asyncapi_doc_bundle:
  asyncapi_version: '2.6.0' # Async API specification version (default: 2.6.0)
  title: 'Service Example API'
  version: '1.2.3' # Your API version
  events: # The event class namespace
    - Ferror\AsyncapiDocBundle\Tests\Examples\UserSignedUp
# config/routes.yaml
ferror_asyncapi_doc_bundle_yaml:
    path: /asyncapi.yaml
    controller: ferror.asyncapi_doc_bundle.controller.yaml
    methods: GET

ferror_asyncapi_doc_bundle_json:
    path: /asyncapi.json
    controller: ferror.asyncapi_doc_bundle.controller.json
    methods: GET

ferror_asyncapi_doc_bundle_html:
    path: /asyncapi
    controller: ferror.asyncapi_doc_bundle.controller.ui
    methods: GET

Minimal Usage

Async API Symfony Bundle will use Reflection to determine the type and name of properties.

Check out the other example if you want to define them manually.

use Ferror\AsyncapiDocBundle\Attribute\Message;
use Ferror\AsyncapiDocBundle\Attribute\Channel;

#[Message(name: 'ProductCreated')]
#[Channel(name: 'product.created')] // optional
final readonly class ProductCreated
{
    public function __construct(
        public int $id,
        public float $amount,
        public string $currency,
        public bool $isPaid,
        public DateTime $createdAt,
        public Week $week,
        public Payment $payment,
        public array $products,
        public array $tags,
    ) {
    }
}

Usage

use Ferror\AsyncapiDocBundle\Attribute as AA;
use Ferror\AsyncapiDocBundle\Schema\Format;
use Ferror\AsyncapiDocBundle\Schema\PropertyType;

#[AA\Message(name: 'ProductCreated')]
#[AA\Channel(name: 'product.created')] // optional
final readonly class ProductCreated
{
    public function __construct(
        #[AA\Property(name: 'id', type: PropertyType::INTEGER)]
        public int $id,
        #[AA\Property(name: 'amount', type: PropertyType::FLOAT)]
        public float $amount,
        #[AA\Property(name: 'currency', type: PropertyType::STRING)]
        public string $currency,
        #[AA\Property(name: 'isPaid', type: PropertyType::BOOLEAN)]
        public bool $isPaid,
        #[AA\Property(name: 'createdAt', type: PropertyType::STRING, format: Format::DATETIME)]
        public DateTime $createdAt,
        #[AA\PropertyEnum(name: 'week', enum: Week::class)]
        public Week $week,
        #[AA\PropertyObject(name: 'payment', class: Payment::class)]
        public Payment $payment,
        #[AA\PropertyArrayObject(name: 'products', class: Product::class)]
        public array $products,
        #[AA\PropertyArray(name: 'tags', itemsType: 'string')]
        public array $tags,
    ) {
    }
}

统计信息

  • 总下载量: 26.53k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-07