From 4f0fddbe1238861d7d4ba45b7dfce325304839c5 Mon Sep 17 00:00:00 2001 From: Chris Hung Date: Wed, 19 Apr 2023 10:32:24 +0800 Subject: [PATCH] feat!: update API version to v3 BREAKING CHNAGE: all EdgeX base API version is changed to v3 closes #774 Signed-off-by: Chris Hung --- common/constants.go | 10 +++++----- dtos/event_test.go | 2 +- dtos/metric_test.go | 4 +++- dtos/requests/device_test.go | 11 ++++++----- dtos/requests/devicecommand_test.go | 2 +- dtos/requests/deviceprofilebasicinfo_test.go | 11 ++++++----- dtos/requests/deviceresource_test.go | 2 +- dtos/requests/deviceservice_test.go | 6 +++--- dtos/requests/interval_test.go | 6 +++--- dtos/requests/intervalaction_test.go | 6 +++--- dtos/requests/provisionwatcher_test.go | 8 ++++---- 11 files changed, 36 insertions(+), 32 deletions(-) diff --git a/common/constants.go b/common/constants.go index f0a3957a..41fd9091 100644 --- a/common/constants.go +++ b/common/constants.go @@ -6,10 +6,10 @@ package common -// Constants related to defined routes in the v2 service APIs +// Constants related to defined routes in the v3 service APIs const ( - ApiVersion = "v2" - ApiBase = "/api/v2" + ApiVersion = "v3" + ApiBase = "/api/v3" ApiEventRoute = ApiBase + "/event" ApiEventServiceNameProfileNameDeviceNameSourceNameRoute = ApiEventRoute + "/{" + ServiceName + "}" + "/{" + ProfileName + "}" + "/{" + DeviceName + "}" + "/{" + SourceName + "}" @@ -131,7 +131,7 @@ const ( ApiMultiConfigRoute = ApiSystemRoute + "/config" ) -// Constants related to defined url path names and parameters in the v2 service APIs +// Constants related to defined url path names and parameters in the v3 service APIs const ( All = "all" Id = "id" @@ -185,7 +185,7 @@ const ( RegexCommand = "ds-regexcmd" //query string to specify if the command name is in regular expression format ) -// Constants related to the default value of query strings in the v2 service APIs +// Constants related to the default value of query strings in the v3 service APIs const ( DefaultOffset = 0 DefaultLimit = 20 diff --git a/dtos/event_test.go b/dtos/event_test.go index 2192ad30..3d76317f 100644 --- a/dtos/event_test.go +++ b/dtos/event_test.go @@ -92,7 +92,7 @@ func TestEvent_ToXML(t *testing.T) { } // Since the order in map is random we have to verify the individual items exists without depending on order contains := []string{ - "v27a1707f0-166f-4c4b-bc9d-1d54c74e0137TestDeviceTestDeviceProfileNameTestSourceName1594963842", + "v37a1707f0-166f-4c4b-bc9d-1d54c74e0137TestDeviceTestDeviceProfileNameTestSourceName1594963842", "Houston-0001", "29.630771", "-95.377603", diff --git a/dtos/metric_test.go b/dtos/metric_test.go index 774366ca..ff1e46ce 100644 --- a/dtos/metric_test.go +++ b/dtos/metric_test.go @@ -21,11 +21,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/edgexfoundry/go-mod-core-contracts/v3/common" ) func TestNewMetric(t *testing.T) { expectedTimestamp := time.Now().UnixNano() - expectedApiVersion := "v2" + expectedApiVersion := common.ApiVersion expectedName := "my-metric" validFields := []MetricField{ diff --git a/dtos/requests/device_test.go b/dtos/requests/device_test.go index 4554ba7e..8123e718 100644 --- a/dtos/requests/device_test.go +++ b/dtos/requests/device_test.go @@ -8,11 +8,12 @@ package requests import ( "encoding/json" "fmt" + "testing" + "github.com/edgexfoundry/go-mod-core-contracts/v3/common" "github.com/edgexfoundry/go-mod-core-contracts/v3/dtos" dtoCommon "github.com/edgexfoundry/go-mod-core-contracts/v3/dtos/common" "github.com/edgexfoundry/go-mod-core-contracts/v3/models" - "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -360,9 +361,9 @@ func TestUpdateDeviceRequest_Validate(t *testing.T) { func TestUpdateDeviceRequest_UnmarshalJSON_NilField(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", - "device":{"apiVersion":"v2", "name":"TestDevice"} + "device":{"apiVersion":"v3", "name":"TestDevice"} }` var req UpdateDeviceRequest @@ -385,10 +386,10 @@ func TestUpdateDeviceRequest_UnmarshalJSON_NilField(t *testing.T) { func TestUpdateDeviceRequest_UnmarshalJSON_EmptySlice(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", "device":{ - "apiVersion":"v2", + "apiVersion":"v3", "name":"TestDevice", "labels":[], "autoEvents":[] diff --git a/dtos/requests/devicecommand_test.go b/dtos/requests/devicecommand_test.go index 0aba982d..a0d898bd 100644 --- a/dtos/requests/devicecommand_test.go +++ b/dtos/requests/devicecommand_test.go @@ -148,7 +148,7 @@ func TestUpdateDeviceCommandRequest_Validate(t *testing.T) { func TestUpdateDeviceCommandRequest_UnmarshalJSON_NilField(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", "profileName": "TestProfile", "deviceCommand":{"name":"TestCommand"} diff --git a/dtos/requests/deviceprofilebasicinfo_test.go b/dtos/requests/deviceprofilebasicinfo_test.go index bc52512b..9da12745 100644 --- a/dtos/requests/deviceprofilebasicinfo_test.go +++ b/dtos/requests/deviceprofilebasicinfo_test.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2022 IOTech Ltd +// Copyright (C) 2022-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -8,12 +8,13 @@ package requests import ( "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/edgexfoundry/go-mod-core-contracts/v3/common" "github.com/edgexfoundry/go-mod-core-contracts/v3/dtos" dtoCommon "github.com/edgexfoundry/go-mod-core-contracts/v3/dtos/common" "github.com/edgexfoundry/go-mod-core-contracts/v3/models" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var testBasicInfoRequest = DeviceProfileBasicInfoRequest{ @@ -114,7 +115,7 @@ func TestDeviceProfileBasicInfoRequest_Validate(t *testing.T) { func TestDeviceProfileBasicInfoRequest_UnmarshalJSON_NilField(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", "basicinfo": { "name": "TestProfile" @@ -134,7 +135,7 @@ func TestDeviceProfileBasicInfoRequest_UnmarshalJSON_NilField(t *testing.T) { func TestDeviceProfileBasicInfoRequest_UnmarshalJSON_EmptySlice(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", "basicinfo": { "name": "TestProfile", diff --git a/dtos/requests/deviceresource_test.go b/dtos/requests/deviceresource_test.go index 24e4284f..d65dbd06 100644 --- a/dtos/requests/deviceresource_test.go +++ b/dtos/requests/deviceresource_test.go @@ -146,7 +146,7 @@ func TestUpdateDeviceResourceRequest_Validate(t *testing.T) { func TestUpdateDeviceResourceRequest_UnmarshalJSON_NilField(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", "profileName": "TestProfile", "resource":{"name":"TestResource"} diff --git a/dtos/requests/deviceservice_test.go b/dtos/requests/deviceservice_test.go index f376f63f..d7a4aabe 100644 --- a/dtos/requests/deviceservice_test.go +++ b/dtos/requests/deviceservice_test.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020-2021 IOTech Ltd +// Copyright (C) 2020-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -283,10 +283,10 @@ func TestUpdateDeviceServiceRequest_UnmarshalJSON_NilField(t *testing.T) { func TestUpdateDeviceServiceRequest_UnmarshalJSON_EmptySlice(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", "service":{ - "apiVersion":"v2", + "apiVersion":"v3", "name":"TestDevice", "labels":[] } diff --git a/dtos/requests/interval_test.go b/dtos/requests/interval_test.go index 3d1032c6..3aeadd24 100644 --- a/dtos/requests/interval_test.go +++ b/dtos/requests/interval_test.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2021 IOTech Ltd +// Copyright (C) 2021-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -230,9 +230,9 @@ func TestUpdateIntervalRequest_Validate(t *testing.T) { func TestUpdateIntervalRequest_UnmarshalJSON_NilField(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", - "interval":{"apiVersion":"v2", "name":"TestInterval"} + "interval":{"apiVersion":"v3", "name":"TestInterval"} }` var req UpdateIntervalRequest diff --git a/dtos/requests/intervalaction_test.go b/dtos/requests/intervalaction_test.go index 8da4857d..2fc44217 100644 --- a/dtos/requests/intervalaction_test.go +++ b/dtos/requests/intervalaction_test.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2021 IOTech Ltd +// Copyright (C) 2021-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -245,9 +245,9 @@ func TestUpdateIntervalActionRequest_Validate(t *testing.T) { func TestUpdateIntervalActionRequest_UnmarshalJSON_NilField(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", - "action":{"apiVersion":"v2", "name":"TestIntervalAction", "intervalName": "afternoon"} + "action":{"apiVersion":"v3", "name":"TestIntervalAction", "intervalName": "afternoon"} }` var req UpdateIntervalActionRequest diff --git a/dtos/requests/provisionwatcher_test.go b/dtos/requests/provisionwatcher_test.go index e6d7845b..eb603019 100644 --- a/dtos/requests/provisionwatcher_test.go +++ b/dtos/requests/provisionwatcher_test.go @@ -291,9 +291,9 @@ func TestUpdateProvisionWatcherRequest_Validate(t *testing.T) { func TestUpdateProvisionWatcherRequest_UnmarshalJSON_NilField(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", - "provisionWatcher":{"apiVersion" : "v2","name":"test-watcher"} + "provisionWatcher":{"apiVersion" : "v3","name":"test-watcher"} }` var req UpdateProvisionWatcherRequest @@ -313,10 +313,10 @@ func TestUpdateProvisionWatcherRequest_UnmarshalJSON_NilField(t *testing.T) { func TestUpdateProvisionWatcherRequest_UnmarshalJSON_EmptySlice(t *testing.T) { reqJson := `{ - "apiVersion" : "v2", + "apiVersion" : "v3", "requestId":"7a1707f0-166f-4c4b-bc9d-1d54c74e0137", "provisionWatcher":{ - "apiVersion" : "v2", + "apiVersion" : "v3", "name":"test-watcher", "labels":[], "discoveredDevice":{