check24 / apitk-deprecation-bundle
该组件提供RESTful API的弃用功能。
Requires
- php: ^7.4 || ^8.0
- check24/apitk-common-bundle: ^2.2 || ^3.0
- check24/apitk-header-bundle: ^2.2 || ^3.0
- doctrine/annotations: ^1.6
- nelmio/api-doc-bundle: ^3.2
- sensio/framework-extra-bundle: ^5.1 || ^6.0
- symfony/config: >= 5.3 <6.0
- symfony/dependency-injection: >= 5.3 <6.0
- symfony/framework-bundle: >= 5.3 <6.0
- symfony/http-kernel: >= 5.3 <6.0
Requires (Dev)
- captainhook/captainhook: ^5.0
- captainhook/plugin-composer: ^5.1
- friendsofphp/php-cs-fixer: ^2.12
- phpmd/phpmd: ^2.6
- phpstan/phpstan: ^0.12
This package is auto-updated.
Last update: 2024-09-05 01:07:58 UTC
README
概览
此组件使您能够标记API端点为弃用,并向客户端通知。
安装
通过composer安装包
composer require check24/apitk-deprecation-bundle
使用
弃用
您可以标记操作为弃用,以便开发者注意到他们必须更新API调用到较新版本或使用全新的端点。
use Shopping\ApiTKDeprecationBundle\Annotation\Deprecated; /** * Returns the users in the system. * * @Rest\Get("/v2/users") * @Rest\View() * * @Deprecated(removedAfter="2018-10-09", since="2018-07-01", description="use /v3/users instead") * @param User[] $users * @return User[] */
在swagger文档内部显示通知,并将新的响应头x-apitk-deprecated: use /v3/users instead
、x-apitk-deprecated-removed-at: 2018-10-09
(如果设置了日期),x-apitk-deprecated-since: 2018-07-01
(如果设置了日期)发送到客户端。
所有注解参数都是可选的,因此您可以只使用@Deprecated
。在这种情况下,所有客户端都将收到一个x-apitk-deprecated: deprecated
的响应头。该头的值可以通过提供上述示例中的description
参数来覆盖。
如果您想从文档中隐藏特定的端点,请使用hideFromDocs=true
参数在Deprecated
注解中。相应的操作将不会显示。
类注解
从版本1.0.6开始,可以在Controller的类上放置@Deprecated
注解,以标记所有包含的端点为弃用。
请注意,方法注解总是完全覆盖类注解。不会进行合并或其他操作。当一个控制器类有@Deprecated
注解时,不可能标记控制器的一个或多个方法为非弃用。
弃用日志记录
从版本2.0.0开始,当调用弃用端点时,apitk-deprecation-bundle将抛出E_USER_DEPRECATED
错误。当您使用NewRelic等APM工具,并希望在被调用弃用端点时收到通知时,这很有用。
弃用日志记录默认是激活的。您可以通过创建一个包含以下内容的config/packages/apitk_deprecation.yaml
全局禁用它:
apitk_deprecation: trigger_deprecations: false # default: true
您还可以只为特定的端点激活/禁用弃用日志记录
/** * Always log deprecations for this route or class, ignoring global settings: * @Deprecated(description="use /v3/users instead", triggerDeprecation=true) * * Never log deprecations for this route or class, ignoring global settings: * @Deprecated(description="use /v3/users instead", triggerDeprecation=false) * ... */