-
-
Save dsbaars/56be85286ebf4f89e4d4 to your computer and use it in GitHub Desktop.
| Hateoas\Representation\CollectionRepresentation: | |
| exclusion_policy: all | |
| exclude: false | |
| expose: true | |
| properties: | |
| rel: | |
| exclude: false | |
| expose: true | |
| groups: [ Default, Hateoas ] | |
| resources: | |
| exclude: false | |
| expose: true | |
| groups: [ Default, Hateoas ] |
| Hateoas\Representation\PaginatedRepresentation: | |
| custom_accessor_order: [page, limit, pages, total] | |
| relations: | |
| - rel: self | |
| href: | |
| route: expr(object.getRoute()) | |
| parameters: | |
| parameters: | |
| page: expr(object.getPage()) | |
| _format: json | |
| absolute: expr(object.isAbsolute()) | |
| exclusion: | |
| groups: [Hateoas] | |
| - rel: first | |
| href: | |
| route: expr(object.getRoute()) | |
| parameters: | |
| page: 1 | |
| _format: json | |
| absolute: expr(object.isAbsolute()) | |
| exclusion: | |
| groups: [Hateoas] | |
| - rel: last | |
| href: | |
| route: expr(object.getRoute()) | |
| parameters: | |
| page: expr(object.getPages()) | |
| _format: json | |
| absolute: expr(object.isAbsolute()) | |
| exclusion: | |
| groups: [Hateoas] | |
| exclude_if: expr(object.getPages() === null) | |
| - rel: next | |
| href: | |
| route: expr(object.getRoute()) | |
| parameters: | |
| page: expr(object.getPage()+1) | |
| _format: json | |
| 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: | |
| page: expr(object.getPage()-1) | |
| _format: json | |
| 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] |
| Hateoas\Representation\RouteAwareRepresentation: | |
| properties: | |
| inline: | |
| expose: true | |
| groups: [ Default, Hateoas ] | |
| serialized_name: _embedded |
Hi I did the same but i am getting empty response.
$serializer = HateoasBuilder::create()
->setUrlGenerator(null, $queryStringUrlGenerator)
->addMetadataDir(DIR . '/../Resources/config/serializer/Hateoas', 'Hateoas\Representation')->build()
$collection = new CollectionRepresentation($users);
$json = $serializer->serialize($collection, 'json', SerializationContext::create()->setGroups(['users']));
Metadata FileName:
Representation.CollectionRepresentation.yml
Hateoas\Representation\CollectionRepresentation:
exclusion_policy: none
properties:
id:
type: integer
groups: ['users']
Any suggestions please?
Right CollectionRepresentation.yml looks like this for me:
Hateoas\Representation\CollectionRepresentation:
exclusion_policy: all
expose: true
virtual_properties:
getResources:
serialized_name: items
expose: true
groups: [ Default, Hateoas ]Current PaginatedRepresentation.yml make an issue and any API endpoint throw error when route have any parameter.
For example: Some mandatory parameters are missing (\"productCode\") to generate a URL for route \"sylius_admin_api_product_variant_index\"."
Fixed PaginatedRepresentation.yml should be like this (add page parameters rather than replace them):
Hateoas\Representation\PaginatedRepresentation:
exclusion_policy: ALL
expose: false
custom_accessor_order: [page, limit, pages, total]
relations:
- rel: self
href:
route: expr(object.getRoute())
parameters: "expr(object.getParameters() + {page: object.getPage()})"
absolute: expr(object.isAbsolute())
exclusion:
groups: [ Default, Hateoas ]
- rel: first
href:
route: expr(object.getRoute())
parameters: "expr(object.getParameters() + {page: 1})"
absolute: expr(object.isAbsolute())
exclusion:
groups: [ Default, Hateoas ]
- rel: last
href:
route: expr(object.getRoute())
parameters: "expr(object.getParameters() + {page: object.getPages()})"
absolute: expr(object.isAbsolute())
exclusion:
groups: [ Default, Hateoas ]
exclude_if: expr(object.getPages() === null)
- rel: next
href:
route: expr(object.getRoute())
parameters: "expr(object.getParameters() + {page: object.getPage()+1})"
absolute: expr(object.isAbsolute())
exclusion:
groups: [ Default, Hateoas ]
exclude_if: expr(object.getPages() !== null && (object.getPage() + 1) > object.getPages())
- rel: previous
href:
route: expr(object.getRoute())
parameters: "expr(object.getParameters() + {page: object.getPage()-1})"
absolute: expr(object.isAbsolute())
exclusion:
groups: [ Default, Hateoas ]
exclude_if: expr((object.getPage() - 1) < 1)
properties:
page:
expose: true
groups: [ Default, Hateoas ]
limit:
expose: true
groups: [ Default, Hateoas ]
pages:
expose: true
groups: [ Default, Hateoas ]
total:
expose: true
groups: [ Default, Hateoas ]
Hello,
thank you for this gist, you missed :