-
Notifications
You must be signed in to change notification settings - Fork 112
Fix for field validation on nested sub-resources #231
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
Conversation
|
Hi @pakali , it seems that there are some failing tests. Can you come online at |
|
Hi @Dragomir-Ivanov, tests fails because this commit change logic of application, application after this commit ignore fields that doesnt exists in Schema (so if you pass in tests additional non-exist field as base field then the error doesn't occured and data will be processed by application). This need to be discussed. You cannot reproduce this problem on older version of rest-layer (like ca3afb7) because there is no nested sub-resources there. I will join to #slack soon and we will discuss this problem. |
|
@pakali There were nested sub-resources before, however they are linked with |
There is problem only with saving data on endpoint like: |
|
Okay, I can't say for certain, but can you remove your |
|
When I removed references then I get error: I will read about schema.Connection and give you answer about result of this case. |
|
Hmm, |
|
I will check this problem with some old version of rest-layer and |
|
Can you put your Go source somewhere, along with the |
|
Sure: After that: |
|
Hi @pakali It seems that your code doesn't work even for the commit ID I gave you, before my work was merged. I will try your fix and think about if it is reasonable, or there is some more deeper work to be done. Good catch! |
|
I got your code working @pakali . I don't claim that this is the right way to fix it, however it is a starting point to work on. @pakali Here is the code: |
|
Thanks for this, both fixes yours and mine working fine, probably your fix is more proper one. |
|
Yes @pakali , I think the same. But lets wait for some input from the owners of the project, since I don't have much insight in this part of the code. |
|
For triple-nested resources, it was always necessary to add all of the outer keys to the inner resource. I.e.: message = schema.Schema{
Fields: schema.Fields{
"id": {
Required: true,
Filterable: true,
Validator: &schema.String{},
},
"users": {
Validator: &schema.Reference{
Path: "users",
},
},
"ticket": {
Validator: &schema.Reference{
Path: "users.tickets",
},
},
},
}By setting the fields ReadOnly, you would avoid items being movable via PATCH or PUT. If we are to allow not having the outer resource in the inner resource (e.g. skipping users), it would be nice if it still worked to do so. Thus the solution should presumably add all route values that are in the resource schema (ignoring other keys). I.e. just updating the last field in the path, is not something I would recommend. This may involve updating some unit-test schemas so that the tests pass. |
|
Sorry for a very late reply on this one. |
Thanks Sindre and don't worry.
you mean the target resource, i.e. the last one in the url path? |
I mean if we do
The last point probably isn't super-important, but would keep current schemas working. What do you think @Dragomir-Ivanov? |
After @Dragomir-Ivanov added nested sub-resources I found that is some issue when you have multiple sub-resources and schema references, for example:
http POST :8080/api/users/[user-id]/tickets/[ticker-id]/messages
Give you error:
Because base is filled by user, and ticket id, in message you dont have user field so error occured. In this case we will check base field exists in resource fields.