Skip to content

Commit abdca6c

Browse files
authored
fix additional properties false not validated (#747)
1 parent 5c0555e commit abdca6c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

openapi3/issue746_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package openapi3
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestIssue746(t *testing.T) {
11+
schema := &Schema{}
12+
err := schema.UnmarshalJSON([]byte(`{"additionalProperties": false}`))
13+
require.NoError(t, err)
14+
15+
var value interface{}
16+
err = json.Unmarshal([]byte(`{"foo": "bar"}`), &value)
17+
require.NoError(t, err)
18+
19+
err = schema.VisitJSON(value)
20+
require.Error(t, err)
21+
22+
schemaErr := &SchemaError{}
23+
require.ErrorAs(t, err, &schemaErr)
24+
require.Equal(t, "properties", schemaErr.SchemaField)
25+
require.Equal(t, `property "foo" is unsupported`, schemaErr.Reason)
26+
}

openapi3/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func (schema *Schema) IsEmpty() bool {
810810
if ap := schema.AdditionalProperties.Schema; ap != nil && !ap.Value.IsEmpty() {
811811
return false
812812
}
813-
if apa := schema.AdditionalProperties.Has; apa != nil && *apa {
813+
if apa := schema.AdditionalProperties.Has; apa != nil && !*apa {
814814
return false
815815
}
816816
if items := schema.Items; items != nil && !items.Value.IsEmpty() {

0 commit comments

Comments
 (0)