From 361b796e906ea492d1c42097f4b5c32ac38312f9 Mon Sep 17 00:00:00 2001 From: Alex Snast Date: Sat, 4 Jul 2020 15:19:13 +0300 Subject: [PATCH] entc/gen: make enum names pascal case regadless of value case Signed-off-by: Alex Snast --- entc/gen/func.go | 6 +++--- entc/gen/type.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/entc/gen/func.go b/entc/gen/func.go index 54c689d9c..6b850fbac 100644 --- a/entc/gen/func.go +++ b/entc/gen/func.go @@ -64,7 +64,7 @@ var ( "list": list, } rules = ruleset() - acronyms = make(map[string]bool) + acronyms = make(map[string]struct{}) ) // ops returns all operations for given field. @@ -114,7 +114,7 @@ func pascal(s string) string { words := strings.Split(s, "_") for i, w := range words { upper := strings.ToUpper(w) - if acronyms[upper] { + if _, ok := acronyms[upper]; ok { words[i] = upper } else { words[i] = rules.Capitalize(w) @@ -258,7 +258,7 @@ func ruleset() *inflect.Ruleset { "TLS", "TTL", "UDP", "UI", "UID", "URI", "URL", "UTF8", "UUID", "VM", "XML", "XMPP", "XSRF", "XSS", } { - acronyms[w] = true + acronyms[w] = struct{}{} rules.AddAcronym(w) } return rules diff --git a/entc/gen/type.go b/entc/gen/type.go index 0c008a912..1ca6be80f 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -615,7 +615,7 @@ func (f Field) Enums() []string { // EnumName returns the constant name of the enum value. func (f Field) EnumName(enum string) string { - return pascal(f.Name) + pascal(enum) + return pascal(f.Name) + pascal(strings.ToLower(enum)) } // Validator returns the validator name.