spryker-sdk / async-api
SDK for AsyncAPI.
Installs: 528 343
Dependents: 9
Suggesters: 0
Security: 0
Stars: 2
Watchers: 12
Forks: 1
Open Issues: 0
Requires
- php: >=8.0
- doctrine/inflector: ~1.4.2 || ~2.0.0
- symfony/console: ^4.0.0 || ^5.3 || ^6.0
- symfony/finder: ^4.0.0 || ^5.3 || ^6.0
- symfony/process: ^4.0.0 || ^5.4 || ^6.0
- symfony/property-access: ^4.0.0 || ^5.4 || ^6.0
Requires (Dev)
- codeception/codeception: ^5.0.0
- codeception/module-asserts: ^3.0.0
- mikey179/vfsstream: ^1.6.10
- sllh/composer-versions-check: ^2.0
- spryker-sdk/architector: 0.1.x-dev
- spryker/code-sniffer: ^0.17.20
- symfony/var-dumper: ^6.0.0
README
This library provides an AsyncAPI parser.
Installation
composer require --dev spryker-sdk/async-api
Usage
Parsing an AsyncAPI file
use SprykerSdk\AsyncApi\AsyncApi\Loader\AsyncApiLoader; $asyncApiLoader = new AsyncApiLoader(); $asyncApi = $asyncApiLoader->load('.../path/to/async-api.yml'); // Get the channel(s) $channels = $asyncApi->getChannels(); $channel = $asyncApi->getChannel('channel-name'); // Get publish message(s) $publishMessages = $channel->getPublishMessages(); $publishMessage = $channel->getPublishMessage('message-name'); // Get subscribe message(s) $subscribeMessages = $channel->getSubscribeMessages(); $subscribeMessage = $channel->getSubscribeMessage('message-name'); // Get message detail(s) $messageAttributes = $subscribeMessage->getAttributes(); $messageAttribute = $subscribeMessage->getAttribute('attribute-name');
Run tests/checks
composer test
- This will execute the tests.composer cs-check
- This will run CodeStyle checks.composer cs-fix
- This will fix fixable CodeStyles.composer stan
- This will run PHPStan checks.
Documentation
The following console commands are available:
vendor/bin/asyncapi schema:asyncapi:create
vendor/bin/asyncapi schema:asyncapi:message:add
vendor/bin/asyncapi schema:asyncapi:validate
vendor/bin/asyncapi code:asyncapi:generate
Adding an AsyncAPI file
The vendor/bin/asyncapi schema:asyncapi:create
adds a minimal AsyncAPI file.
Arguments and Options
Arguments
title
vendor/bin/asyncapi schema:asyncapi:create "Your Async API title"
will set the title in your AsyncAPI file.
...
info:
title: 'Your Async API title'
...
Options
asyncapi-file
api-version
vendor/bin/asyncapi schema:asyncapi:create --asyncapi-file "path/to/async-api.yml"
will override the default file location (resources/api/asyncapi.yml).
vendor/bin/asyncapi schema:asyncapi:create --api-version 1.0.0
will override the default file version (0.1.0).
Adding a message to an AsyncAPI file
The vendor/bin/asyncapi schema:asyncapi:message:add
adds a message to a given AsyncAPI file. This command can also be used to reverse engineer from an existing Transfer object.
This console command has many options to be configured. See all of them by running
vendor/bin/asyncapi schema:asyncapi:message:add -h
it will print a help page for this command.
Adding a subscribe message
To subscribe to messages from a specific channel you need to run the command as following:
vendor/bin/asyncapi schema:asyncapi:message:add foo-bar ZipZap ModuleName -e subscribe -P propertyA:string -P propertyB:int
This will add a subscribe section to the given AsyncAPI schema file that describes that sent messages with the name "ZipZap" that are sent over the channel "foo-bar" and that you sent the properties "propertyA of type string" and "propertyB of type int".
You can now create code from this definition.
Adding a publish message
To receive messages from a specific channel you need to run the command as following:
vendor/bin/asyncapi schema:asyncapi:message:add foo-bar ZipZap ModuleName -e publish -P propertyA:string -P propertyB:int
This will add a publish section to the given AsyncAPI schema file that describes that you want to receive messages with the name "ZipZap" that are sent over the channel "foo-bar" and that you want to use the properties "propertyA of type string" and "propertyB of type int".
You can now create code from this definition.
Reverse Engineer from given Transfer
Validating an AsyncAPI file
The vendor/bin/asyncapi schema:asyncapi:validate
validates a given AsyncAPI file.
Create code from an existing AsyncAPI
The vendor/bin/asyncapi code:asyncapi:generate
reads an existing AsyncAPI file and creates code out of it. This command creates:
- Message Transfer definitions (XML)
- Adds handler for Messages that are sent to the application
Options
asyncapi-file
, can be used to run the generator with a specific AsyncAPI fileorganization
, can be used to set a specific organization, when set to Spryker code will be generated in the core modules (default: App)