[英]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.