4

I upgraded my FOSUserBundle to 2.4 from 2.1 while I was upgrading my project to Symfony 3.4 from 2.8.

With the same code that worked before, and this yml file:

# app/config/routing.yml
api_request_backend:
    type: rest
    prefix: /api
    resource: "@AppBundle/Resources/config/default.yml"

-

# AppBundle/Resources/config/default.yml
api:
    type: rest    # This resource will have RESTful routes
    prefix:
    resource: "@AppBundle\Controller\ApiController"
    name_prefix: api_
apiV2:
    type: rest    # This resource will have RESTful routes
    prefix: /v2
    resource: "@AppBundle\Controller\ApiV2Controller"
    name_prefix: api_v2_
api_user:
    type: rest    # This resource will have RESTful routes
    prefix:
    resource: "@AppBundle\Controller\ApiUserController"
    name_prefix: api_

I receive this error:

Exception thrown when handling an exception (Symfony\Component\Config\Exception\FileLoaderLoadException: The file "/var/www/project/src/AppBundle/Resources/config/default.yml" does not contain valid YAML in /var/www/project/src/AppBundle/Resources/config/default.yml (which is being imported from "/var/www/project/app/config/routing.yml"). Make sure there is a loader supporting the "rest" type.)

Where am I wrong? I also tried to downgrade FOSRestBundle to 2.3.1 (I read this here) but nothing changes.

cezar
  • 11,616
  • 6
  • 48
  • 84
NicolaPez
  • 567
  • 1
  • 4
  • 27
  • I tried to enhance the formatting (indentation) of your code, but there are missing values for `prefix` in two occasions. That couldn't work. Would you please take a look at your code example and eventually correct those two lines? – cezar Oct 30 '18 at 11:29
  • the prefix field are not required, the solution below works right with null values. – NicolaPez Oct 30 '18 at 15:29
  • 2
    thanks! I struggle with the same error. Your question and answer are valuable resources. – cezar Oct 30 '18 at 15:32

2 Answers2

2

For newest (>3.0) you must change the route type from rest to annotation.

IndyDevGuy
  • 126
  • 5
1

The issue is the invalid YAML. The following works:

# app/config/routing.yml
api_request_backend:
    type: rest
    prefix: /api
    resource: '@AppBundle/Resources/config/default.yml' 

and

# AppBundle/Resources/config/default.yml
api:
    type: rest    # This resource will have RESTful routes
    resource: '@AppBundle\Controller\ApiController'
    name_prefix: api_

thanks to xabbuh for the fix

cezar
  • 11,616
  • 6
  • 48
  • 84
NicolaPez
  • 567
  • 1
  • 4
  • 27
  • The only relevant change I see is converting the double quotes to single quotes. Was that really the solution or I'm missing something more important here. – cezar Oct 30 '18 at 11:27
  • yes, with the upgrade the double quotes are not valid – NicolaPez Oct 30 '18 at 15:15