You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
The text was updated successfully, but these errors were encountered:
The problem is, when I specify required: [name] I would expect that if I sent a payload to the server that did not contain a name field at all it should return a 400 bad request. I can fix this with a minLength which works for my use-case, but other validators I've used rely on the required field only, if I am happy to accept "" as an input as long as the field is there.
I'll use minLength for now as this project as few schemas but a larger product I work on that has a very large hand-written schema I am considering moving from oapi-codegen to ogen and this would require specifying minLength on around a thousand fields that already have required specified to keep it consistent.
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.
What did you expect to see?
A validator function that checks for
name
being present inoas_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.
The text was updated successfully, but these errors were encountered: