Skip to content

Commit

Permalink
EDX-4765 Remove the DTO name restriction
Browse files Browse the repository at this point in the history
Remove the DTO name restriction as community changes, edgexfoundry/go-mod-core-contracts#853.

Signed-off-by: bruce <weichou1229@gmail.com>
  • Loading branch information
weichou1229 committed Mar 6, 2024
1 parent 8c5a831 commit 306cbdf
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions dtos/corecommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
package dtos

type DeviceCoreCommand struct {
DeviceName string `json:"deviceName" validate:"required,edgex-dto-none-empty-string,edgex-dto-no-reserved-chars"`
ProfileName string `json:"profileName" validate:"required,edgex-dto-none-empty-string,edgex-dto-no-reserved-chars"`
DeviceName string `json:"deviceName" validate:"required,edgex-dto-none-empty-string"`
ProfileName string `json:"profileName" validate:"required,edgex-dto-none-empty-string"`
CoreCommands []CoreCommand `json:"coreCommands,omitempty" validate:"dive"`
}

type CoreCommand struct {
Name string `json:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-no-reserved-chars"`
Name string `json:"name" validate:"required,edgex-dto-none-empty-string"`
Get bool `json:"get,omitempty" validate:"required_without=Set"`
Set bool `json:"set,omitempty" validate:"required_without=Get"`
Path string `json:"path,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions dtos/devicecommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ package dtos
import "github.com/edgexfoundry/go-mod-core-contracts/v3/models"

type DeviceCommand struct {
Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-no-reserved-chars"`
Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string"`
IsHidden bool `json:"isHidden" yaml:"isHidden"`
ReadWrite string `json:"readWrite" yaml:"readWrite" validate:"required,oneof='R' 'W' 'RW' 'WR'"`
ResourceOperations []ResourceOperation `json:"resourceOperations" yaml:"resourceOperations" validate:"gt=0,dive"`
Tags map[string]any `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type UpdateDeviceCommand struct {
Name *string `json:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-no-reserved-chars"`
Name *string `json:"name" validate:"required,edgex-dto-none-empty-string"`
IsHidden *bool `json:"isHidden"`
}

Expand Down
4 changes: 2 additions & 2 deletions dtos/deviceprofilebasicinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package dtos

type DeviceProfileBasicInfo struct {
Id string `json:"id,omitempty" validate:"omitempty,uuid" yaml:"id,omitempty"`
Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-no-reserved-chars"`
Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string"`
Manufacturer string `json:"manufacturer,omitempty" yaml:"manufacturer,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Model string `json:"model,omitempty" yaml:"model,omitempty"`
Expand All @@ -16,7 +16,7 @@ type DeviceProfileBasicInfo struct {

type UpdateDeviceProfileBasicInfo struct {
Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"`
Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string,edgex-dto-no-reserved-chars"`
Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"`
Manufacturer *string `json:"manufacturer"`
Description *string `json:"description"`
Model *string `json:"model"`
Expand Down
4 changes: 2 additions & 2 deletions dtos/deviceservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type DeviceService struct {
DBTimestamp `json:",inline"`
Id string `json:"id,omitempty" validate:"omitempty,uuid"`
Name string `json:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
Name string `json:"name" validate:"required,edgex-dto-none-empty-string"`
Description string `json:"description,omitempty"`
Labels []string `json:"labels,omitempty"`
BaseAddress string `json:"baseAddress" validate:"required,uri"`
Expand All @@ -24,7 +24,7 @@ type DeviceService struct {

type UpdateDeviceService struct {
Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"`
Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"`
Description *string `json:"description"`
BaseAddress *string `json:"baseAddress" validate:"omitempty,uri"`
Labels []string `json:"labels"`
Expand Down
8 changes: 4 additions & 4 deletions dtos/provisionwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
type ProvisionWatcher struct {
DBTimestamp `json:",inline"`
Id string `json:"id,omitempty" yaml:"id,omitempty" validate:"omitempty,uuid"`
Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
ServiceName string `json:"serviceName" yaml:"serviceName" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string"`
ServiceName string `json:"serviceName" yaml:"serviceName" validate:"required,edgex-dto-none-empty-string"`
Labels []string `json:"labels,omitempty" yaml:"labels,omitempty"`
Identifiers map[string]string `json:"identifiers" yaml:"identifiers" validate:"gt=0,dive,keys,required,endkeys,required"`
BlockingIdentifiers map[string][]string `json:"blockingIdentifiers,omitempty" yaml:"blockingIdentifiers,omitempty"`
Expand All @@ -23,8 +23,8 @@ type ProvisionWatcher struct {

type UpdateProvisionWatcher struct {
Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"`
Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
ServiceName *string `json:"serviceName" validate:"omitempty,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"`
Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"`
ServiceName *string `json:"serviceName" validate:"omitempty,edgex-dto-none-empty-string"`
Labels []string `json:"labels"`
Identifiers map[string]string `json:"identifiers" validate:"omitempty,gt=0,dive,keys,required,endkeys,required"`
BlockingIdentifiers map[string][]string `json:"blockingIdentifiers"`
Expand Down
6 changes: 3 additions & 3 deletions dtos/requests/deviceprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ func TestDeviceProfileRequest_Validate(t *testing.T) {
err := profileNameWithUnreservedChars.Validate()
assert.NoError(t, err, fmt.Sprintf("DeviceProfileRequest with profile name containing unreserved chars %s should pass validation", nameWithUnreservedChars))

// Following tests verify if profile name containing reserved characters should be detected with an error
for _, n := range namesWithReservedCharEdgeX {
// Following tests verify if profile name containing reserved characters should not be detected with an error
for _, n := range namesWithReservedChar {
profileNameWithReservedChar := profileData()
profileNameWithReservedChar.Profile.Name = n

err := profileNameWithReservedChar.Validate()
assert.Error(t, err, fmt.Sprintf("DeviceProfileRequest with profile name containing reserved char %s should return error during validation", n))
assert.NoError(t, err, fmt.Sprintf("DeviceProfileRequest with profile name containing reserved char %s should not return error during validation", n))
}
}

Expand Down
8 changes: 4 additions & 4 deletions dtos/requests/deviceservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ func TestAddDeviceServiceRequest_Validate(t *testing.T) {
err := serviceNameWithUnreservedChars.Validate()
assert.NoError(t, err, fmt.Sprintf("AddDeviceServiceRequest with service name containing unreserved chars %s should pass validation", nameWithUnreservedChars))

// Following tests verify if service name containing reserved characters should be detected with an error
// Following tests verify if service name containing reserved characters should be detected without an error
for _, n := range namesWithReservedChar {
serviceNameWithReservedChar := testAddDeviceService
serviceNameWithReservedChar.Service.Name = n

err := serviceNameWithReservedChar.Validate()
assert.Error(t, err, fmt.Sprintf("AddDeviceServiceRequest with service name containing reserved char %s should return error during validation", n))
assert.NoError(t, err, fmt.Sprintf("AddDeviceServiceRequest with service name containing reserved char %s should nout return error during validation", n))
}
}

Expand Down Expand Up @@ -255,13 +255,13 @@ func TestUpdateDeviceServiceRequest_Validate(t *testing.T) {
err := serviceNameWithUnreservedChars.Validate()
assert.NoError(t, err, fmt.Sprintf("UpdateDeviceServiceRequest with service name containing unreserved chars %s should pass validation", nameWithUnreservedChars))

// Following tests verify if service name containing reserved characters should be detected with an error
// Following tests verify if service name containing reserved characters should not be detected with an error
for i, n := range namesWithReservedChar {
serviceNameWithReservedChar := testUpdateDeviceService
serviceNameWithReservedChar.Service.Name = &namesWithReservedChar[i]

err := serviceNameWithReservedChar.Validate()
assert.Error(t, err, fmt.Sprintf("UpdateDeviceServiceRequest with service name containing reserved char %s should return error during validation", n))
assert.NoError(t, err, fmt.Sprintf("UpdateDeviceServiceRequest with service name containing reserved char %s should not return error during validation", n))
}
}

Expand Down
4 changes: 2 additions & 2 deletions dtos/requests/provisionwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestAddProvisionWatcherRequest_Validate(t *testing.T) {
{"valid AddProvisionWatcherRequest, no Request Id", noReqId, false},
{"invalid AddProvisionWatcherRequest, Request Id is not an uuid", invalidReqId, true},
{"invalid AddProvisionWatcherRequest, no ProvisionWatcherName", noProvisionWatcherName, true},
{"valid AddProvisionWatcherRequest, ProvisionWatcherName with reserved chars", provisionWatcherNameWithReservedChar, true},
{"valid AddProvisionWatcherRequest, ProvisionWatcherName with reserved chars", provisionWatcherNameWithReservedChar, false},
{"invalid AddProvisionWatcherRequest, no Identifiers", noIdentifiers, true},
{"invalid AddProvisionWatcherRequest, missing Identifiers key", missingIdentifiersKey, true},
{"invalid AddProvisionWatcherRequest, missing Identifiers value", missingIdentifiersValue, true},
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestUpdateProvisionWatcherRequest_Validate(t *testing.T) {
{"valid, only name", validOnlyName, false},
{"valid, name and empty Id", nameAndEmptyId, false},
{"invalid, empty name", invalidEmptyName, true},
{"valid, name with reserved chars", reservedName, true},
{"valid, name with reserved chars", reservedName, false},

{"invalid, no Id and name", noIdAndName, true},

Expand Down

0 comments on commit 306cbdf

Please sign in to comment.