简体   繁体   English

FOSRestBundle 路由版本控制

[英]FOSRestBundle routes versioning

I wanted to implement versioning of endpoints for my project.. turns out the FOSRestBundle implementation is not quite clear so I wanted to implement like follow:我想为我的项目实现端点的版本控制。事实证明 FOSRestBundle 的实现不是很清楚,所以我想实现如下:

Symfony 5.4 Symfony 5.4

FOSRestBundle 3 FOSRestBundle 3

see below annotation.yaml file:请参见下面的注释。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

when I run this command php bin/console debug:router --show-controllers I get the following result:当我运行此命令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()            
...
..

You can see that the new version is also overriding the older endpoint for some weird reasons您可以看到,由于一些奇怪的原因,新版本也覆盖了旧端点

and finally here's my fos_rest.yaml config:最后是我的 fos_rest.yaml 配置:

# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest:
    param_fetcher_listener:  true

Inside the controller directory, you need to create two separate directories, one for v1 and the other for v2 and this should solve the problem.在 controller 目录中,您需要创建两个单独的目录,一个用于 v1,另一个用于 v2,这应该可以解决问题。

Controller/
    v1/
    v2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM