mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Enable overriding server url for yaml and json export from console
This commit is contained in:
parent
181f4b2763
commit
1a21f1855e
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 = <<<YAML
|
||||
servers:
|
||||
-
|
||||
url: 'http://example.com/api'
|
||||
YAML;
|
||||
self::assertStringContainsString($expectedYaml, $output);
|
||||
}
|
||||
|
||||
/** @dataProvider provideAssetsMode */
|
||||
|
Loading…
x
Reference in New Issue
Block a user