Sylius: API Grouping bug with Hateoas.

Created on 31 Jul 2015  ·  14Comments  ·  Source: Sylius/Sylius

Hi, All
I can't serialize api by using groups feature of JMS serializer, Anyone can solve this problem.

I found related issue: https://github.com/willdurand/Hateoas/issues/141

cc. @pjedrzejewski @aRn0D

Potential Bug

All 14 comments

I found the solution by that issue's comments https://github.com/willdurand/Hateoas/issues/141#issuecomment-37234651 and https://github.com/willdurand/Hateoas/issues/141#issuecomment-104926272

but we need to change a bit yaml snippet like:

Hateoas\Representation\PaginatedRepresentation:
    custom_accessor_order: [page, limit, pages, total]
    relations:
      - rel: self
        href:
          route: expr(object.getRoute())
          # parameters should get out from object.getParameters()
          parameters: expr(object.getParameters())
          absolute: expr(object.isAbsolute())
        exclusion:
          groups: [Hateoas]
      - rel: first
        href:
          route: expr(object.getRoute())
          parameters: expr(object.getParameters(1))
          absolute: expr(object.isAbsolute())
        exclusion:
          groups: [Hateoas]
      - rel: last
        href:
          route: expr(object.getRoute())
          parameters: expr(object.getParameters(object.getPages()))
          absolute: expr(object.isAbsolute())
        exclusion:
          groups: [Hateoas]
          exclude_if: expr(object.getPages() === null)
      - rel: next
        href:
          route: expr(object.getRoute())
          parameters: expr(object.getParameters(object.getPage()+1))
          absolute: expr(object.isAbsolute())
        exclusion:
          groups: [Hateoas]
          exclude_if: expr(object.getPages() !== null && (object.getPage() + 1) > object.getPages())
      - rel: previous
        href:
          route: expr(object.getRoute())
          parameters: expr(object.getParameters(object.getPage()-1))
          #absolute: true
          absolute: expr(object.isAbsolute())
        exclusion:
          groups: [Hateoas]
          exclude_if: expr((object.getPage() - 1) < 1)
    properties:
        page:
            expose: true
            groups: [Hateoas]
        limit:
            expose: true
            groups: [Hateoas]
        pages:
            expose: true
            groups: [Hateoas]
        total:
            expose: true
            groups: [Hateoas]

PS. We need to add this to Sylius-Core?

@liverbool Did you fix this problem?

@lchrusciel Yes, By adding new serializer yaml mapping file same as my comment above.
screen shot 2558-12-09 at 19 00 25

But nobody fixed it in Sylius, I suppose.

I thinks yes.

Hello,
is this on track for the 1.0 stable release?

Is anyone with more API knowledge willing to take this one? :)

following those steps seem sufficient: I've done it and don't see any drawback, but I'm not an expert :
https://github.com/willdurand/Hateoas/issues/141#issuecomment-104926272
https://github.com/willdurand/Hateoas/issues/141#issuecomment-37234651
https://github.com/willdurand/Hateoas/issues/141#issuecomment-287052292

NB : just think that in case of inheritance, all class have to me mapped (you cannot defined the parent class serialize rules in the child)

@bruno-ds would you like to contribute it to Sylius? :)

@pamil : this gist https://gist.github.com/dsbaars/56be85286ebf4f89e4d4 contains each files except the conf. Telling JMS serializer to look for a custom dir for a given namespace.

As Liverbol asked : is it to be put in the core?

This issue is related more to HATEOAS and reconfigured serialization of pagination, then to Sylius itself. The same way we would override current Sylius mapping. In general, groups are working(we have tests for that). Probably can be closed and some FAQ section would be a good place for this thread.

already fixed by vendor.

Solution using https://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies#overriding-groups-of-deeper-branches-of-the-graph

sylius_admin_api_product_index:
    path: /api/v{version}/products/
    methods: [GET]
    defaults:
        _controller: sylius.controller.product:indexAction
        _sylius:
            grid: sylius_admin_api_product
            serialization_groups: { 0: Default, items: [ Autocomplete ] }
            serialization_version: $version

The groups passed to items key will be applied to the collection items, i.e. product objects in this example

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mezoni picture mezoni  ·  3Comments

loic425 picture loic425  ·  3Comments

xleliberty picture xleliberty  ·  3Comments

eb22fbb4 picture eb22fbb4  ·  3Comments

javiereguiluz picture javiereguiluz  ·  3Comments