FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 703 forks source link

symfony FOS Rest bundle verisoning is not working #1958

Closed elangosundar closed 4 years ago

elangosundar commented 5 years ago

I have tried the symfony4 with fos bundle rest api versioning and api versioning alone is not working. Please find my below code and i have missed out anything.

**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;
    }
}

My Url :

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

when we accessing the above urls always returning the same set of reults v1.

Tobion commented 4 years ago

Your example is missing the controller for v2. Also you are setting condition: "request.attributes.get('version') == 'v1'" on the route which overwrites the @Version("v1") annotation on the controller. So there is likely a conflict. Closing as the @Version annotation is deprecated (#1954)