@@ -22,9 +22,17 @@ func (f *fieldPath) Documentation() *common.Doc {
2222 return common .NewFieldDoc (f .path , f .celType .String (), f .description )
2323}
2424
25+ type documentationProvider interface {
26+ // FindStructFieldDescription returns documentation for a field if available.
27+ // Returns false if the field could not be found.
28+ FindStructFieldDescription (typeName , fieldName string ) (string , bool )
29+ }
30+
2531type backtrack struct {
2632 // provider used to resolve types.
2733 provider types.Provider
34+ // provider for resolving documentation. nil if unsupported
35+ docProvider documentationProvider
2836 // paths of fields that have been visited along the path.
2937 path []string
3038 // types of fields that have been visited along the path. used to avoid cycles.
@@ -79,10 +87,14 @@ func (b *backtrack) expandFieldPaths(celType *Type, paths []*fieldPath) []*field
7987 continue
8088 }
8189 b .push (field , celType )
90+ description := ""
91+ if b .docProvider != nil {
92+ description , _ = b .docProvider .FindStructFieldDescription (celType .String (), field )
93+ }
8294 path := & fieldPath {
8395 celType : fieldType .Type ,
8496 path : formatPath (b .path ),
85- description : fieldType . Description ,
97+ description : description ,
8698 isLeaf : false ,
8799 }
88100 paths = append (paths , path )
@@ -137,9 +149,10 @@ func (b *backtrack) expandFieldPaths(celType *Type, paths []*fieldPath) []*field
137149// fieldPathsForType expands the reachable fields from the given root identifier.
138150func fieldPathsForType (provider types.Provider , identifier string , celType * Type ) []* fieldPath {
139151 b := & backtrack {
140- provider : provider ,
141- path : []string {identifier },
142- types : []* Type {celType },
152+ provider : provider ,
153+ docProvider : provider .(documentationProvider ),
154+ path : []string {identifier },
155+ types : []* Type {celType },
143156 }
144157 paths := []* fieldPath {
145158 {
0 commit comments