yauhenko / rest-bundle
REST and TypeScript generator for Symfony 6
Installs: 1 118
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
Requires (Dev)
- doctrine/doctrine-bundle: ^2.2
- doctrine/doctrine-migrations-bundle: ^3.0
- doctrine/orm: ^2.9
- sensio/framework-extra-bundle: ^6.0
- symfony/security-bundle: 6.0.*
- symfony/serializer: ^6.0
- symfony/validator: ^6.0
README
Step 1: Run
composer req yauhenko/rest-bundle
Step 2: Add to config/routes/annotations.yaml
two lines:
rest_bundle: resource: '@RestBundle/config/routes.yaml'
It will register /docs
routes
Step 3: Create Types class in src/Types.php
:
<?php namespace App; use Yauhenko\RestBundle\TypesInterface; use Yauhenko\RestBundle\Service\TypeScript; class Types implements TypesInterface { public static function registerTypes(TypeScript $ts): void { // register custom types here (optional) $ts->registerTypeOf('TBadge', ['notifications', 'shop']); // register interfaces $ts->registerInterfacesFromDir(__DIR__ . '/Entity'); $ts->registerInterfacesFromDir(__DIR__ . '/Models'); } public static function codePostProcessor(string $code): string { // change generated TypeScript code here (optional) return $code; } }
You can change path to Types class using yauhenko.rest.types_class
parameter in config/services.yaml
Step 4 (optional): Configure config/services.yaml
:
parameters: # Enable TypeScript generation (default: true) yauhenko.rest.ts_enabled: '%env(bool:API_TS_ENABLED)%' # Types class (default) yauhenko.rest.types_class: 'App\Types' # Path to controllers (default) yauhenko.rest.controllers_dir: '%kernel.project_dir%/src/Controller'