From f543e7accc36d768bee784ead37c7a6c58a707bf Mon Sep 17 00:00:00 2001 From: Deluan Date: Mon, 27 Nov 2023 13:25:06 -0500 Subject: [PATCH] Fix getOpenSubsonicExtensions endpoint Match the current doc: https://opensubsonic.netlify.app/docs/endpoints/getopensubsonicextensions/ openSubsonicExtensions must be an array, not a struct --- ...nicExtensions with data should match .JSON | 16 ++++++++++ ...onicExtensions with data should match .XML | 6 ++++ ...Extensions without data should match .JSON | 8 +++++ ...cExtensions without data should match .XML | 1 + server/subsonic/responses/responses.go | 9 ++++-- server/subsonic/responses/responses_test.go | 30 +++++++++++++++++++ 6 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions with data should match .JSON create mode 100644 server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions with data should match .XML create mode 100644 server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions without data should match .JSON create mode 100644 server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions without data should match .XML diff --git a/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions with data should match .JSON b/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions with data should match .JSON new file mode 100644 index 000000000..5e8b33ae3 --- /dev/null +++ b/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions with data should match .JSON @@ -0,0 +1,16 @@ +{ + "status": "ok", + "version": "1.8.0", + "type": "navidrome", + "serverVersion": "v0.0.0", + "openSubsonic": true, + "openSubsonicExtensions": [ + { + "name": "template", + "versions": [ + 1, + 2 + ] + } + ] +} diff --git a/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions with data should match .XML b/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions with data should match .XML new file mode 100644 index 000000000..587eda70d --- /dev/null +++ b/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions with data should match .XML @@ -0,0 +1,6 @@ + + + 1 + 2 + + diff --git a/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions without data should match .JSON b/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions without data should match .JSON new file mode 100644 index 000000000..143bd1f80 --- /dev/null +++ b/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions without data should match .JSON @@ -0,0 +1,8 @@ +{ + "status": "ok", + "version": "1.8.0", + "type": "navidrome", + "serverVersion": "v0.0.0", + "openSubsonic": true, + "openSubsonicExtensions": [] +} diff --git a/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions without data should match .XML b/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions without data should match .XML new file mode 100644 index 000000000..651d6df0d --- /dev/null +++ b/server/subsonic/responses/.snapshots/Responses OpenSubsonicExtensions without data should match .XML @@ -0,0 +1 @@ + diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.go index 87f9fa508..07c3b07f0 100644 --- a/server/subsonic/responses/responses.go +++ b/server/subsonic/responses/responses.go @@ -424,13 +424,18 @@ type JukeboxPlaylist struct { JukeboxStatus Entry []Child `xml:"entry,omitempty" json:"entry,omitempty"` } -type OpenSubsonicExtensions struct{} +type OpenSubsonicExtension struct { + Name string `xml:"name,attr" json:"name"` + Versions []int32 `xml:"versions" json:"versions"` +} + +type OpenSubsonicExtensions []OpenSubsonicExtension -// OpenSubsonic response type for multi-valued genres list type ItemGenre struct { Name string `xml:"name,attr" json:"name"` } +// ItemGenres holds a list of genres (OpenSubsonic). If it is null, it must be marshalled as an empty array. type ItemGenres []ItemGenre func (i ItemGenres) MarshalJSON() ([]byte, error) { diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.go index 6fc95270c..14cc2d26c 100644 --- a/server/subsonic/responses/responses_test.go +++ b/server/subsonic/responses/responses_test.go @@ -725,6 +725,36 @@ var _ = Describe("Responses", func() { }) }) + Describe("OpenSubsonicExtensions", func() { + BeforeEach(func() { + response.OpenSubsonic = true + response.OpenSubsonicExtensions = &OpenSubsonicExtensions{} + }) + + Describe("without data", func() { + It("should match .XML", func() { + Expect(xml.MarshalIndent(response, "", " ")).To(MatchSnapshot()) + }) + It("should match .JSON", func() { + Expect(json.MarshalIndent(response, "", " ")).To(MatchSnapshot()) + }) + }) + + Describe("with data", func() { + BeforeEach(func() { + response.OpenSubsonicExtensions = &OpenSubsonicExtensions{ + OpenSubsonicExtension{Name: "template", Versions: []int32{1, 2}}, + } + }) + It("should match .XML", func() { + Expect(xml.MarshalIndent(response, "", " ")).To(MatchSnapshot()) + }) + It("should match .JSON", func() { + Expect(json.MarshalIndent(response, "", " ")).To(MatchSnapshot()) + }) + }) + }) + Describe("InternetRadioStations", func() { BeforeEach(func() { response.InternetRadioStations = &InternetRadioStations{}