Hello, first thanks for this wonderful project !
Im hitting this issue, when one of my fields is called type, it crashes on:
[1] $ go generate ./ent
format file /path/to/code/test/ent/mymodel/model.go: /path/to/code/ent/mymodel/model.go:111:18: expected type, found 'type' (and 1 more errors)
exit status 1
ent/generate.go:3: running "go": exit status 1
That's weird as we do use this name in integration tests here. Could you post your entire schema directory?
I just debugged it a bit more and its failing on this field definition:
field.String("type").NotEmpty().MaxLen(255)
It generates the following validator code:
TypeValidator = func() func (string) error {
validators := descType.Validators
fns := [...]func(string) error {
validators[0].(func(string) error),
validators[1].(func(string) error),
}
return func(type string) error {
for _, fn := range fns {
if err := fn(type); err != nil {
return err
}
}
return nil
}
}()
Ok, I'm able to reproduce. It occurs when a field named type has more than one validator (NotEmpty and MaxLen in this case).
Most helpful comment
111 fixes.