From 2c78994c08d61fc9589d0633b7ba21c16d5f4c75 Mon Sep 17 00:00:00 2001 From: Nicolas Ruflin Date: Mon, 23 Sep 2019 15:34:44 +0200 Subject: [PATCH] Change empty search response from null to [] (#111) So far if the filter on the `/search` endpoint returned no results, it returned `null`. To still have an array type, it should return `[]` instead. This changes the behaviour. --- CHANGELOG.md | 2 ++ search.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d10a35e5..be5303050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +* Change empty /search API output from `null` to `[]`. + ### Deprecated ### Removed diff --git a/search.go b/search.go index 8e1f91cbf..5f7b3720c 100644 --- a/search.go +++ b/search.go @@ -147,5 +147,10 @@ func getPackageOutput(packagesList map[string]map[string]util.Package) ([]byte, output = append(output, data) } + // Instead of return `null` in case of an empty array, return [] + if len(output) == 0 { + return []byte("[]"), nil + } + return json.MarshalIndent(output, "", " ") }