wwwision/types-glossary

1.1.1 2024-08-09 14:57 UTC

This package is auto-updated.

Last update: 2024-09-09 15:26:26 UTC


README

为 wwwision/types 包提供简单集成,允许生成所有类型的 Markdown 术语表

使用方法

此包可以通过 composer 安装

composer require wwwision/types-glossary

要生成术语表,至少需要一个类

#[StringBased(minLength: 1, maxLength: 200)]
final class Name {
    private function __construct(public readonly string $value) {}
}

#[IntegerBased(minimum: 1, maximum: 130)]
final class Age {
    private function __construct(public readonly int $value) {}
}

final class Contact {
    public function __construct(
        public readonly Name $name,
        public readonly Age $age,
    ) {}
}

#[ListBased(itemClassName: Contact::class, minCount: 1, maxCount: 5)]
final class Contacts {
    private function __construct(private readonly array $contacts) {}
}

现在,可以通过以下方式渲染术语表

// ...
$generator = new GlossaryGenerator();
$generator->registerClassNames('Group 01', Name::class, Age::class);
$generator->registerClassNames('Group 02', Contact::class, Contacts::class);

$expected = <<<MARKDOWN
# Group 01

## Name

### Schema

 * **type**: string
 * **minLength**: 1
 * **maxLength**: 200

## Age

### Schema

 * **type**: integer
 * **minimum**: 1
 * **maximum**: 130

# Group 02

## Contact

### Schema

 * **type**: object

#### Properties

 * name ([Name](#name))
 * age ([Age](#age))

## Contacts

### Schema

 * **type**: array
 * **items.type**: [Contact](#contact)
 * **minItems**: 1
 * **maxItems**: 5


MARKDOWN;

assert($generator->generate() === $expected);

有关更多示例,请参阅 GlossaryGeneratorTest.php

贡献

问题拉取请求的形式的贡献非常受欢迎

许可证

请参阅 LICENSE