laminas-api-tools / api-tools-hal

Laminas Module providing Hypermedia Application Language assets and rendering
https://api-tools.getlaminas.org/documentation
BSD 3-Clause "New" or "Revised" License
6 stars 12 forks source link

Collection Name in response of POST_COLLECTION falls back to default value "items" #40

Open ppaulis opened 1 year ago

ppaulis commented 1 year ago

Bug Report

Q A
Version(s) 1.9.0

Summary

When creating multiple entities in a POST_COLLECTION request, the name of the collection in the HAL response is the default name items instead of the Collection Name defined in the Interface.

Current behavior

Example:

{
  "_links": {
    "self": {
      "href": "..."
    },
    "first": {
      "href": "..."
    },
    "last": {
      "href": "..."
    }
  },
  "_embedded": {
    "items": [ <========================= Uses default value "items" instead of Collection Name
      {
        "id": "..."
      }
    ]
  },
  "page_count": 1,
  "page_size": 30,
  "total_items": 3,
  "page": 1
}

Looking at the module.config.php file, the collection_name is present in the api-tools-rest section and it's used for GET collection calls :

'api-tools-rest' => array(
    'tms\\V1\\Rest\\MyController\\Controller' => array(
            'listener' => '...',
            'route_name' => '...',
            'route_identifier_name' => '...',
            'collection_name' => 'myCollection',

However the POST collection call doesn't use this key/value pair.

If, on the other hand, I manually add the collection_name to the Metadata Map, then the collection name is set correctly:

'api-tools-hal' => array(
        'metadata_map' => array(
            'tms\\V1\\Rest\\MyResource\\MyResourceCollection' => array(
                'entity_identifier_name' => 'id',
                'route_name' => '...',
                'route_identifier_name' => '...',
                'is_collection' => true,
                'collection_name' => 'myCollection'
            ),

How to reproduce

Create multiple entities in a single POST call.

Expected behavior

I would expect the collection name of the POST_COLLECTION response to match the collection_name from the api-tools-rest section of the module.config.php file.

Thanks and best regards, Pascal