Skip to content

Commit

Permalink
Omit items if empty in object list response (#1266)
Browse files Browse the repository at this point in the history
GCS does not include the `items` attribute in the response from the
[object list][1] operation when it is empty (i.e., when there are no
objects). With this commit we emulate that behavior.

Example responses from GCS:

```shell
$ curl 'https://storage.googleapis.com/storage/v1/b/<MY-BUCKET>/o/?prefix=nonexistent_path' -H "Authorization: Bearer <MY-TOKEN>"
{
  "kind": "storage#objects"
}
```

```shell
$ curl 'https://storage.googleapis.com/storage/v1/b/<MY-BUCKET>/o/?delimiter=%2F&prefix=only_dirs_inside%2F' -H "Authorization: Bearer <MY-TOKEN>"
{
  "kind": "storage#objects",
  "prefixes": [
    "only_dirs_inside/a_dir/"
  ]
}
```

[1]: https://cloud.google.com/storage/docs/json_api/v1/objects/list
  • Loading branch information
manuteleco authored Jul 29, 2023
1 parent 6f4a5c2 commit 0a4d05f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fakestorage/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func formatTime(t time.Time) string {

type listResponse struct {
Kind string `json:"kind"`
Items []any `json:"items"`
Items []any `json:"items,omitempty"`
Prefixes []string `json:"prefixes,omitempty"`
}

Expand Down

0 comments on commit 0a4d05f

Please sign in to comment.