citizen63000 / easy-api-bundle
Complete API bundle to create easily your API
Installs: 1 382
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 3
Open Issues: 10
Type:symfony-bundle
Requires
- php: ^8.3
- ext-fileinfo: *
- citizen63000/easy-api-core: ^2.0|dev-main
- doctrine/annotations: ^1.13
- doctrine/common: ^3.3
- doctrine/doctrine-bundle: ^2.7
- doctrine/orm: ^2.7
- doctrine/persistence: ^3.0
- fakerphp/faker: v1.23.1
- friendsofsymfony/rest-bundle: ^3.1
- lexik/jwt-authentication-bundle: ^v3.1.0
- nelmio/api-doc-bundle: 4.10.1
- nelmio/cors-bundle: ^2.2
- ramsey/uuid-doctrine: ^1.8
- sensio/framework-extra-bundle: ^v6.2
- stof/doctrine-extensions-bundle: ^1.7
- symfony/asset: ^6.4
- symfony/console: ^6.4
- symfony/dotenv: ^6.4
- symfony/expression-language: ^6.4
- symfony/form: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/monolog-bundle: ^3.8
- symfony/process: ^6.4
- symfony/security-bundle: ^6.4
- symfony/serializer: ^6.4
- symfony/templating: ^6.4
- symfony/translation: ^6.4
- symfony/twig-bundle: ^6.4
- symfony/validator: ^6.4
- symfony/yaml: ^6.4
- vich/uploader-bundle: ^1.21
Requires (Dev)
- friendsofphp/php-cs-fixer: @stable
- guzzlehttp/psr7: ^1.3
- php-http/guzzle6-adapter: ^1.1
- phpunit/php-code-coverage: 9.*
- phpunit/phpunit: 9.*
- symfony/phpunit-bridge: ^3.0
- dev-master
- 4.0.1
- 4.0
- 3.2.9
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.1
- 3.1
- 3.0
- 2.0.1
- 2.0
- 1.x-dev
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1
- 1.0
- 0.90
- 0.88
- 0.87
- 0.86.1
- 0.86
- 0.85.1
- 0.85
- 0.84.5
- 0.84.4
- 0.84.3
- 0.84.2
- 0.84.1
- 0.84
- 0.83.1
- 0.82.2
- 0.82.1
- 0.82
- 0.81
- 0.80
- 0.79
- 0.78
- 0.77
- 0.76
- 0.75
- 0.74
- 0.73
- 0.72
- 0.71
- 0.70
- 0.69
- 0.68
- 0.67
- 0.66
- 0.65
- 0.64
- 0.63
- 0.62
- 0.61
- 0.60
- 0.59
- 0.58
- 0.57
- 0.56
- 0.55
- 0.54
- 0.53
- 0.52
- 0.51
- 0.50
- 0.49
- 0.48
- 0.47
- 0.46
- 0.45
- 0.44
- 0.43
- 0.42
- 0.41
- 0.40
- 0.39
- 0.38
- 0.37
- 0.36
- 0.35
- 0.34
- 0.33
- 0.32
- 0.31
- 0.30
- 0.29
- 0.28
- 0.27
- 0.26
- 0.25
- 0.24
- 0.23
- 0.22
- 0.21
- 0.20
- 0.18
- 0.17
- 0.16
- 0.15
- 0.14
- 0.13
- 0.12
- 0.11
- 0.10
- dev-sf6.4
- dev-php8
- dev-sf4
- dev-sf5
- dev-controllers_naming_flex
- dev-nelmio_apidoc_4
- dev-flex_light
- dev-flex_test
- dev-flex
- dev-sf4_idp
- dev-sf4_serializer_service
- dev-serializer_cache
- dev-validation_groups_validation_alternative
- dev-lae_filters
- dev-tests_with_login
This package is not auto-updated.
Last update: 2024-11-18 15:44:39 UTC
README
Symfony bundle to easily make api, inspired by work of DarwinOnLine
CRUD controllers :
Exemple :
/** * @Route("/my-path", name="my_path") * @OA\Tag(name="MyEntity") */ class MyEntityCrudController extends AbstractApiController { public const entityClass = MyEntity::class; public const entityCreateTypeClass = MyEntityType::class; public const entityUpdateTypeClass = MyEntityType::class; public const serializationGroups = ['my_entity_full']; public const listSerializationGroups = ['my_entity_light']; public const filterFields = []; public const filterSortFields = []; use CrudControllerTrait; }
CRUD routing :
Example:
api_my_path: resource: "@AppBundle/Controller/MyContext/MyController.php" type: annotation
Configuration (everything is optionnal) :
easy_api: authentication: true user_class: AppBundle\Entity\User\User user_tracking : enable: false connection_history_class: AppBundle\Entity\User\ConnectionHistory inheritance: entity: 'App\Entity\AbstractEntity' entityReferential: 'App\Entity\AbstractReferential' form: 'App\Form\Type\AbstractCoreType' repository: 'App\Form\Type\AbstractRepository' controller: 'App\Controller\AbstractApiController' serialized_form: 'App\Form\Model\SerializedForm' tests: debug: true # true by default datetime_format: 'Y-m-d H:i:s' # DateTimeInterface::ATOM format by default
Form options for frontend apps :
You can specify some options in attr field of form fields:
- group : to group fields
- discriminator
- other options you want to pass
API-DOC Annotations
You can use all annotations of the nelmio api bundle. The DoctrineAnnorationReader cannot read self and static constants but with this bundle you can use it as strings in two cases as long as the issue isn't closed :
In Nelmio model annotation:
/** * Get entity. * * @OA\Annotations\Response( * response=200, * description="Successful operation", * @OA\Annotations\Schema( * ref=@Nelmio\ApiDocBundle\Annotation\Model( * type="static::entityClass", * groups={"static::serializationGroups"} * ) * ) * ), * @param Request $request * * @return Response */ public function getAction(Request $request) { ... }
And in an annotation named "GetFormParameter" which allows you to generate api-doc of form fields as get parameters :
/** * List entities. * * @EasyApiBundle\Annotation\GetFormParameter(type="static::entitySearchTypeClass") * ... */ public function listAction(Request $request) { ... }
Test framework
User assertion:
Define it in php static::$additionalAssessableFunctions
and implement it, with good parameters :
static::$additionalAssessableFunctions = ['assertMyAssertion']; ... /** * @param $key The key in response * @param $parameter The parameter passed (optionnal) * @param $value The value in response */ protected static function assertMyAssertion($key, $parameter, $value): void { $parameter = $parameter ?? 'John'; $expected = "hello world $parameter"; $errorMessage = "Invalid value for {$key} field: expected {$expected}, get {$value}"; static::assertTrue($expected === $value, $errorMessage); }
Performance optimization
- Implement the Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface on normalizers (see https://symfony.com/doc/current/serializer/custom_normalizer.html)
- see https://symfony.com/doc/4.4/performance.html