Install the Package
composer require cnd-api-maker/symfony
Ensure cnd-api-maker/core is also installed (required dependency).
Configure the Bundle
Add the bundle to config/bundles.php:
return [
// ...
Cnd\ApiMaker\Symfony\CndApiMakerBundle::class => ['all' => true],
];
Create a JDL File
Define your entities and relationships in a .jdl file (e.g., src/main/resources/example.jdl):
entity Employee {
firstName String required
lastName String required
}
Generate Code Run the console command to generate entities, repositories, and optionally API Platform resources:
php bin/console cnd:api-maker:generate --input=src/main/resources/example.jdl
Verify Output
Check the generated files in src/Entity/, src/Repository/, and optionally src/ApiResource/ (if API Platform is enabled).
Generate a CRUD API for an Employee Entity
Employee entity (as above).config/packages/api_platform.yaml (if needed):
api_platform:
formats:
jsonld:
mime_types: ['application/ld+json']
php bin/console cnd:api-maker:generate --input=src/main/resources/example.jdl --with-api-platform
/api/employees (or /api/employee if singular naming is configured).--overwrite to regenerate files without losing custom logic in non-generated blocks (e.g., add @ORM\GeneratedValue to an auto-increment field).
php bin/console cnd:api-maker:generate --input=example.jdl --overwrite
--with-api-platform to generate API resources, DTOs, and filters.ApiResource classes to add custom serialization groups or metadata:
// src/ApiResource/EmployeeApiResource.php (generated)
public function getOperations(EntityManagerInterface $manager): array
{
$reflection = new \ReflectionClass($this);
return [
new Get(),
new Post(
input: 'App\\ApiResource\\Dto\\EmployeeInput',
output: $reflection->getName() . 'Output'
),
// ...
];
}
--with-fixtures to create Doctrine fixtures for testing:
php bin/console cnd:api-maker:generate --input=example.jdl --with-fixtures
tests/Entity/ to bootstrap test suites.vendor/cnd-api-maker/symfony/templates to templates/cnd-api-maker in your project.Cnd\ApiMaker\Core\Generator\AbstractGenerator and register them in the Symfony bundle’s configuration.Cnd\ApiMaker\Symfony\Generator\Generator to trigger generation programmatically:
use Cnd\ApiMaker\Symfony\Generator\Generator;
class MyCommand extends Command {
public function __construct(private Generator $generator) {}
protected function execute(InputInterface $input, OutputInterface $output): int {
$this->generator->generateFromFile('path/to/file.jdl');
return Command::SUCCESS;
}
}
php bin/console make:migration && php bin/console doctrine:migrations:migrate
api_platform.yaml to control:
enable_pagination).resource_classes).formats).cnd.api_maker.generate events to run custom logic after generation:
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Cnd\ApiMaker\Symfony\Event\GenerateEvent;
class MySubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents(): array {
return [
'cnd.api_maker.generate' => 'onGenerate',
];
}
public function onGenerate(GenerateEvent $event) {
// Modify generated files or trigger side-effects
}
}
Template Overrides
templates/cnd-api-maker may not be picked up if the bundle’s cache is not cleared.php bin/console cache:clear after adding new templates.API Platform Conflicts
api-platform/core installed will fail silently.api-platform/core is required in composer.json if using --with-api-platform.JDL Parsing Errors
Overwriting Custom Code
@generated docblocks to mark auto-generated sections and avoid editing them:
/**
* @generated This code is auto-generated by Cnd API Maker. Do not edit manually.
*/
Doctrine Annotations vs. Attributes
use Doctrine\ORM\Mapping as ORM; (annotations) instead of attributes (#[ORM\...]).config/packages/cnd_api_maker.yaml:
cnd_api_maker:
use_attributes: true
Verbose Output Enable debug mode for the generator:
php bin/console cnd:api-maker:generate --input=example.jdl --debug
Dry Run Test generation without writing files:
php bin/console cnd:api-maker:generate --input=example.jdl --dry-run
Log Generation Steps Enable Symfony’s debug toolbar to inspect the generator’s internal state during execution.
Partial Generations
Use --entity to generate only specific entities:
php bin/console cnd:api-maker:generate --input=example.jdl --entity=Employee
Environment-Specific Configs
Override generator settings per environment (e.g., dev vs. prod) in config/packages/cnd_api_maker.yaml:
when@dev:
cnd_api_maker:
with_fixtures: true
with_tests: true
JDL Includes
Reuse JDL snippets across projects by using include directives:
include ../shared/jdl/common_entities.jdl
entity Project {
name String required
}
Custom Naming Strategies
Override default naming conventions (e.g., pluralization) by extending Cnd\ApiMaker\Core\Naming\NamingStrategy and configuring it in the bundle.
Performance For large JDL files, pre-compile templates to reduce generation time:
php bin/console cnd:api-maker:compile-templates
How can I help you explore Laravel packages today?