Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
fix: the input validator can not validate array data
Browse files Browse the repository at this point in the history
  • Loading branch information
donch1989 committed Sep 27, 2024
1 parent fa9eb17 commit bed7328
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion base/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package base

import (
"encoding/base64"
"fmt"
"mime"
"strings"

Expand Down Expand Up @@ -30,9 +31,23 @@ type InstillAcceptFormatsSchema []string
func (s InstillAcceptFormatsSchema) Validate(ctx jsonschema.ValidationContext, v interface{}) error {

// TODO: We should design a better approach to validate the Base64 data.

fmt.Println("Validate")
switch v := v.(type) {

case []any:
// TODO: We should validate the data type as well, not just check if
// it's an array.
ok := false
for _, instillAcceptFormat := range s {
if strings.HasPrefix(instillAcceptFormat, "array:") {
ok = true
}
}
if !ok {
return ctx.Error("instillAcceptFormats", "expected one of %v", s)
}

return nil
case string:
mimeType := ""
for _, instillAcceptFormat := range s {
Expand Down

0 comments on commit bed7328

Please sign in to comment.