PersonalSnippet update with files support
What does this MR do?
This MR adds support for a new parameter called files to the PersonalSnippet REST API update endpoint.
This will add support for updating multiple files when the snippet_multiple_files feature flag is enabled (or removed in future).
Refs #217763 (closed)
As can be seen in the referenced issue, we need to have some form of backwards compatibility for API users using the "old" fields (file_name and content instead of files). To achieve this, we are allowing those parameters to be used, unless the snippet has multiple files already.
This is because we cannot rely on just those fields for update actions against a snippet with multiple files (because we need to know which file is being updated).
The field rules this MR should implement are:
-
filesrequired if FF on (or removed) and Snippet has multiple files -
file_name&contentallowed if FF off or Snippet has only a single file -
filesrequiresactionand at least one of eitherfile_pathorprevious_path -
filesandfile_name/contentare mutually exclusive
No changelog or docs changes have been added because although the files parameter will be available to be used in this MR, support for multiple files is still behind a feature flag. We have an issue to track the addition of the docs for this, here: #217808 (closed)
Testing
The following is an example curl request you can make to test this endpoint:
curl --request PUT \
--data '{ "title": "Testing Update", "files": [{"action": "create", "file_path": "testing.md","content": "my content"}]}' \
--header 'Content-Type: application/json' \
--header "PRIVATE-TOKEN: <Your Access Token>" \
"http://127.0.0.1:3000/api/v4/snippets/1"