Skip to content

Commit 054ec33

Browse files
committed
add test for model with required fields and additionalProperties: false
1 parent 6f21afd commit 054ec33

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
sw "github.com/OpenAPITools/openapi-generator/samples/client/petstore/go/go-petstore"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestRequiredFieldsWithAdditionalPropertiesFalse(t *testing.T) {
12+
assert := assert.New(t)
13+
14+
newAnimal := (sw.Animal{})
15+
jsonAnimal := `{"className":"invalidAnimal","extraThing":"foo"}`
16+
17+
err := newAnimal.UnmarshalJSON([]byte(jsonAnimal))
18+
expected := "json: unknown field \"extraThing\""
19+
20+
assert.ErrorContains(err, expected, "Animal should return error when missing additional fields are present")
21+
}

0 commit comments

Comments
 (0)