Skip to content

Commit

Permalink
Add only not unique items into result errors
Browse files Browse the repository at this point in the history
  • Loading branch information
austinov committed Nov 2, 2018
1 parent f3a9dae commit f4728f8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions validation.go
Expand Up @@ -517,21 +517,25 @@ func (v *subSchema) validateArray(currentSubSchema *subSchema, value []interface
// uniqueItems:
if currentSubSchema.uniqueItems {
var stringifiedItems []string
var notUniqueItems []interface{}
for _, v := range value {
vString, err := marshalWithoutNumber(v)
if err != nil {
result.addInternalError(new(InternalError), context, value, ErrorDetails{"err": err})
}
if isStringInSlice(stringifiedItems, *vString) {
result.addInternalError(
new(ItemsMustBeUniqueError),
context,
value,
ErrorDetails{"type": TYPE_ARRAY},
)
notUniqueItems = append(notUniqueItems, v)
}
stringifiedItems = append(stringifiedItems, *vString)
}
if len(notUniqueItems) > 0 {
result.addInternalError(
new(ItemsMustBeUniqueError),
context,
notUniqueItems,
ErrorDetails{"type": TYPE_ARRAY},
)
}
}

// contains:
Expand Down

0 comments on commit f4728f8

Please sign in to comment.