API: ensure empty build cache is represented as empty JSON array

Ensure empty `BuildCache` field is represented as empty JSON array(`[]`)
instead of `null` to be consistent with `Images`, `Containers` etc.

Signed-off-by: Roman Volosatovs <roman.volosatovs@docker.com>
This commit is contained in:
Roman Volosatovs 2021-07-08 13:12:13 +02:00
parent 5e4da6cc82
commit f2225933bb
No known key found for this signature in database
GPG key ID: 216DD5F8CA6618A1
2 changed files with 6 additions and 0 deletions

View file

@ -120,6 +120,11 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter,
du.BuilderSize = builderSize
du.BuildCache = buildCache
if buildCache == nil {
// Ensure empty `BuildCache` field is represented as empty JSON array(`[]`)
// instead of `null` to be consistent with `Images`, `Containers` etc.
du.BuildCache = []*types.BuildCache{}
}
return httputils.WriteJSON(w, http.StatusOK, du)
}

View file

@ -8339,6 +8339,7 @@ paths:
UsageData:
Size: 10920104
RefCount: 2
BuildCache: []
500:
description: "server error"
schema: