willdurand / BazingaHateoasBundle

Integration of the Hateoas library into Symfony.
MIT License
294 stars 59 forks source link

Setting $limitParameterName doesn't impact limit property name #47

Open mickaelmagniez opened 8 years ago

mickaelmagniez commented 8 years ago

Hello,

When setting $limitParameterName to another value :

public function getMediasAction(ParamFetcher $paramFetcher)
{
    $queryBuilder = $this->getMediaHandler()->all();

    $pagerAdapter = new DoctrineODMMongoDBAdapter($queryBuilder);
    $pager = new Pagerfanta($pagerAdapter);
    $pager->setCurrentPage($paramFetcher->get('page'));
    $pager->setMaxPerPage($paramFetcher->get('hits_per_page'));

    $pagerFactory = new PagerfantaFactory('page', 'hits_per_page');

    return $pagerFactory->createRepresentation(
        $pager,
        new Route('dam_get_medias')
    );
}

Limit property name doesn't change in output :

{
    "page": 1,
    "limit": 2,
    "pages": 214,
    "total": 428,
    "_links": {
        "self": {
            "href": "/app_dev.php/api/medias?page=1&hits_per_page=2"
        },
    },
}

Is this a bug or correct behaviour ?

Best regards

maennchen commented 8 years ago

The limitParameterName is only used when reading and generating url's. It's not used in the serialization of the pager.

You could use JMS to override this name: http://jmsyst.com/bundles/JMSSerializerBundle/master/configuration#overriding-third-party-metadata

serialized_name should do the trick.