Context
An array schema validates only against a slice of empty interface: []interface{}{...}. If a slice of non-empty interface (e.g. []string{...}) is attempted to validate against that schema, this error occurs: unhandled value of type []string
Reproduce
package main
import (
"fmt"
"github.com/getkin/kin-openapi/openapi3"
)
func main() {
schema := &openapi3.Schema{
Type: "array",
UniqueItems: true,
Items: openapi3.NewStringSchema().NewRef(),
}
data := []string{"foo", "bar"}
err := schema.VisitJSON(data)
fmt.Println(err)
}
Expected
In this case, a nil error should be printed because VisitJSON would recognize that data is a slice.
There is a bug in VisitJSON where the []interface{} case does not cover all slices:
|
case []interface{}: |
|
return schema.visitJSONArray(settings, value) |
Context
An array schema validates only against a slice of empty interface:
[]interface{}{...}. If a slice of non-empty interface (e.g.[]string{...}) is attempted to validate against that schema, this error occurs:unhandled value of type []stringReproduce
Expected
In this case, a nil error should be printed because
VisitJSONwould recognize thatdatais a slice.There is a bug in
VisitJSONwhere the[]interface{}case does not cover all slices:kin-openapi/openapi3/schema.go
Lines 1108 to 1109 in 9f99fee