diff --git a/Generator/Generator.php b/Generator/Generator.php index e8dcbc7..f3f1180 100644 --- a/Generator/Generator.php +++ b/Generator/Generator.php @@ -45,8 +45,13 @@ public function generate(): void ); $filePath = $this->docsFolder.'index.html'; + $filePathSpecification = $this->docsFolder.'specification.json'; $fs = new Filesystem(); $fs->dumpFile($filePath, $docs); + + /** @var string $swaggerConfigAsJson */ + $swaggerConfigAsJson = json_encode($swaggerConfig, \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR); + $fs->dumpFile($filePathSpecification, $swaggerConfigAsJson); } } diff --git a/Tests/Generator/GeneratorTest.php b/Tests/Generator/GeneratorTest.php index 6a7a8b6..8e4df9c 100644 --- a/Tests/Generator/GeneratorTest.php +++ b/Tests/Generator/GeneratorTest.php @@ -24,6 +24,7 @@ final class GeneratorTest extends TestCase private string $docsFolder = __DIR__.'/Fixtures/'; private string $docsFile = __DIR__.'/Fixtures/index.html'; + private string $specificationFile = __DIR__.'/Fixtures/specification.json'; /** @var Environment|MockObject */ private Environment|MockObject $twig; @@ -41,6 +42,7 @@ protected function setUp(): void $this->parser = $this->createMock(ConfigParser::class); $this->filesystem = new Filesystem(); $this->filesystem->dumpFile($this->docsFile, ''); + $this->filesystem->dumpFile($this->specificationFile, ''); $this->generator = new Generator($this->twig, $this->parser, $this->docsFolder); } @@ -54,11 +56,12 @@ protected function tearDown(): void ); $this->filesystem->remove($this->docsFile); + $this->filesystem->remove($this->specificationFile); } public function testGenerate(): void { - $swaggerConfig = ['open api config']; + $swaggerConfig = ['open api config' => 'value']; $this->parser ->expects(self::once()) @@ -76,6 +79,13 @@ public function testGenerate(): void $this->generator->generate(); + $swaggerConfigAsJson = <<<'EOT' +{ + "open api config": "value" +} +EOT; + self::assertStringEqualsFile($this->docsFolder.'index.html', $docs); + self::assertStringEqualsFile($this->docsFolder.'specification.json', $swaggerConfigAsJson); } }