citizen63000 / easy-api-bundle
易于创建API的完整API包
4.0.1
2024-09-12 17:07 UTC
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-dependabot/composer/twig/twig-3.14.0
- 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-09-26 17:21:25 UTC
README
Symfony扩展包,可轻松创建API,灵感来源于DarwinOnLine
CRUD控制器
示例
/** * @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路由
示例
api_my_path: resource: "@AppBundle/Controller/MyContext/MyController.php" type: annotation
配置(全部为可选)
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
前端应用表单选项
您可以在表单字段的attr字段中指定一些选项
- group : 用于分组字段
- discriminator
- 您想要传递的其他选项
API-DOC注解
您可以使用nelmio api bundle的所有注解。DoctrineAnnorationReader无法读取self和static常量,但使用此包,您可以在问题未关闭的情况下将其作为字符串使用两种情况。
在Nelmio模型注解中
/** * 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) { ... }
并在一个名为"GetFormParameter"的注解中,它允许您将表单字段的API文档作为GET参数生成
/** * List entities. * * @EasyApiBundle\Annotation\GetFormParameter(type="static::entitySearchTypeClass") * ... */ public function listAction(Request $request) { ... }
测试框架
用户断言
在 php static::$additionalAssessableFunctions
中定义它,并实现它,使用良好的参数
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); }
性能优化
- 在规范化器上实现Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface(请参阅https://symfony.com.cn/doc/current/serializer/custom_normalizer.html)
- 请参阅https://symfony.com.cn/doc/4.4/performance.html