Skip to content

Commit

Permalink
remove slices.Contains
Browse files Browse the repository at this point in the history
  • Loading branch information
eiixy committed Aug 7, 2024
1 parent 0e89407 commit 545ee4b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions jsonschema/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jsonschema
import (
"encoding/json"
"errors"
"slices"
)

func Unmarshal(schema Definition, content []byte, v any) error {
Expand Down Expand Up @@ -60,7 +59,7 @@ func validateObject(schema Definition, data any) bool {
value, exists := dataMap[key]
if exists && !Validate(valueSchema, value) {
return false
} else if !exists && slices.Contains(schema.Required, key) {
} else if !exists && contains(schema.Required, key) {
return false
}
}
Expand All @@ -79,3 +78,12 @@ func validateArray(schema Definition, data any) bool {
}
return true
}

func contains[S ~[]E, E comparable](s S, v E) bool {
for i := range s {
if v == s[i] {
return true
}
}
return false
}

0 comments on commit 545ee4b

Please sign in to comment.