From d524d8c204f739d8b5b86ef1ba60ec8e5cd14733 Mon Sep 17 00:00:00 2001 From: bruce Date: Fri, 8 Nov 2024 10:28:20 +0800 Subject: [PATCH] fix: Allow binary reading value to be empty Since we accept the nil reading value, the binary reading value can be empty fixes edgex-go#4986 Signed-off-by: bruce --- dtos/reading.go | 2 +- dtos/requests/event_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dtos/reading.go b/dtos/reading.go index 2b0e8bba..2946e956 100644 --- a/dtos/reading.go +++ b/dtos/reading.go @@ -41,7 +41,7 @@ type SimpleReading struct { } type BinaryReading struct { - BinaryValue []byte `json:"binaryValue,omitempty" validate:"omitempty,gt=0"` + BinaryValue []byte `json:"binaryValue,omitempty" validate:"omitempty"` MediaType string `json:"mediaType,omitempty" validate:"required_with=BinaryValue"` } diff --git a/dtos/requests/event_test.go b/dtos/requests/event_test.go index 98f58101..a5d63ea2 100644 --- a/dtos/requests/event_test.go +++ b/dtos/requests/event_test.go @@ -120,7 +120,7 @@ func TestAddEventRequest_Validate(t *testing.T) { {"invalid AddEventRequest, no Reading ValueType", invalidReadingNoValueType, true}, {"invalid AddEventRequest, invalid Reading ValueType", invalidReadingInvalidValueType, true}, {"invalid AddEventRequest, no SimpleReading Value", invalidSimpleReadingNoValue, true}, - {"invalid AddEventRequest, no BinaryReading BinaryValue", invalidBinaryReadingNoValue, true}, + {"valid AddEventRequest, no BinaryReading BinaryValue", invalidBinaryReadingNoValue, false}, {"invalid AddEventRequest, no BinaryReading MediaType", invalidBinaryReadingNoMedia, true}, {"valid AddEventRequest, nil Binary value", nilBinaryReadingNoMedia, false}, {"valid AddEventRequest, nil Simple value", nilSimpleReading, false},