File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed
reference-gen/pkg/generator Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,7 @@ func (g *generator) renderOutput(typesToRender map[*types.Type][]*types.Type) er
144144func (g * generator ) buildTemplate (typesToRender map [* types.Type ][]* types.Type , typeList []* types.Type ) (* template.Template , error ) {
145145 knownTypes := newTypeSetFromList (typeList )
146146 t := template .New ("" ).Funcs (map [string ]interface {}{
147+ "aliasDisplayName" : aliasDisplayNameFunc (knownTypes ),
147148 "backtick" : backtick ,
148149 "dereference" : tryDereference ,
149150 "fieldEmbedded" : fieldEmbedded ,
Original file line number Diff line number Diff line change @@ -27,9 +27,9 @@ const typeTemplate = `
2727### {{ .Name.Name }}
2828{{- if eq .Kind "Alias" }}
2929{{ if linkForType .Underlying }}
30- #### ([{{ typeDisplayName .Underlying }}]({{ linkForType .Underlying}}) alias)
30+ #### ([{{ aliasDisplayName . }}]({{ linkForType .Underlying}}) alias)
3131{{- else -}}
32- #### ({{ backtick (typeDisplayName .Underlying )}} alias)
32+ #### ({{ backtick (aliasDisplayName . )}} alias)
3333{{- end -}}
3434{{ end }}
3535{{ with (typeReferences .) }}
Original file line number Diff line number Diff line change @@ -95,6 +95,26 @@ func createTypeList(typesForList map[*types.Type][]*types.Type) []*types.Type {
9595
9696// BEGIN: template functions
9797
98+ // aliasDisplayNameFunc constructs a aliasDisplayName function for the template
99+ func aliasDisplayNameFunc (knownTypes typeSet ) func (t * types.Type ) string {
100+ return func (t * types.Type ) string {
101+ return aliasDisplayName (t , knownTypes )
102+ }
103+ }
104+
105+ // aliasDisplayName allows types to replace their alias with an alternate
106+ // alias display name.
107+ // This can be useful when a type has a custom marshalling rule.
108+ func aliasDisplayName (t * types.Type , knownTypes typeSet ) string {
109+ tags := types .ExtractCommentTags ("+" , t .CommentLines )
110+ if alias , ok := tags ["reference-gen:alias-name" ]; ok {
111+ // There should only be one entry
112+ return alias [0 ]
113+ }
114+
115+ return typeDisplayName (t .Underlying , knownTypes )
116+ }
117+
98118// anchorIDForLocalType returns the #anchor string for the local type
99119func anchorIDForLocalType (t * types.Type ) string {
100120 return strings .ToLower (t .Name .Name )
You can’t perform that action at this time.
0 commit comments