Skip to content

[genref] Strip prefix in map types. #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions genref/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ func (t *apiType) Link() string {
return ""
}

func stripPrefix(s string) string {
// strip prefix if desired
for _, prefix := range config.StripPrefix {
if strings.HasPrefix(s, prefix) {
s = strings.Replace(s, prefix, "", 1)
}
}
return s
}

// DisplayName deterimines how a type is displayed in the docs.
func (t *apiType) DisplayName() string {
s := t.typeId()
Expand All @@ -318,18 +328,14 @@ func (t *apiType) DisplayName() string {
types.Slice,
types.Builtin:
// noop
case types.Map: // return original name
return t.Name.Name
case types.Map:
elm := apiType{*t.Elem}
return strings.Join([]string{"map[", stripPrefix(t.Key.Name.Name), "]", elm.DisplayName()}, "")
default:
klog.Warningf("Type '%s' has kind='%v' which is unhandled", t.Name, t.Kind)
}

// strip prefix if desired
for _, prefix := range config.StripPrefix {
if strings.HasPrefix(s, prefix) {
s = strings.Replace(s, prefix, "", 1)
}
}
s = stripPrefix(s)

if t.Kind == types.Slice {
s = "[]" + s
Expand Down