-
Notifications
You must be signed in to change notification settings - Fork 8
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
PATCH accepts all valid json bodies #186
Comments
Right now, the API accepts anything, by design. Data validation should be performed by the clients. The only way I can see supporting server-side schema validation is if it can be implemented such that it is:
And implementing that would take quite a lot of effort - so much that it is unlikely there will be any change of this in 2023. In the meantime I suggest you implement schema validation in your API client. |
I think, given that you have made an endpoint to patch data, you will likely be setting yourselves up for getting lots of users having done this incorrectly and messing up their data. Once the data for a submission no longer follows the forms metadata, it also breaks the Nettskjema webui loader (not in all cases, but in certain formats). |
Maybe so, that does not change the timeline for any API-side implementation though, so I still suggest adding schema validation to your tool. |
Adding validation to pysquril: unioslo/pysquril#60 will enable this. |
Note: To force nettskjema submissions to follow the forms metadata, it would require a custom schema for each form (plus updates whenever the metadata gets updated) |
So we have two generic JSON schemas atm: one for submissions, and another for form metadata. I was thinking that all submissions and all instances of form metadata would be compliant with the aforementioned schemas. Is that not correct? Having submissions follow form metadata is something else than JSON schema validation, correct? |
Yes, correct. Also the submission schema is composed of mini schemas - one for each type of answer (attachment, checkbox, ...). Currently the nettskjema portal validates against the submission schema whenever edits to a submission are made.
Hmm, not necessarily. It would be possible to generate a more specific submission schema from the metadata. The current generic schema allows all possible types for any key. But with info from the metadata, we could generate a schema that would, for example, say "key |
Ok TL;Dr, my point was just that schema validation might not solve the issue Mo mentioned unless we do additional stuff |
I see, thanks for the info. In terms of the scope of unioslo/pysquril#60 it sounds like pysquril should implement running an arbitrary function on input data before insert and updates - something that raises a generic exception like a It would then be up to the library user to implement the required logic. In this case, the file/survey API could then do the domain specific work of preparing the relevant schema/mini schema, and pass that along with a validator function to pysquril. Or maybe unioslo/pysquril#6 is not needed at all? Don't have the full picture yet... |
@uio-torjus and I have drawn up a plan:
|
the patch submissions endpoint accepts all json bodies that are in the format
The problem arises when the provided json keys do not exist in the form they are being submitted to, this results with data for this one submission that no longer adheres to the rest of the forms data. I.e. this submission is incompatible with the rest of the data.
In the nettskjema loader (web ui) inside TSD, this means the data for this submission looks empty. It means also accessing the data from the API, this one submission has data that cannot be appended to the rest, as its incompatible.
example, given the true data are as above, if someone submits
status return is 201, data is successfully updated. And this is the data I can receive from the API. But I cannot add it to the remaining form data, as these are column keys that dont exist in the rest.
This might be particularly important to think about because of the nested structure for checkboxes and matrices.
if the true data are
and you submit
status is 201, data is sent. But no longer compatible with the remaining data. And I can see this happening for the nested data easily.
It would be ideal if there was some sort of API validation towards the forms metadata that stops incorrectly formatted patch data to be accepted.
The text was updated successfully, but these errors were encountered: