From 545ee4b600299711ba47f75bde9272f28399e96b Mon Sep 17 00:00:00 2001 From: eiixy <990656271@qq.com> Date: Thu, 8 Aug 2024 00:25:52 +0800 Subject: [PATCH] remove slices.Contains --- jsonschema/validate.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/jsonschema/validate.go b/jsonschema/validate.go index af884333b..63902356b 100644 --- a/jsonschema/validate.go +++ b/jsonschema/validate.go @@ -3,7 +3,6 @@ package jsonschema import ( "encoding/json" "errors" - "slices" ) func Unmarshal(schema Definition, content []byte, v any) error { @@ -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 } } @@ -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 +}