diff --git a/src/Schema/V2/SchemaRenderer.php b/src/Schema/V2/SchemaRenderer.php index 45dfc1c..0a0a926 100644 --- a/src/Schema/V2/SchemaRenderer.php +++ b/src/Schema/V2/SchemaRenderer.php @@ -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; } } diff --git a/tests/Integration/DumpSpecificationConsoleTest.php b/tests/Integration/DumpSpecificationConsoleTest.php index 2450c8f..41fc953 100644 --- a/tests/Integration/DumpSpecificationConsoleTest.php +++ b/tests/Integration/DumpSpecificationConsoleTest.php @@ -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: @@ -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; diff --git a/tests/Unit/Symfony/Controller/JsonSpecificationControllerTest.php b/tests/Unit/Symfony/Controller/JsonSpecificationControllerTest.php index d8807e4..bbc58fe 100644 --- a/tests/Unit/Symfony/Controller/JsonSpecificationControllerTest.php +++ b/tests/Unit/Symfony/Controller/JsonSpecificationControllerTest.php @@ -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": { diff --git a/tests/Unit/Symfony/Controller/YamlSpecificationControllerTest.php b/tests/Unit/Symfony/Controller/YamlSpecificationControllerTest.php index d8912f3..aec198e 100644 --- a/tests/Unit/Symfony/Controller/YamlSpecificationControllerTest.php +++ b/tests/Unit/Symfony/Controller/YamlSpecificationControllerTest.php @@ -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: