Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
dunglas opened this Issue · 4 comments

3 participants

@dunglas

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
Owner

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
Owner

@Elexy another ticket you could have a look at.

@Elexy

Ok

@lsmith77
Owner

see #549

@lsmith77 lsmith77 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.