forked from loafle/openapi-generator-original
* update template for required field validation when additional properties are not allowed * regenerate samples * move bytes import from template to GoClientCodegen * regenerate samples * add test for model with required fields and additionalProperties: false
22 lines
569 B
Go
22 lines
569 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
sw "github.com/OpenAPITools/openapi-generator/samples/client/petstore/go/go-petstore"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRequiredFieldsWithAdditionalPropertiesFalse(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
newAnimal := (sw.Animal{})
|
|
jsonAnimal := `{"className":"invalidAnimal","extraThing":"foo"}`
|
|
|
|
err := newAnimal.UnmarshalJSON([]byte(jsonAnimal))
|
|
expected := "json: unknown field \"extraThing\""
|
|
|
|
assert.ErrorContains(err, expected, "Animal should return error when missing additional fields are present")
|
|
}
|