-
-
Notifications
You must be signed in to change notification settings - Fork 490
Closed
Description
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:
kin-openapi/openapi3/schema.go
Lines 1108 to 1109 in 9f99fee
| case []interface{}: | |
| return schema.visitJSONArray(settings, value) |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels