entc/gen: make enum names pascal case regadless of value case

Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
Alex Snast
2020-07-04 15:19:13 +03:00
parent da56f8e6e8
commit 361b796e90
2 changed files with 4 additions and 4 deletions

View File

@@ -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

View File

@@ -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.