Skip to content

Commit

Permalink
bug: dont render empty servers (#21)
Browse files Browse the repository at this point in the history
The servers in json were unable to parse empty array to object.
  • Loading branch information
Ferror authored Jan 29, 2024
1 parent fb68121 commit 9a828a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/Schema/V2/SchemaRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ public function generate(): array
$messages[$messageKey] = $message[$messageKey];
}

return [
$schema = [
'asyncapi' => $this->schemaVersion,
'info' => $this->infoRenderer->render(),
'servers' => $this->servers,
'channels' => $channels,
'components' => [
'messages' => $messages,
],
];

if ($this->servers) {
$schema['servers'] = $this->servers;
}

return $schema;
}
}
18 changes: 9 additions & 9 deletions tests/Integration/DumpSpecificationConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ public function testExecuteYaml(): void
title: 'Service Example API'
version: 1.2.3
description: 'This service is in charge of processing user signups'
servers:
production:
url: broker.mycompany.com
protocol: amqp
description: 'This is production broker.'
staging:
url: broker.mycompany.com
protocol: amqp
description: 'This is staging broker.'
channels:
user_signed_up:
subscribe:
Expand Down Expand Up @@ -178,6 +169,15 @@ public function testExecuteYaml(): void
- payment
- products
- tags
servers:
production:
url: broker.mycompany.com
protocol: amqp
description: 'This is production broker.'
staging:
url: broker.mycompany.com
protocol: amqp
description: 'This is staging broker.'
YAML;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function test(): void
"version": "1.2.3",
"description": "This service is in charge of processing user signups"
},
"servers": [],
"channels": {
"user_signed_up": {
"subscribe": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function test(): void
title: 'Service Example API'
version: 1.2.3
description: 'This service is in charge of processing user signups'
servers: { }
channels:
user_signed_up:
subscribe:
Expand Down

0 comments on commit 9a828a9

Please sign in to comment.