Fosrestbundle: Unrecognized option "media_type" under "fos_rest.format_listener" since 2.0

Created on 27 Jun 2016  路  5Comments  路  Source: FriendsOfSymfony/FOSRestBundle

Since upgrading your bundle to v2.0, I get the following error:

  [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]  
  Unrecognized option "media_type" under "fos_rest.format_listener"              


Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception


  [RuntimeException]                                                                 
  An error occurred when executing the "'cache:clear --no-warmup'" command:          

    [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]    
    Unrecognized option "media_type" under "fos_rest.format_listener"                

  .                                                                                  

I searched media_type on your UPGRADING-2.0.md note, but nothing about that.

My actual configuration:

fos_rest:
    routing_loader:
        default_format: json
    body_converter:
        enabled: true
        validate: true
    serializer:
        serialize_null: true
    view:
        formats:
            xml:  false
            json: true
            rss:  false
            yml:  true
        view_response_listener: force
    param_fetcher_listener: force
    format_listener:
        rules:
            - { path: '^/api/', priorities: ['json', 'yml'], fallback_format: json, prefer_extension: true }
            - { path: '^/', stop: true } # FOSRest should not handle other routes than API
        media_type:
            enabled: true

Mistake? Forgotten note?

Thanks.

Most helpful comment

Ok for anyone having the same issue, here is the right config:

fos_rest:
    routing_loader:
        default_format: json
    body_converter:
        enabled: true
        validate: true
    serializer:
        serialize_null: true
    view:
        formats:
            xml:  false
            json: true
            rss:  false
            yml:  true
        view_response_listener: force
    param_fetcher_listener: force
    format_listener:
        rules:
            - { path: '^/api/', priorities: ['json', 'yml'], fallback_format: json, prefer_extension: true }
            - { path: '^/', stop: true } # FOSRest should not handle other routes than API
    versioning:
        enabled: true
        resolvers:
            media_type:
                enabled: true

All 5 comments

I saw the deprecation message here: https://github.com/FriendsOfSymfony/FOSRestBundle/compare/1.8.0...2.0.0#diff-ffb88a00253e285e14e0d32ef5423cd1L198

But this does not get so much information.

Ok for anyone having the same issue, here is the right config:

fos_rest:
    routing_loader:
        default_format: json
    body_converter:
        enabled: true
        validate: true
    serializer:
        serialize_null: true
    view:
        formats:
            xml:  false
            json: true
            rss:  false
            yml:  true
        view_response_listener: force
    param_fetcher_listener: force
    format_listener:
        rules:
            - { path: '^/api/', priorities: ['json', 'yml'], fallback_format: json, prefer_extension: true }
            - { path: '^/', stop: true } # FOSRest should not handle other routes than API
    versioning:
        enabled: true
        resolvers:
            media_type:
                enabled: true

Indeed, we forgot this in our UPGRADING file... Thanks !

can someone update the upgrading file and then close this ticket?

Was this page helpful?
0 / 5 - 0 ratings