symfony4 FOS Rest捆绑验证不起作用

时间:2018-11-19 05:45:06

标签: symfony fosuserbundle symfony4 jms-serializer api-versioning

我已经尝试过 symfony4 和fos bundle rest api版本控制,并且它的url路由有效,但是api版本控制却无效。请找到下面的代码,我什么都错过了。

我的网址:

example.com/v2/api/guesttest
example.com/v1/api/guesttest

当我们访问上述网址时,总是返回相同的结果v1集。

Routes.yml

guest_api:
    path:  /{version}/api/guesttest
    controller: App\Controller\TestController::test1
    condition:  "request.attributes.get('version') == 'v1'"
    requirements: 
        version: 'v1|v2'

fos_rest.yaml

fos_rest:
    param_fetcher_listener:  true
    allowed_methods_listener:  true
    routing_loader: 
        include_format: false
    body_listener: true

    format_listener:
        rules:
            - { path: ^/api, prefer_extension: false, fallback_format: json, priorities: [ json ] }
            - { path: ^/, prefer_extension: true, fallback_format: html, priorities: [ html ] }

    versioning:
        enabled: true
        default_version: v1

TestController.php

/**
 * @Version("v1")
 * @NamePrefix("v1")
 * 
*/

class TestController extends FOSRestController
{
    public function test1() 
    {
         return new Response("success....!");
        exit;
    }
}

jms_serializer.yaml

jms_serializer:
    visitors:
        xml:
            format_output: '%kernel.debug%'

    metadata:
        cache: file
        debug: "%kernel.debug%"
        file_cache:
            dir: "%kernel.cache_dir%/serializer"
        auto_detection: true 

参考链接:

  1. github
  2. Symfony-verioning

0 个答案:

没有答案