-
Notifications
You must be signed in to change notification settings - Fork 114
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 requests removes required fields with default values #174
Comments
For 0.2, do what ever is simplest. E.g. rejecting with 422 is fine for now if that's easier. |
HTTP PUT is expected to be idempotent, so it makes sense calling it multiple times to return the same result ( filling the missing required with default values ). I will look around. |
I think this should go as follows:
We document that behavior in the README. Does it sounds plausible @smyrman ? |
I think it's important not to mimic PATCH behaviors, so I think it probably should not matter if a field is required or not for weather or not the original value is kept. I think that for most cases, what makes sense is to error if a required field without a default is missing, and to always set defaults for all fields, no matter if they are required or not. There are however some odd cases, and I will get back to at least one of those. Consider a schema (pseudo notation):
For a sequence of PUT requests, this are the responses/results I think make the most sense:
Or if we are passing a type the first time:
But now, I will come to the difficult part... What about we adding a field "createTime"? new schema:
In this speical-case I want the createTime to be kept.
So to sum that up, I think the best semantics are:
Ther may be more edge cases we are missing, but it would be a lot better than the current behaviour. The next big question is, how easy is it to implement this the current code base. As a limitation of scope, I don;t think we can't easily solve this for sub fields of nested FieldValidators atm. (schema.Dict, schema.AnyOf, schema.AllOf, schema.Object); Those probably need to be addressed by #192 and #77. Longer term we should probably support at least AnyOf and AllOff clauses... But if we can solve it at the top level, that would be a great start never the less. For our own code, we have disabled PUT (via middleware), so that we can prevent users from being able to clear fields that they should not be allowed to clear according to the schema. If the fields are used as part of determining access, that would be a potential attack surface. |
I also need to add, that a perfectly valid solution for now, at least as far as I am concerned, could be not to allow PUT request to do an update at all; they are allowed as a method of creating new objects, but for UPDATE, they return a HTTP 501 Not Implemented. That addresses any security and data-corruption concerns, and people can still do updates via PATCH. |
I agree with that, but it is a REST convention, that you can update the whole document with PUT, where any missing fields, are deleted from original document(unlike PATCH, where missing fields stay as is in the original document). |
For me, ( |
I don't disagreee @Dragomir-Ivanov; I am just stating that removing On Basically, if checking |
If I PUT a new resource at
/resourcepath/myid
, It will set non-provided required fields with the specifiedDefault
values. If I do another PUT request against the same URL with the same body, required fields that are not part of the body gets cleared away...I would instead have expected one of:
I believe 2 is the most correct / desirable thing to do, or to put it in other words; the least wrong thing to do. This would still "reset" fields that are not in the body to their default values, but that seams acceptable, and in some cases even desirable. It must of course be documented that this is what happens.
Case 1 is also much better than the current behaviour, but can not guarantee that a second PUT request will work just because the first one did, which if nothing else, is vert convenient.
Rest-layer versions:
Relevant references:
The text was updated successfully, but these errors were encountered: