cloudcreativity / laravel-json-api

JSON API (jsonapi.org) package for Laravel applications.
http://laravel-json-api.readthedocs.io/en/latest/
Apache License 2.0
780 stars 109 forks source link

PATCH with relationships error #402

Closed bbprojectnet closed 5 years ago

bbprojectnet commented 5 years ago

Let's consider that PATCH request:

{
    "data": {
        "type": "identities",
        "id": "1",
        "attributes": {
            "email": "jane.doe@example.com"
        },
        "relationships": {
            "groups": {
                "data": [
                    {
                        "type": "groups",
                        "id": "3"
                    }
                ]
            }
        }
    }
}

...everything is fine, record is updated with relationship groups.

But, if we make a mistake and forget array in relationships.groups.data:

{
    "data": {
        "type": "identities",
        "id": "1",
        "attributes": {
            "email": "jane.doe@example.com"
        },
        "relationships": {
            "groups": {
                "data": {
                    "type": "groups",
                    "id": "3"
                }               
            }
        }
    }
}

we get error: Expecting relationship to have a data member that is an array. at (...)\vendor\cloudcreativity\laravel-json-api\src\Adapter\AbstractRelationshipAdapter.php:77

I write some validator rules to avoid this but i think this should by validated by library itselfy, like other things, eg.: ID as string, data as object, non existing relation object etc.

Btw. Great library! Good job! :)

bbprojectnet commented 5 years ago

I found same issue here: https://github.com/cloudcreativity/laravel-json-api/issues/335 Sorry for a duplicate.

lindyhopchris commented 5 years ago

Ah no problem. The work around for the moment is to add the validation rules, as described in that issue. I'll fix it for 2.0 as it'll require some interface changes.

As this is a duplicate issue, I'll close this one.