diff --git a/Command/DumpCommand.php b/Command/DumpCommand.php index 47f80be..c2d929f 100644 --- a/Command/DumpCommand.php +++ b/Command/DumpCommand.php @@ -31,7 +31,6 @@ class DumpCommand extends Command private $defaultHtmlConfig = [ 'assets_mode' => AssetsMode::CDN, 'swagger_ui_config' => [], - 'server_url' => null, ]; public function __construct(RenderOpenApi $renderOpenApi) @@ -57,8 +56,9 @@ class DumpCommand extends Command 'Output format like: '.implode(', ', $availableFormats), RenderOpenApi::JSON ) + ->addOption('server-url', '', InputOption::VALUE_REQUIRED, 'URL where live api doc is served') ->addOption('html-config', '', InputOption::VALUE_REQUIRED, '', json_encode($this->defaultHtmlConfig)) - ->addOption('no-pretty', '', InputOption::VALUE_NONE, 'Do not pretty format output') + ->addOption('no-pretty', '', InputOption::VALUE_NONE, 'Do not pretty format JSON output') ; } @@ -80,6 +80,10 @@ class DumpCommand extends Command ]; } + if ($input->getOption('server-url')) { + $options['server_url'] = $input->getOption('server-url'); + } + $docs = $this->renderOpenApi->render($format, $area, $options); $output->writeln($docs, OutputInterface::OUTPUT_RAW); diff --git a/Resources/doc/commands.rst b/Resources/doc/commands.rst index 93bb6e1..839a122 100644 --- a/Resources/doc/commands.rst +++ b/Resources/doc/commands.rst @@ -17,6 +17,12 @@ without whitespace, use the ``--no-pretty`` option. $ php app/console api:doc:dump --format=json > json-pretty-formatted.json $ php app/console api:doc:dump --format=json --no-pretty > json-no-pretty.json +Every format can override API url. Useful if static documentation is not hosted on API url: + +.. code-block:: bash + + $ php app/console api:doc:dump --format=yaml --server-url "http://example.com/api" > api.yaml + For example to generate a static version of your documentation you can use: .. code-block:: bash diff --git a/Tests/Command/DumpCommandTest.php b/Tests/Command/DumpCommandTest.php index eb2bfbe..9d82f38 100644 --- a/Tests/Command/DumpCommandTest.php +++ b/Tests/Command/DumpCommandTest.php @@ -42,8 +42,14 @@ class DumpCommandTest extends WebTestCase { $output = $this->executeDumpCommand([ '--format' => 'yaml', + '--server-url' => 'http://example.com/api', ]); - self::assertStringContainsString($this->getOpenApiDefinition()->toYaml(), $output); + $expectedYaml = <<