diff --git a/openapi3/schema.go b/openapi3/schema.go index 0d1d18382..415c28170 100644 --- a/openapi3/schema.go +++ b/openapi3/schema.go @@ -1120,6 +1120,17 @@ func (schema *Schema) visitJSON(settings *schemaValidationSettings, value interf return schema.visitJSONObject(settings, values) } } + + // Catch slice of non-empty interface type + if reflect.TypeOf(value).Kind() == reflect.Slice { + valueR := reflect.ValueOf(value) + newValue := make([]interface{}, valueR.Len()) + for i := 0; i < valueR.Len(); i++ { + newValue[i] = valueR.Index(i).Interface() + } + return schema.visitJSONArray(settings, newValue) + } + return &SchemaError{ Value: value, Schema: schema, diff --git a/openapi3/schema_test.go b/openapi3/schema_test.go index 2bd9848dd..26669799a 100644 --- a/openapi3/schema_test.go +++ b/openapi3/schema_test.go @@ -1354,3 +1354,15 @@ enum: err = schema.VisitJSON(map[string]interface{}{"d": "e"}) require.Error(t, err) } + +func TestIssue751(t *testing.T) { + schema := &Schema{ + Type: "array", + UniqueItems: true, + Items: NewStringSchema().NewRef(), + } + validData := []string{"foo", "bar"} + invalidData := []string{"foo", "foo"} + require.NoError(t, schema.VisitJSON(validData)) + require.ErrorContains(t, schema.VisitJSON(invalidData), "duplicate items found") +}