Installation:
composer require bigz/api-doc-dumper-bundle --dev
Ensure the package is listed in config/bundles.php under the dev environment:
return [
// ...
Bigz\ApiDocDumperBundle\BigzApiDocDumperBundle::class => ['dev' => true],
];
First Use Case: Run the dump command to generate an OpenAPI spec JSON file:
bin/console dump:api-doc
Outputs apidoc.json in your project root (customizable via --file argument).
Prerequisites:
@ApiResource or configured in NelmioApiDoc.CI/CD Pipeline:
dump:api-doc in your CI (e.g., GitHub Actions) to auto-generate docs on dev pushes.- name: Generate API Docs
run: php bin/console dump:api-doc --file=public/api-docs.json
Custom Output Paths:
public/ for web access:
bin/console dump:api-doc --file=public/api-docs.json
bin/console dump:api-doc --file=${API_DOCS_PATH:-apidoc.json}
Symfony Flex Integration:
nelmio/api-doc-bundle is installed first:
composer require nelmio/api-doc-bundle --dev
Scheduled Dumps:
CronBundle or a custom command to regenerate docs nightly:
# config/packages/cron.yaml
cron:
jobs:
dump_api_docs:
command: 'app:console dump:api-doc'
schedule: '0 3 * * *'
Versioned Docs:
apidoc-v1.json) and update in README.md:
bin/console dump:api-doc --file=docs/api/v1/apidoc-v1.json
Missing NelmioApiDoc:
Command "dump:api-doc" not found.nelmio/api-doc-bundle first:
composer require nelmio/api-doc-bundle --dev
Empty Output:
@ApiResource or configured in NelmioApiDoc.bin/console debug:router and check for missing annotations.Outdated Dependencies:
File Permissions:
Permission denied when writing to project root.bin/console dump:api-doc --file=var/api-docs.json
Verbose Output:
-v flag to debug:
bin/console dump:api-doc -v
Validate OpenAPI:
apidoc.json.Customize NelmioApiDoc:
config/packages/nelmio_api_doc.yaml to filter routes:
nelmio_api_doc:
areas: # Use areas to restrict routes
path_patterns:
- ^/api(?!/internal)
Post-Processing:
// Example: Minify JSON with Node.js
const fs = require('fs');
fs.readFile('apidoc.json', (err, data) => {
fs.writeFile('apidoc.min.json', JSON.stringify(JSON.parse(data)), () => {});
});
Custom Command:
// src/Command/DumpApiDocWithGit.php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DumpApiDocWithGit extends Command {
protected function execute(InputInterface $input, OutputInterface $output) {
$this->getApplication()->find('dump:api-doc')->run(
$input,
$output
);
// Add Git logic here (e.g., commit changes)
}
}
Dynamic File Naming:
// config/services.yaml
App\Command\CustomDumpApiDocCommand::tags: ['console.command']
// src/Command/CustomDumpApiDocCommand.php
namespace App\Command;
use Bigz\ApiDocDumperBundle\Command\DumpApiDocCommand;
use Symfony\Component\Console\Input\InputOption;
class CustomDumpApiDocCommand extends DumpApiDocCommand {
protected function configure() {
$this->addOption('file', null, InputOption::VALUE_REQUIRED, 'Custom filename', sprintf('apidoc-%s.json', date('YmdHis')));
}
}
Integration with API Gateways:
curl -X POST --data-binary @apidoc.json http://gateway/api-docs
How can I help you explore Laravel packages today?