@@ -261,7 +261,7 @@ func (cg *GenConfig) GeneratePathCode(yangFiles, includePaths []string) (map[str
261261 }
262262
263263 // Get NodeDataMap for the schema.
264- nodeDataMap , es := getNodeDataMap (directories , leafTypeMap , schemaStructPkgAccessor , cg .PathStructSuffix , cg .PackageName , cg .SplitByModule , cg .TrimOCPackage )
264+ nodeDataMap , es := getNodeDataMap (directories , leafTypeMap , cg . FakeRootName , schemaStructPkgAccessor , cg .PathStructSuffix , cg .PackageName , cg .SplitByModule , cg .TrimOCPackage )
265265 if es != nil {
266266 errs = util .AppendErrs (errs , es )
267267 }
@@ -275,23 +275,6 @@ func (cg *GenConfig) GeneratePathCode(yangFiles, includePaths []string) (map[str
275275 util .NewErrs (fmt .Errorf ("GeneratePathCode: Implementation bug -- node %s not found in dirNameMap" , directoryName )))
276276 }
277277
278- if ygen .IsFakeRoot (directory .Entry ) {
279- // Since we always generate the fake root, we add the
280- // fake root GoStruct to the data map as well.
281- nodeDataMap [directory .Name + cg .PathStructSuffix ] = & NodeData {
282- GoTypeName : "*" + schemaStructPkgAccessor + yang .CamelCase (cg .FakeRootName ),
283- LocalGoTypeName : "*" + yang .CamelCase (cg .FakeRootName ),
284- GoFieldName : "" ,
285- SubsumingGoStructName : yang .CamelCase (cg .FakeRootName ),
286- IsLeaf : false ,
287- IsScalarField : false ,
288- HasDefault : false ,
289- YANGTypeName : "" ,
290- YANGPath : "/" ,
291- GoPathPackageName : goPackageName (directory , cg .SplitByModule , cg .TrimOCPackage , cg .PackageName ),
292- }
293- }
294-
295278 var listBuilderKeyThreshold uint
296279 if cg .GenerateWildcardPaths {
297280 listBuilderKeyThreshold = cg .ListBuilderKeyThreshold
@@ -332,16 +315,16 @@ func (cg *GenConfig) GeneratePathCode(yangFiles, includePaths []string) (map[str
332315// packageNameReplacePattern matches all characters allowed in yang modules, but not go packages.
333316var packageNameReplacePattern = regexp .MustCompile ("[._-]" )
334317
335- // goPackageName returns the go package to use when generating code for the input Directory .
318+ // goPackageName returns the go package to use when generating code for the input schema Entry .
336319// If splitByModule is false, the pkgName is always returned. Otherwise,
337320// a transformed version of the module that the directory belongs to is returned.
338321// If trimOCPkg is true, "openconfig-" is remove from the package name.
339322// fakeRootPkgName is the name of the package that contains just the fake root path struct.
340- func goPackageName (dir * ygen. Directory , splitByModule , trimOCPkg bool , pkgName string ) string {
341- if ! splitByModule || ygen .IsFakeRoot (dir . Entry ) {
323+ func goPackageName (entry * yang. Entry , splitByModule , trimOCPkg bool , pkgName string ) string {
324+ if ! splitByModule || ygen .IsFakeRoot (entry ) {
342325 return pkgName
343326 }
344- name := util .SchemaTreeRoot (dir . Entry ).Name
327+ name := util .SchemaTreeRoot (entry ).Name
345328 if trimOCPkg {
346329 name = strings .TrimPrefix (name , "openconfig-" )
347330 }
@@ -622,11 +605,27 @@ func mustTemplate(name, src string) *template.Template {
622605// packageName, splitByModule, and trimOCPackage are used to determine
623606// the generated Go package name for the generated PathStructs.
624607// If a directory or field doesn't exist in the leafTypeMap, then an error is returned.
625- // Note: Top-level nodes, but *not* the fake root, are part of the output.
626- func getNodeDataMap (directories map [string ]* ygen.Directory , leafTypeMap map [string ]map [string ]* ygen.MappedType , schemaStructPkgAccessor , pathStructSuffix , packageName string , splitByModule , trimOCPackage bool ) (NodeDataMap , util.Errors ) {
608+ func getNodeDataMap (directories map [string ]* ygen.Directory , leafTypeMap map [string ]map [string ]* ygen.MappedType , fakeRootName , schemaStructPkgAccessor , pathStructSuffix , packageName string , splitByModule , trimOCPackage bool ) (NodeDataMap , util.Errors ) {
627609 nodeDataMap := NodeDataMap {}
628610 var errs util.Errors
629611 for path , dir := range directories {
612+ if ygen .IsFakeRoot (dir .Entry ) {
613+ // Since we always generate the fake root, we add the
614+ // fake root GoStruct to the data map as well.
615+ nodeDataMap [dir .Name + pathStructSuffix ] = & NodeData {
616+ GoTypeName : "*" + schemaStructPkgAccessor + yang .CamelCase (fakeRootName ),
617+ LocalGoTypeName : "*" + yang .CamelCase (fakeRootName ),
618+ GoFieldName : "" ,
619+ SubsumingGoStructName : yang .CamelCase (fakeRootName ),
620+ IsLeaf : false ,
621+ IsScalarField : false ,
622+ HasDefault : false ,
623+ YANGTypeName : "" ,
624+ YANGPath : "/" ,
625+ GoPathPackageName : goPackageName (dir .Entry , splitByModule , trimOCPackage , packageName ),
626+ }
627+ }
628+
630629 goFieldNameMap := ygen .GoFieldNameMap (dir )
631630 fieldTypeMap , ok := leafTypeMap [path ]
632631 if ! ok {
@@ -686,7 +685,7 @@ func getNodeDataMap(directories map[string]*ygen.Directory, leafTypeMap map[stri
686685 HasDefault : isLeaf && (field .Default != "" || mType .DefaultValue != nil ),
687686 YANGTypeName : yangTypeName ,
688687 YANGPath : field .Path (),
689- GoPathPackageName : goPackageName (dir , splitByModule , trimOCPackage , packageName ),
688+ GoPathPackageName : goPackageName (field , splitByModule , trimOCPackage , packageName ),
690689 }
691690 }
692691 }
@@ -843,8 +842,8 @@ func generateDirectorySnippet(directory *ygen.Directory, directories map[string]
843842 // If it is, add that package as a dependency and set the accessor.
844843 if ygen .IsFakeRoot (directory .Entry ) {
845844 if fieldDirectory := directories [field .Path ()]; fieldDirectory != nil {
846- parentPackge := goPackageName (directory , splitByModule , trimOCPkg , pkgName )
847- childPackage := goPackageName (fieldDirectory , splitByModule , trimOCPkg , pkgName )
845+ parentPackge := goPackageName (directory . Entry , splitByModule , trimOCPkg , pkgName )
846+ childPackage := goPackageName (field , splitByModule , trimOCPkg , pkgName )
848847 if parentPackge != childPackage {
849848 deps [childPackage ] = true
850849 childPkgAccessor = childPackage + "."
@@ -892,7 +891,7 @@ func generateDirectorySnippet(directory *ygen.Directory, directories map[string]
892891 PathStructName : structData .TypeName ,
893892 StructBase : structBuf .String (),
894893 ChildConstructors : methodBuf .String (),
895- Package : goPackageName (directory , splitByModule , trimOCPkg , pkgName ),
894+ Package : goPackageName (directory . Entry , splitByModule , trimOCPkg , pkgName ),
896895 }
897896 for dep := range deps {
898897 snippet .Deps = append (snippet .Deps , dep )
0 commit comments