PUT behavior is not setting Defaults when replacing item
apuigsech opened this issue · comments
I am trying to fix an issue I found on the SQL Storage Handler (apuigsech/rest-layer-sql#1) and I was able to fix it just partially because seems that REST Layer is not considering some Schema attributes, as the Default, when a PUT is done to replace an element.
Next lines shows how the default value (0 on the 'int' field) is setup when creating the object but not when replacing it;
$ http PUT :8080/units/cgqgksbmvbapo5vtaia0 str="foo"
HTTP/1.1 201 Created
Content-Length: 139
Content-Type: application/json
Date: Tue, 08 Jan 2019 20:40:18 GMT
Etag: W/"56f12b97ab2fd36da3a7e841136a9e9d"
Last-Modified: Tue, 08 Jan 2019 20:40:18 GMT
{
"created": "2019-01-08T21:40:18.051874+01:00",
"id": "cgqgksbmvbapo5vtaia0",
"int": 0,
"str": "foo",
"updated": "2019-01-08T21:40:18.051875+01:00"
}
$ http PUT :8080/units/cgqgksbmvbapo5vtaia0 str="foo"
HTTP/1.1 200 OK
Content-Length: 131
Content-Type: application/json
Date: Tue, 08 Jan 2019 20:40:21 GMT
Etag: W/"67dda4f6e88d4c99740c50df7ea2e74f"
Last-Modified: Tue, 08 Jan 2019 20:40:21 GMT
{
"created": "2019-01-08T21:40:21.935495+01:00",
"id": "cgqgksbmvbapo5vtaia0",
"str": "foo",
"updated": "2019-01-08T21:40:21.935496+01:00"
}
Try making that field (Required,Default)
. #206
Required and Default sounds like excluding attributes to me, because if the field is required to be provided, the default value should never be used, right? However, I tried to setup both attributes and this is how it went;
$ http -b PUT :8080/units/bgqgksbmvbapo5vtaia0 str="foo"
{
"created": "2019-01-08T22:21:32.816287+01:00",
"id": "bgqgksbmvbapo5vtaia0",
"int": 0,
"str": "foo",
"updated": "2019-01-08T22:21:32.816288+01:00"
}
$ http -b PUT :8080/units/bgqgksbmvbapo5vtaia0 str="foo"
{
"created": "2019-01-08T22:21:37.695354+01:00",
"id": "bgqgksbmvbapo5vtaia0",
"int": 0,
"str": "foo",
"updated": "2019-01-08T22:21:37.695355+01:00"
}
Seems that it's working, but its confusing that field are not really required, even on a POST statement :)
$ http -b POST :8080/units str="foo"
{
"created": "2019-01-08T22:26:18.817044+01:00",
"id": "bgqhaujmvbappgf3fgcg",
"int": 0,
"str": "foo",
"updated": "2019-01-08T22:26:18.817045+01:00"
}
I think that enabling the Required attribute to all those that have Default should fix my issue.
Thanks!
Yeah, I am thinking the same, as we are missing something with these qualifiers. We are open for discussions and ideas how to fix these. Discussion at #174.
@apuigsech Should we close this, or you have something to add?
We can close it :)