-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: channel and operation attribute
- Loading branch information
Showing
7 changed files
with
241 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Attribute; | ||
|
||
use Attribute; | ||
use Ferror\AsyncapiDocBundle\Schema\V2\ChannelType; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
readonly class Channel | ||
{ | ||
public function __construct( | ||
public string $name, | ||
public ChannelType $type = ChannelType::SUBSCRIBE, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Attribute; | ||
|
||
use Attribute; | ||
use Ferror\AsyncapiDocBundle\Schema\V3\OperationType; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
class Operation | ||
{ | ||
public function __construct( | ||
public string $name, | ||
public OperationType $type = OperationType::SEND, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Tests\Unit\Schema\V3; | ||
|
||
use Ferror\AsyncapiDocBundle\Schema\V3\InfoRenderer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class InfoRendererTest extends TestCase | ||
{ | ||
public function testItRenders(): void | ||
{ | ||
$renderer = new InfoRenderer(); | ||
|
||
$document = []; | ||
|
||
$actual = $renderer->render($document); | ||
|
||
$expected = [ | ||
'version' => '2.6.0', | ||
'title' => 'Async API Title', | ||
'description' => 'Async API Description', | ||
]; | ||
|
||
$this->assertEquals($expected, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Tests\Unit\Schema\V3; | ||
|
||
use Ferror\AsyncapiDocBundle\Schema\V3\MessageRenderer; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
class MessageRendererTest extends TestCase | ||
{ | ||
public function testReflection(): void | ||
{ | ||
$document = [ | ||
'name' => 'UserSignedUp', | ||
'properties' => [ | ||
[ | ||
'name' => 'name', | ||
'type' => 'string', | ||
'required' => true, | ||
], | ||
[ | ||
'name' => 'email', | ||
'type' => 'string', | ||
'required' => true, | ||
], | ||
[ | ||
'name' => 'age', | ||
'type' => 'int', | ||
'required' => true, | ||
], | ||
[ | ||
'name' => 'isCitizen', | ||
'type' => 'bool', | ||
'required' => true, | ||
], | ||
], | ||
]; | ||
|
||
$schema = new MessageRenderer(); | ||
|
||
$specification = $schema->render($document); | ||
|
||
$expectedSpecification = <<<YAML | ||
UserSignedUp: | ||
payload: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
email: | ||
type: string | ||
age: | ||
type: integer | ||
isCitizen: | ||
type: boolean | ||
required: | ||
- name | ||
- age | ||
- isCitizen | ||
YAML; | ||
|
||
$this->assertEquals($expectedSpecification, Yaml::dump($specification, 10, 2)); | ||
} | ||
|
||
public function testAttributes(): void | ||
{ | ||
$document = [ | ||
'name' => 'UserSignedUp', | ||
'properties' => [ | ||
[ | ||
'name' => 'name', | ||
'type' => 'string', | ||
'description' => 'Name of the user', | ||
'example' => 'John', | ||
'format' => 'string', | ||
'required' => true, | ||
], | ||
[ | ||
'name' => 'email', | ||
'type' => 'string', | ||
'description' => 'Email of the user', | ||
'format' => 'email', | ||
'example' => '[email protected]', | ||
'required' => true, | ||
], | ||
[ | ||
'name' => 'age', | ||
'type' => 'integer', | ||
'description' => 'Age of the user', | ||
'format' => 'int', | ||
'example' => '18', | ||
'required' => true, | ||
], | ||
[ | ||
'name' => 'isCitizen', | ||
'type' => 'boolean', | ||
'description' => 'Is user a citizen', | ||
'format' => 'boolean', | ||
'example' => 'true', | ||
'required' => true, | ||
], | ||
], | ||
]; | ||
|
||
$schema = new MessageRenderer(); | ||
|
||
$specification = $schema->render($document); | ||
|
||
$expectedSpecification = <<<YAML | ||
UserSignedUp: | ||
payload: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
description: 'Name of the user' | ||
format: string | ||
example: John | ||
email: | ||
type: string | ||
description: 'Email of the user' | ||
format: email | ||
example: [email protected] | ||
age: | ||
type: integer | ||
description: 'Age of the user' | ||
format: int | ||
example: '18' | ||
isCitizen: | ||
type: boolean | ||
description: 'Is user a citizen' | ||
format: boolean | ||
example: 'true' | ||
required: | ||
- name | ||
- age | ||
- isCitizen | ||
YAML; | ||
|
||
$this->assertEquals($expectedSpecification, Yaml::dump($specification, 10, 2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Tests\Unit\Schema\V3; | ||
|
||
use Ferror\AsyncapiDocBundle\Schema\V3\SchemaRenderer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SchemaRendererTest extends TestCase | ||
{ | ||
public function testItRenders(): void | ||
{ | ||
$renderer = new SchemaRenderer(); | ||
|
||
$actual = $renderer->generate(); | ||
|
||
$expected = []; | ||
|
||
$this->assertEquals($expected, $actual); | ||
} | ||
} |