diff --git a/src/Writer.php b/src/Writer.php index 43d1c70d..997a6124 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -34,7 +34,7 @@ public static function writeToJson(SpecObjectInterface $object): string */ public static function writeToYaml(SpecObjectInterface $object): string { - return Yaml::dump($object->getSerializableData(), 256, 2, Yaml::DUMP_OBJECT_AS_MAP); + return Yaml::dump($object->getSerializableData(), 256, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE); } /** diff --git a/tests/WriterTest.php b/tests/WriterTest.php index 9ae22213..fc415b51 100644 --- a/tests/WriterTest.php +++ b/tests/WriterTest.php @@ -1,17 +1,19 @@ '3.0.0', 'info' => [ 'title' => 'Test API', 'version' => '1.0.0', ], 'paths' => [], - ]); + ], $merge)); } public function testWriteJson() @@ -78,6 +80,108 @@ public function testWriteYaml() version: 1.0.0 paths: { } +YAML + ), + $yaml + ); + } + + public function testWriteEmptySecurityJson() + { + $openapi = $this->createOpenAPI([ + 'security' => [], + ]); + + $json = \cebe\openapi\Writer::writeToJson($openapi); + + $this->assertEquals(preg_replace('~\R~', "\n", <<createOpenAPI([ + 'security' => [], + ]); + + $yaml = \cebe\openapi\Writer::writeToYaml($openapi); + + + $this->assertEquals(preg_replace('~\R~', "\n", <<createOpenAPI([ + 'security' => [new SecurityRequirement(['Bearer' => []])], + ]); + + $json = \cebe\openapi\Writer::writeToJson($openapi); + + $this->assertEquals(preg_replace('~\R~', "\n", <<createOpenAPI([ + 'security' => [new SecurityRequirement(['Bearer' => []])], + ]); + + $yaml = \cebe\openapi\Writer::writeToYaml($openapi); + + + $this->assertEquals(preg_replace('~\R~', "\n", <<