diff --git a/models/forgefed/activity.go b/models/forgefed/activity.go index a2d7d0cdaa..ae3b1493d0 100644 --- a/models/forgefed/activity.go +++ b/models/forgefed/activity.go @@ -45,7 +45,7 @@ func (like ForgeLike) IsNewer(compareTo time.Time) bool { func (like ForgeLike) Validate() []string { var result []string result = append(result, validation.ValidateNotEmpty(string(like.Type), "type")...) - result = append(result, validation.ValidateOneOf(string(like.Type), []any{"Like"})...) + result = append(result, validation.ValidateOneOf(string(like.Type), []any{"Like"}, "type")...) if like.Actor == nil { result = append(result, "Actor my not be nil.") } else { diff --git a/models/forgefed/actor.go b/models/forgefed/actor.go index 03c4caeb00..704bd42da5 100644 --- a/models/forgefed/actor.go +++ b/models/forgefed/actor.go @@ -108,7 +108,7 @@ func (id PersonID) HostSuffix() string { func (id PersonID) Validate() []string { result := id.ActorID.Validate() result = append(result, validation.ValidateNotEmpty(id.Source, "source")...) - result = append(result, validation.ValidateOneOf(id.Source, []any{"forgejo", "gitea"})...) + result = append(result, validation.ValidateOneOf(id.Source, []any{"forgejo", "gitea"}, "Source")...) switch id.Source { case "forgejo", "gitea": if strings.ToLower(id.Path) != "api/v1/activitypub/user-id" && strings.ToLower(id.Path) != "api/activitypub/user-id" { @@ -147,7 +147,7 @@ func NewRepositoryID(uri, source string) (RepositoryID, error) { func (id RepositoryID) Validate() []string { result := id.ActorID.Validate() result = append(result, validation.ValidateNotEmpty(id.Source, "source")...) - result = append(result, validation.ValidateOneOf(id.Source, []any{"forgejo", "gitea"})...) + result = append(result, validation.ValidateOneOf(id.Source, []any{"forgejo", "gitea"}, "Source")...) switch id.Source { case "forgejo", "gitea": if strings.ToLower(id.Path) != "api/v1/activitypub/repository-id" && strings.ToLower(id.Path) != "api/activitypub/repository-id" { @@ -219,7 +219,7 @@ func (s *ForgePerson) UnmarshalJSON(data []byte) error { func (s ForgePerson) Validate() []string { var result []string result = append(result, validation.ValidateNotEmpty(string(s.Type), "type")...) - result = append(result, validation.ValidateOneOf(string(s.Type), []any{string(ap.PersonType)})...) + result = append(result, validation.ValidateOneOf(string(s.Type), []any{string(ap.PersonType)}, "Type")...) result = append(result, validation.ValidateNotEmpty(s.PreferredUsername.String(), "preferredUsername")...) return result diff --git a/models/forgefed/nodeinfo.go b/models/forgefed/nodeinfo.go index 73536b67ab..19e992cfbf 100644 --- a/models/forgefed/nodeinfo.go +++ b/models/forgefed/nodeinfo.go @@ -73,7 +73,7 @@ func (node NodeInfoWellKnown) Validate() []string { result = append(result, "Href has to be absolute") } - result = append(result, validation.ValidateOneOf(parsedURL.Scheme, []any{"http", "https"})...) + result = append(result, validation.ValidateOneOf(parsedURL.Scheme, []any{"http", "https"}, "parsedURL.Scheme")...) if parsedURL.RawQuery != "" { result = append(result, "Href may not contain query") @@ -129,7 +129,7 @@ func NewNodeInfo(body []byte) (NodeInfo, error) { func (node NodeInfo) Validate() []string { var result []string result = append(result, validation.ValidateNotEmpty(string(node.SoftwareName), "source")...) - result = append(result, validation.ValidateOneOf(node.SoftwareName, KnownSourceTypes)...) + result = append(result, validation.ValidateOneOf(node.SoftwareName, KnownSourceTypes, "node.SoftwareName")...) return result } diff --git a/modules/validation/validatable.go b/modules/validation/validatable.go index 8ff282b50d..f4f3d04da0 100644 --- a/modules/validation/validatable.go +++ b/modules/validation/validatable.go @@ -57,7 +57,7 @@ func ValidateMaxLen(value string, maxLen int, name string) []string { return []string{} } -func ValidateOneOf(value any, allowed []any) []string { +func ValidateOneOf(value any, allowed []any, name string) []string { for _, allowedElem := range allowed { if value == allowedElem { return []string{}