summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/controllers/api/v2/file.php6
-rw-r--r--application/test/tests/api_v2/test_file_delete.php15
-rw-r--r--doc/api.md1
-rw-r--r--doc/api/file.md6
4 files changed, 26 insertions, 2 deletions
diff --git a/application/controllers/api/v2/file.php b/application/controllers/api/v2/file.php
index c3a42388b..15a43fc45 100644
--- a/application/controllers/api/v2/file.php
+++ b/application/controllers/api/v2/file.php
@@ -75,7 +75,11 @@ class file extends \controllers\api\api_controller {
{
$this->muser->require_access("apikey");
$ids = $this->input->post_array("ids");
- return \service\files::delete($ids);
+ $ret = \service\files::delete($ids);
+
+ $ret = ensure_json_keys_contain_objects($ret, array("errors", "deleted"));
+
+ return $ret;
}
public function create_multipaste()
diff --git a/application/test/tests/api_v2/test_file_delete.php b/application/test/tests/api_v2/test_file_delete.php
index b4d63409d..d9ffc5b2c 100644
--- a/application/test/tests/api_v2/test_file_delete.php
+++ b/application/test/tests/api_v2/test_file_delete.php
@@ -64,4 +64,19 @@ class test_file_delete extends common {
$this->t->is($ret["data"]["deleted_count"], 0, "deleted_count correct");
}
+ public function test_delete_empty_json_structure()
+ {
+ $apikey = $this->createUserAndApikey();
+ $ret = $this->uploadFile($apikey, "data/tests/small-file");
+ $id = $ret["data"]["ids"][0];
+
+ $ret = $this->CallEndpoint("POST", "file/delete", array(
+ "apikey" => $apikey,
+ "ids[1]" => $id,
+ ), true);
+
+ $this->t->is($ret, '{"status":"success","data":{"errors":{},"deleted":{"'.$id.'":{"id":"'.$id.'"}},"total_count":1,"deleted_count":1}}', "empty lists should be json objects, not arrays");
+ }
+
+
}
diff --git a/doc/api.md b/doc/api.md
index cbdc5bbb9..aee738c88 100644
--- a/doc/api.md
+++ b/doc/api.md
@@ -148,6 +148,7 @@ These are the most common errors that can be returned by any API call.
| Version | Endpoint | Note |
| ------- | -------- | ---- |
| 2.1.1 | file/history | Empty objects (values of `items` and `multipaste_items`) are now always returned as {}. Before they were returned as [] |
+| 2.1.1 | file/delete | Empty objects (values of `errors` and `deleted`) are now always returned as {}. Before they were returned as [] |
| 2.1.0 | file/history | Add ''item.thumbnail'' |
| 2.0.0 | file/history | Add ''multipaste_item.date'' |
| 2.0.0 | file/history | Remove private fields in response |
diff --git a/doc/api/file.md b/doc/api/file.md
index c461caf01..7d95274a3 100644
--- a/doc/api/file.md
+++ b/doc/api/file.md
@@ -230,7 +230,7 @@ Example:
> curl -s $base/file/delete -F apikey=$apikey -F "ids[1]=uu28" | json_pp
{
"data" : {
- "errors" : [],
+ "errors" : {},
"total_count" : 1,
"deleted" : {
"uu28" : {
@@ -243,6 +243,10 @@ Example:
}
```
+| Version | Change |
+| ------- | ------ |
+| 2.1.1 | Empty objects (values of `errors` and `deleted`) are now always returned as {}. Before they were returned as [] |
+
## file/create_multipaste
Required access level: `basic`