Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUT behavior is not setting Defaults when replacing item #226

Closed
apuigsech opened this issue Jan 8, 2019 · 5 comments
Closed

PUT behavior is not setting Defaults when replacing item #226

apuigsech opened this issue Jan 8, 2019 · 5 comments

Comments

@apuigsech
Copy link
Contributor

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"
}
@Dragomir-Ivanov
Copy link
Contributor

Dragomir-Ivanov commented Jan 8, 2019

Try making that field (Required,Default). #206

@apuigsech
Copy link
Contributor Author

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!

@Dragomir-Ivanov
Copy link
Contributor

Dragomir-Ivanov commented Jan 8, 2019

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.

@Dragomir-Ivanov
Copy link
Contributor

@apuigsech Should we close this, or you have something to add?

@apuigsech
Copy link
Contributor Author

We can close it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants