Skip to content

Commit 23a78f4

Browse files
authored
Merge pull request kubernetes-sigs#343 from trasc/strip-prefix-map
[genref] Strip prefix in map types.
2 parents c519be1 + 95f4caa commit 23a78f4

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

genref/types.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,16 @@ func (t *apiType) Link() string {
300300
return ""
301301
}
302302

303+
func stripPrefix(s string) string {
304+
// strip prefix if desired
305+
for _, prefix := range config.StripPrefix {
306+
if strings.HasPrefix(s, prefix) {
307+
s = strings.Replace(s, prefix, "", 1)
308+
}
309+
}
310+
return s
311+
}
312+
303313
// DisplayName deterimines how a type is displayed in the docs.
304314
func (t *apiType) DisplayName() string {
305315
s := t.typeId()
@@ -318,18 +328,14 @@ func (t *apiType) DisplayName() string {
318328
types.Slice,
319329
types.Builtin:
320330
// noop
321-
case types.Map: // return original name
322-
return t.Name.Name
331+
case types.Map:
332+
elm := apiType{*t.Elem}
333+
return strings.Join([]string{"map[", stripPrefix(t.Key.Name.Name), "]", elm.DisplayName()}, "")
323334
default:
324335
klog.Warningf("Type '%s' has kind='%v' which is unhandled", t.Name, t.Kind)
325336
}
326337

327-
// strip prefix if desired
328-
for _, prefix := range config.StripPrefix {
329-
if strings.HasPrefix(s, prefix) {
330-
s = strings.Replace(s, prefix, "", 1)
331-
}
332-
}
338+
s = stripPrefix(s)
333339

334340
if t.Kind == types.Slice {
335341
s = "[]" + s

0 commit comments

Comments
 (0)