-
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: async api schema v3 without operations (#23)
Async API V3 adds an Operation object. It gives many more features but also increases the complexity. Therefore, this PR introduces Schema V3 compatibility, but without operations.
- Loading branch information
Showing
19 changed files
with
566 additions
and
34 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 |
---|---|---|
|
@@ -8,10 +8,13 @@ on: | |
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
name: CI - PHP ${{ matrix.php }}, Dependencies ${{ matrix.dependencies }} | ||
name: CI - PHP ${{ matrix.php }}, Dependencies ${{ matrix.dependencies }}, Schema ${{ matrix.schema }} | ||
env: | ||
ASYNCAPI_VERSION: ${{ matrix.schema }} | ||
strategy: | ||
matrix: | ||
php: [8.2, 8.3] | ||
schema: [3.0.0, 2.6.0] | ||
dependencies: [lowest, highest] | ||
include: | ||
- | ||
|
@@ -55,12 +58,12 @@ jobs: | |
- # Run AsyncAPI Validation | ||
name: AsyncAPI Validation | ||
run: | | ||
docker run --rm -v $(pwd):/app asyncapi/cli:1.4.4 validate /app/var/asyncapi.yaml | ||
docker run --rm -v $(pwd):/app asyncapi/cli:1.4.4 validate /app/var/asyncapi.json | ||
docker run --rm -v $(pwd):/app asyncapi/cli:1.4.4 validate /app/var/${{ matrix.schema }}/asyncapi.yaml | ||
docker run --rm -v $(pwd):/app asyncapi/cli:1.4.4 validate /app/var/${{ matrix.schema }}/asyncapi.json | ||
- # Upload Coverage to Coveralls | ||
name: Coveralls | ||
if: ${{ matrix.coveralls }} | ||
if: ${{ matrix.coveralls && github.event_name == 'pull_request' }} | ||
uses: coverallsapp/[email protected] | ||
with: | ||
file: var/coverage/clover.xml |
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
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
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Schema\V3; | ||
|
||
final readonly class ChannelRenderer | ||
{ | ||
public function render(array $document): array | ||
{ | ||
$channels = []; | ||
|
||
foreach ($document['channels'] as $channel) { | ||
$channels[$channel['name']] = [ | ||
'messages' => [ | ||
$document['name'] => [ | ||
'$ref' => '#/components/messages/' . $document['name'], | ||
] | ||
], | ||
]; | ||
} | ||
|
||
return $channels; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Schema\V3; | ||
|
||
final readonly class InfoRenderer | ||
{ | ||
public function __construct( | ||
public string $title, | ||
public string $description, | ||
public string $version, | ||
) { | ||
} | ||
|
||
public function render(): array | ||
{ | ||
return [ | ||
'title' => $this->title, | ||
'version' => $this->version, | ||
'description' => $this->description, | ||
]; | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Schema\V3; | ||
|
||
use Ferror\AsyncapiDocBundle\PropertyTypeTranslator; | ||
|
||
final readonly class MessageRenderer | ||
{ | ||
public function render(array $document): array | ||
{ | ||
$properties = []; | ||
$required = []; | ||
|
||
foreach ($document['properties'] as $property) { | ||
$properties[$property['name']]['type'] = PropertyTypeTranslator::translate($property['type']); | ||
|
||
if (!empty($property['description'])) { | ||
$properties[$property['name']]['description'] = $property['description']; | ||
} | ||
|
||
if (!empty($property['format'])) { | ||
$properties[$property['name']]['format'] = $property['format']; | ||
} | ||
|
||
if (!empty($property['example'])) { | ||
$properties[$property['name']]['example'] = $property['example']; | ||
} | ||
|
||
if (isset($property['required']) && $property['required']) { | ||
$required[] = $property['name']; | ||
} | ||
} | ||
|
||
$message[$document['name']] = [ | ||
'payload' => [ | ||
'type' => 'object', | ||
'properties' => $properties, | ||
'required' => $required, | ||
], | ||
]; | ||
|
||
return $message; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ferror\AsyncapiDocBundle\Schema\V3; | ||
|
||
final readonly class ServerRenderer | ||
{ | ||
public function __construct(private array $servers) | ||
{ | ||
} | ||
|
||
public function render(): array | ||
{ | ||
$servers = []; | ||
|
||
foreach ($this->servers as $name => $properties) { | ||
$url = $properties['url']; | ||
unset($properties['url']); | ||
$properties['host'] = $url; | ||
|
||
$servers[$name] = $properties; | ||
} | ||
|
||
return $servers; | ||
} | ||
} |
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
Oops, something went wrong.