Charles Treatman da13013a27
[Go] fix validation of property names when a model has required fields and doesn't allow additional properties (#17267)
* 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
2023-12-22 12:35:52 +08:00

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")
}