MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / SanitizeEnumNames

Function SanitizeEnumNames

pkg/codegen/utils.go:790–821  ·  view source on GitHub ↗

SanitizeEnumNames fixes illegal chars in the enum names and removes duplicates

(enumNames, enumValues []string)

Source from the content-addressed store, hash-verified

788// SanitizeEnumNames fixes illegal chars in the enum names
789// and removes duplicates
790func SanitizeEnumNames(enumNames, enumValues []string) map[string]string {
791 dupCheck := make(map[string]int, len(enumValues))
792 deDup := make([][]string, 0, len(enumValues))
793
794 for i, v := range enumValues {
795 n := v
796 if i < len(enumNames) {
797 n = enumNames[i]
798 }
799 if _, dup := dupCheck[n]; !dup {
800 deDup = append(deDup, []string{n, v})
801 }
802 dupCheck[n] = 0
803 }
804
805 dupCheck = make(map[string]int, len(deDup))
806 sanitizedDeDup := make(map[string]string, len(deDup))
807
808 for _, p := range deDup {
809 n, v := p[0], p[1]
810 sanitized := SanitizeGoIdentity(SchemaNameToTypeName(n))
811
812 if _, dup := dupCheck[sanitized]; !dup {
813 sanitizedDeDup[sanitized] = v
814 } else {
815 sanitizedDeDup[sanitized+strconv.Itoa(dupCheck[sanitized])] = v
816 }
817 dupCheck[sanitized]++
818 }
819
820 return sanitizedDeDup
821}
822
823func typeNamePrefix(name string) (prefix string) {
824 if len(name) == 0 {

Callers 1

GenerateGoSchemaFunction · 0.85

Calls 2

SanitizeGoIdentityFunction · 0.85
SchemaNameToTypeNameFunction · 0.85

Tested by

no test coverage detected