diff --git a/CHANGELOG.md b/CHANGELOG.md index b8d5f89..0400f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ - `check`: removed subcommands of `check` command, unifying both into the parent command - `repo`: reorganized commands that change repo config: renamed/created `config auth`, `config description`, and `config headers` commands +### Fixed + +- return "application/tm+json" as MIME type when fetching TMs via API + ## [v0.1.1] ### Added diff --git a/api/tm-catalog.openapi.yaml b/api/tm-catalog.openapi.yaml index 5da534f..48addb4 100644 --- a/api/tm-catalog.openapi.yaml +++ b/api/tm-catalog.openapi.yaml @@ -268,7 +268,7 @@ paths: **For the schema of the returned Thing Model see** [Thing Model JSON schema](https://github.com/w3c/wot-thing-description/blob/main/validation/tm-json-schema-validation.json) content: - application/json: + application/tm+json: schema: type: object '400': @@ -355,7 +355,7 @@ paths: **For the schema of the returned Thing Model see** [Thing Model JSON schema](https://github.com/w3c/wot-thing-description/blob/main/validation/tm-json-schema-validation.json) content: - application/json: + application/tm+json: schema: type: object '400': diff --git a/internal/app/http/common.go b/internal/app/http/common.go index c71f4c5..8c27eed 100644 --- a/internal/app/http/common.go +++ b/internal/app/http/common.go @@ -35,6 +35,7 @@ const ( HeaderXContentTypeOptions = "X-Content-Type-Options" MimeText = "text/plain" MimeJSON = "application/json" + MimeTMJSON = "application/tm+json" MimeOctetStream = "application/octet-stream" MimeProblemJSON = "application/problem+json" NoSniff = "nosniff" diff --git a/internal/app/http/handler.go b/internal/app/http/handler.go index 34b48df..5b15008 100644 --- a/internal/app/http/handler.go +++ b/internal/app/http/handler.go @@ -93,7 +93,7 @@ func (h *TmcHandler) GetThingModelByFetchName(w http.ResponseWriter, r *http.Req return } - HandleByteResponse(w, r, http.StatusOK, MimeJSON, data) + HandleByteResponse(w, r, http.StatusOK, MimeTMJSON, data) } // GetInventoryByID returns the metadata of a single TM by ID @@ -127,7 +127,7 @@ func (h *TmcHandler) GetThingModelById(w http.ResponseWriter, r *http.Request, i return } - HandleByteResponse(w, r, http.StatusOK, MimeJSON, data) + HandleByteResponse(w, r, http.StatusOK, MimeTMJSON, data) } // DeleteThingModelById Delete a Thing Model by ID diff --git a/internal/app/http/handler_test.go b/internal/app/http/handler_test.go index 036f404..0b8cae2 100644 --- a/internal/app/http/handler_test.go +++ b/internal/app/http/handler_test.go @@ -646,7 +646,7 @@ func Test_FetchThingModel(t *testing.T) { // when: calling the route rec := testutils.NewRequest(http.MethodGet, route).RunOnHandler(httpHandler) // then: it returns status 200 - assertResponse200(t, rec) + assertResponseTM200(t, rec) assert.Equal(t, tmContent, rec.Body.Bytes()) }) @@ -655,7 +655,7 @@ func Test_FetchThingModel(t *testing.T) { // when: calling the route rec := testutils.NewRequest(http.MethodGet, route+"?restoreId=false").RunOnHandler(httpHandler) // then: it returns status 200 - assertResponse200(t, rec) + assertResponseTM200(t, rec) assert.Equal(t, tmContent, rec.Body.Bytes()) }) t.Run("with true restoreId", func(t *testing.T) { @@ -663,7 +663,7 @@ func Test_FetchThingModel(t *testing.T) { // when: calling the route rec := testutils.NewRequest(http.MethodGet, route+"?restoreId=true").RunOnHandler(httpHandler) // then: it returns status 200 - assertResponse200(t, rec) + assertResponseTM200(t, rec) assert.Equal(t, tmContent, rec.Body.Bytes()) }) t.Run("with invalid restoreId", func(t *testing.T) { @@ -1266,6 +1266,11 @@ func assertResponse200(t *testing.T, rec *httptest.ResponseRecorder) { assert.Equal(t, MimeJSON, rec.Header().Get(HeaderContentType)) } +func assertResponseTM200(t *testing.T, rec *httptest.ResponseRecorder) { + assert.Equal(t, http.StatusOK, rec.Code) + assert.Equal(t, MimeTMJSON, rec.Header().Get(HeaderContentType)) +} + func assertResponse201(t *testing.T, rec *httptest.ResponseRecorder) { assert.Equal(t, http.StatusCreated, rec.Code) assert.Equal(t, MimeJSON, rec.Header().Get(HeaderContentType))