Skip to content

Commit c36ec5e

Browse files
committed
add uniqueItems validation
1 parent e2650c3 commit c36ec5e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/val.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ function val_enum(val::Dict, lst)
1515
end
1616
true
1717
end
18+
function val_unique_items(val::Vector, is_unique)
19+
is_unique || return true
20+
return length(Set(val)) == length(val)
21+
end
1822

1923
const MSG_INVALID_API_PARAM = Dict{Symbol,Function}([
2024
:maximum => (val,excl)->string("must be a value less than ", excl ? "or equal to " : "", val),
@@ -23,7 +27,8 @@ const MSG_INVALID_API_PARAM = Dict{Symbol,Function}([
2327
:minLength => (len)->string("length must be greater than or equal to ", len),
2428
:maxItems => (val)->string("number of items must be less than or equal to ", val),
2529
:minItems => (val)->string("number of items must be greater than or equal to ", val),
26-
:enum => (lst)->string("value is not from the allowed values", lst)
30+
:uniqueItems => (val)->string("items must be unique"),
31+
:enum => (lst)->string("value is not from the allowed values", lst),
2732
])
2833

2934
const VAL_API_PARAM = Dict{Symbol,Function}([
@@ -33,7 +38,8 @@ const VAL_API_PARAM = Dict{Symbol,Function}([
3338
:minLength => val_min_length,
3439
:maxItems => val_max_length,
3540
:minItems => val_min_length,
36-
:enum => val_enum
41+
:uniqueItems => val_unique_items,
42+
:enum => val_enum,
3743
])
3844

3945
function validate_param(param, operation, rule, value, args...)

0 commit comments

Comments
 (0)