[英]FOSRestBundle routes versioning
我想为我的项目实现端点的版本控制。事实证明 FOSRestBundle 的实现不是很清楚,所以我想实现如下:
Symfony 5.4
FOSRestBundle 3
请参见下面的注释。yaml 文件:
v2_controllers:
resource: ../../src/Controller/V2/
type: annotation
prefix: /v2
name_prefix: 'api_v2_'
controllers:
resource: ../../src/Controller/
type: annotation
name_prefix: 'api_'
kernel:
resource: ../../src/Kernel.php
type: annotation
当我运行此命令php bin/console debug:router --show-controllers
我得到以下结果:
..
..
...
api_offer_list GET ANY ANY /offer-list/{productId}/{pageType}/ App\Controller\V2\OfferListV2Controller::offerListAction()
api_v2_offer_list GET ANY ANY /v2/offer-list/{productId}/{pageType}/ App\Controller\V2\OfferListV2Controller::offerListAction()
...
..
您可以看到,由于一些奇怪的原因,新版本也覆盖了旧端点
最后是我的 fos_rest.yaml 配置:
# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest:
param_fetcher_listener: true
在 controller 目录中,您需要创建两个单独的目录,一个用于 v1,另一个用于 v2,这应该可以解决问题。
Controller/
v1/
v2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.