Laravel-json-api: Incorrect pointer in validation error when the attribute wasn't include in the request body.

Created on 7 Mar 2019  路  1Comment  路  Source: cloudcreativity/laravel-json-api

My rule is "'customer_id' => "required|string|min:10"", when I use wrong value for it, the pointer is correct,
{
"status": "422",
"title": "Unprocessable Entity",
"detail": "The customer id must be at least 10 characters.",
"source": {
"pointer": "/data/attributes/customer_id"
}
}
but if the value of customer_id was not set in the request body, the pointer only shows "/data",
{
"status": "422",
"title": "Unprocessable Entity",
"detail": "The customer id field is required.",
"source": {
"pointer": "/data"
}
}

Is this wrong or it should be like this?

question

Most helpful comment

Is this correct.

If the field foo is required, and is not present in the JSON sent by the client, it would be invalid to give them a JSON pointer of /data/attributes/foo because that is pointing to a field that does not exist in their JSON.

Instead /data is accurate, because the resource object that is at /data is invalid as it is missing a required field. So /data points to the field that is invalid in their request.

Note that this only applies if the field is not present in their request data. For example, if they sent a null value for foo, the field foo would exist in their request so a pointer to /data/attributes/foo is accurate.

>All comments

Is this correct.

If the field foo is required, and is not present in the JSON sent by the client, it would be invalid to give them a JSON pointer of /data/attributes/foo because that is pointing to a field that does not exist in their JSON.

Instead /data is accurate, because the resource object that is at /data is invalid as it is missing a required field. So /data points to the field that is invalid in their request.

Note that this only applies if the field is not present in their request data. For example, if they sent a null value for foo, the field foo would exist in their request so a pointer to /data/attributes/foo is accurate.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GregPeden picture GregPeden  路  5Comments

JeanLucEsser picture JeanLucEsser  路  6Comments

featurecode picture featurecode  路  3Comments

osteel picture osteel  路  3Comments

lindyhopchris picture lindyhopchris  路  6Comments