mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: reject schemas whose package conflicts with ent predeclared identifiers (#1244)
This commit is contained in:
@@ -691,12 +691,12 @@ func ValidSchemaName(name string) error {
|
||||
if types.Universe.Lookup(pkg) != nil {
|
||||
return fmt.Errorf("schema lowercase name conflicts with Go predeclared identifier %q", pkg)
|
||||
}
|
||||
if _, ok := globalIdent[pkg]; ok {
|
||||
return fmt.Errorf("schema lowercase name conflicts ent predeclared identifier %q", pkg)
|
||||
}
|
||||
if _, ok := globalIdent[name]; ok {
|
||||
return fmt.Errorf("schema name conflicts with ent predeclared identifier %q", name)
|
||||
}
|
||||
if _, ok := privateField[pkg]; ok {
|
||||
return fmt.Errorf("schema name conflicts with ent builder fields %q", pkg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1348,6 +1348,7 @@ var (
|
||||
"As",
|
||||
"Asc",
|
||||
"Client",
|
||||
"config",
|
||||
"Count",
|
||||
"Debug",
|
||||
"Desc",
|
||||
|
||||
@@ -321,3 +321,14 @@ func TestEdge(t *testing.T) {
|
||||
require.Equal(t, "user_groups", users.Label())
|
||||
require.Equal(t, "user_groups", groups.Label())
|
||||
}
|
||||
|
||||
func TestValidSchemaName(t *testing.T) {
|
||||
err := ValidSchemaName("Config")
|
||||
require.Error(t, err)
|
||||
err = ValidSchemaName("Mutation")
|
||||
require.Error(t, err)
|
||||
err = ValidSchemaName("Boring")
|
||||
require.NoError(t, err)
|
||||
err = ValidSchemaName("Order")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user