wwwision / types-glossary
Fund package maintenance!
bwaidelich
Paypal
Installs: 1 204
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- webmozart/assert: ^1.11
- wwwision/types: ^1.2
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.1
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^4.0.x-dev
README
Simple integration for the wwwision/types package that allows to generate Markdown Glossary for all types
Usage
This package can be installed via composer:
composer require wwwision/types-glossary
To generate a Glossary, at least one class is required:
#[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) {} }
Now, a glossary can be rendered via:
// ... $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);
See GlossaryGeneratorTest.php for more examples
Contribution
Contributions in the form of issues or pull requests are highly appreciated
License
See LICENSE