ogen
ogen copied to clipboard
Validation: property fields marked as required are not checked
What version of ogen are you using?
v1.10.0
Can this issue be reproduced with the latest version?
Yes
What did you do?
Enable client/request/validation
Write a schema with a request object with a required property.
Test:
required: [name]
properties:
name:
type: string
description:
type: string
data_type:
type: string
enum: [one, two, three]
What did you expect to see?
A validator function that checks for name being present in oas_validators_gen.go
What did you see instead?
No such validator was generated. I know validators are working as I am seeing some code being generated for validating the values of enum types but nothing for required fields.
func (s *Test) Validate() error {
if s == nil {
return validate.ErrNilPointer
}
var failures []validate.FieldError
if err := func() error {
if err := s.DataType.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "data_type",
Error: err,
})
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}