Skip to content

Commit

Permalink
fix additional properties false not validated
Browse files Browse the repository at this point in the history
  • Loading branch information
ori-shalom committed Jan 21, 2023
1 parent 5c0555e commit c8f5c68
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions openapi3/issue746_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package openapi3

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
)

func TestIssue746(t *testing.T) {
schema := &Schema{}
err := schema.UnmarshalJSON([]byte(`{"additionalProperties": false}`))
require.NoError(t, err)

var value interface{}
err = json.Unmarshal([]byte(`{"foo": "bar"}`), &value)
require.NoError(t, err)

err = schema.VisitJSON(value)
require.Error(t, err)

schemaErr := &SchemaError{}
require.ErrorAs(t, err, &schemaErr)
require.Equal(t, "properties", schemaErr.SchemaField)
require.Equal(t, `property "foo" is unsupported`, schemaErr.Reason)
}
2 changes: 1 addition & 1 deletion openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ func (schema *Schema) IsEmpty() bool {
if ap := schema.AdditionalProperties.Schema; ap != nil && !ap.Value.IsEmpty() {
return false
}
if apa := schema.AdditionalProperties.Has; apa != nil && *apa {
if apa := schema.AdditionalProperties.Has; apa != nil && !*apa {
return false
}
if items := schema.Items; items != nil && !items.Value.IsEmpty() {
Expand Down

0 comments on commit c8f5c68

Please sign in to comment.