ClassResourceInterface generates wrong post route name (or there is an error in the doc) #347

Closed
dunglas opened this Issue Dec 29, 2012 · 4 comments

Comments

Projects
None yet
3 participants
@dunglas
Contributor

dunglas commented Dec 29, 2012

Form the doc:

https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/5-automatic-route-generation_single-restful-controller.md

post - this action accepts POST requests to the url /resources and creates a new resource of this type. > Shown as UsersController::postUsersAction() above.

But the generated route is not pluralized and it breaks the RESTful model:

<?php
namespace Dunglas\ChaplinDemoBundle\Controller;

use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;

class PostController extends FOSRestController implements ClassResourceInterface
{
    public function postAction()
    {
    }
}
$ php app/console router:debug post_post
[router] Route "post_post"
Name         post_post
Pattern      /api/post.{_format}
Class        Symfony\Component\Routing\Route
Defaults     _controller: Dunglas\ChaplinDemoBundle\Controller\PostController::postAction
             _format: json
Requirements _method: POST
Options      compiler_class: Symfony\Component\Routing\RouteCompiler
Regex        #^/api/post(?:\.(?P<_format>[^\.]+))?$#s

If you create a cpostAction() action instead a correct pluralized route is generated:

<?php
namespace Dunglas\ChaplinDemoBundle\Controller;

use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;

class PostController extends FOSRestController implements ClassResourceInterface
{
    public function cpostAction()
    {
    }
}
$ php app/console router:debug post_posts
[router] Route "post_posts"
Name         post_posts
Pattern      /api/posts.{_format}
Class        Symfony\Component\Routing\Route
Defaults     _controller: Dunglas\ChaplinDemoBundle\Controller\PostController::cpostAction
             _format: json
Requirements _method: POST
Options      compiler_class: Symfony\Component\Routing\RouteCompiler
Regex        #^/api/posts(?:\.(?P<_format>[^\.]+))?$#s

I don't know if its a bug or an error in the documentation but it must be fixed.

@lsmith77

This comment has been minimized.

Show comment Hide comment
@lsmith77

lsmith77 Jan 3, 2013

Member

i think this is simply an edge case that was never considered. i think the routing layer gets confused by the use of "post" .. but this needs some investigation.

Member

lsmith77 commented Jan 3, 2013

i think this is simply an edge case that was never considered. i think the routing layer gets confused by the use of "post" .. but this needs some investigation.

@lsmith77

This comment has been minimized.

Show comment Hide comment
@lsmith77

lsmith77 Mar 13, 2013

Member

@Elexy another ticket you could have a look at.

Member

lsmith77 commented Mar 13, 2013

@Elexy another ticket you could have a look at.

@Elexy

This comment has been minimized.

Show comment Hide comment
@Elexy

Elexy Mar 13, 2013

Ok

Elexy commented Mar 13, 2013

Ok

@lsmith77

This comment has been minimized.

Show comment Hide comment
@lsmith77

lsmith77 Sep 10, 2013

Member

see #549

Member

lsmith77 commented Sep 10, 2013

see #549

@lsmith77 lsmith77 closed this Sep 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment