From 3404092e4daebd68bda035a05ef071954ed18569 Mon Sep 17 00:00:00 2001 From: William Wilson Date: Wed, 11 May 2022 10:04:37 -0500 Subject: [PATCH 1/2] Fail validation if required property is zero value --- validation.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/validation.go b/validation.go index 9081bd92..bd29b1a0 100644 --- a/validation.go +++ b/validation.go @@ -612,8 +612,17 @@ func (v *subSchema) validateObject(currentSubSchema *subSchema, value map[string // required: for _, requiredProperty := range currentSubSchema.required { - _, ok := value[requiredProperty] + propertyValue, ok := value[requiredProperty] if ok { + propertyField := reflect.ValueOf(propertyValue) + if propertyField.IsZero() { + result.addInternalError( + new(RequiredError), + context, + value, + ErrorDetails{"property": requiredProperty}, + ) + } result.incrementScore() } else { result.addInternalError( From a9e80821c5d69960ac86a1611aa34787fc64211d Mon Sep 17 00:00:00 2001 From: William Wilson Date: Thu, 12 May 2022 08:33:58 -0500 Subject: [PATCH 2/2] Add a nil check on the value for safety before calling IsZero --- validation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validation.go b/validation.go index bd29b1a0..f08af903 100644 --- a/validation.go +++ b/validation.go @@ -615,7 +615,7 @@ func (v *subSchema) validateObject(currentSubSchema *subSchema, value map[string propertyValue, ok := value[requiredProperty] if ok { propertyField := reflect.ValueOf(propertyValue) - if propertyField.IsZero() { + if propertyValue == nil || propertyField.IsZero() { result.addInternalError( new(RequiredError), context,