From a1b8f0d71e18c0f02659ce6efa87b1aaff3e7fbf Mon Sep 17 00:00:00 2001 From: Wen Bo Li <50884368+wenovus@users.noreply.github.com> Date: Fri, 26 Jun 2020 15:21:05 -0700 Subject: [PATCH] Allow ypathgen to generate path structs that don't conflict GoStructs (#406) * Allow ypathgen to generate path structs that don't conflict with ygen's GoStructs --- ypathgen/generator/generator.go | 10 +- ypathgen/pathgen.go | 131 +- ypathgen/pathgen_test.go | 1510 +++++++++-------- .../structs/choice-case-example.path-txt | 171 +- .../testdata/structs/enum-module.path-txt | 177 +- .../structs/openconfig-camelcase.path-txt | 75 +- .../structs/openconfig-enumcamelcase.path-txt | 63 +- .../structs/openconfig-simple-30.path-txt | 21 +- .../structs/openconfig-simple-31.path-txt | 21 +- .../structs/openconfig-simple-32.path-txt | 117 +- .../openconfig-simple-intendedconfig.path-txt | 157 +- .../structs/openconfig-simple.path-txt | 157 +- .../structs/openconfig-unione.path-txt | 197 ++- .../openconfig-withlist-builder.path-txt | 143 +- ...nconfig-withlist-separate-package.path-txt | 295 ++++ .../structs/openconfig-withlist.path-txt | 171 +- 16 files changed, 1894 insertions(+), 1522 deletions(-) create mode 100644 ypathgen/testdata/structs/openconfig-withlist-separate-package.path-txt diff --git a/ypathgen/generator/generator.go b/ypathgen/generator/generator.go index 1c35528c8..d145edc43 100644 --- a/ypathgen/generator/generator.go +++ b/ypathgen/generator/generator.go @@ -38,13 +38,13 @@ var ( ignoreCircDeps = flag.Bool("ignore_circdeps", false, "If set to true, circular dependencies between submodules are ignored.") preferOperationalState = flag.Bool("prefer_operational_state", false, "If set to true, state (config false) fields in the YANG schema are preferred over intended config leaves when building paths. This flag is only valid when exclude_state=false.") fakeRootName = flag.String("fakeroot_name", "device", "The name of the fake root entity. This name will be capitalized for exporting.") - schemaStructPkgAlias = flag.String("schema_struct_pkg_alias", "", "The package alias of the schema struct package.") - schemaStructPath = flag.String("schema_struct_path", "", "The import path to use for ygen-generated schema structs.") + schemaStructPath = flag.String("schema_struct_path", "", "The import path to use for ygen-generated schema structs. This should only be specified if the generated path structs are to reside in a different package.") gnmiProtoPath = flag.String("gnmi_proto_path", genutil.GoDefaultGNMIImportPath, "The import path to use for gNMI's proto package.") ygotImportPath = flag.String("ygot_path", genutil.GoDefaultYgotImportPath, "The import path to use for ygot.") listBuilderKeyThreshold = flag.Uint("list_builder_key_threshold", 0, "The threshold equal or over which the builder API is used for key population. 0 means infinity.") skipEnumDedup = flag.Bool("skip_enum_deduplication", false, "If set to true, all leaves of type enumeration will have a unique enum output for them, rather than sharing a common type (default behaviour).") shortenEnumLeafNames = flag.Bool("shorten_enum_leaf_names", false, "If also set to true when compression is on, all leaves of type enumeration will by default not be prefixed with the name of its residing module.") + pathStructSuffix = flag.String("path_struct_suffix", "Path", "The suffix string appended to each generated path struct in order to differentiate their names from their corresponding schema struct names.") ) // writeGoCodeSingleFile takes a ypathgen.GeneratedPathCode struct and writes @@ -68,10 +68,6 @@ func main() { log.Exitln("Error: no input modules specified") } - if *schemaStructPath == "" { - log.Exitln("Error: schemaStructPath unspecified") - } - // Determine the set of paths that should be searched for included // modules. This is supplied by the user as a set of comma-separated // paths, so we split the string. Additionally, for each path @@ -111,8 +107,8 @@ func main() { SkipEnumDeduplication: *skipEnumDedup, ShortenEnumLeafNames: *shortenEnumLeafNames, FakeRootName: *fakeRootName, + PathStructSuffix: *pathStructSuffix, ExcludeModules: modsExcluded, - SchemaStructPkgAlias: "oc", YANGParseOptions: yang.Options{ IgnoreSubmoduleCircularDependencies: *ignoreCircDeps, }, diff --git a/ypathgen/pathgen.go b/ypathgen/pathgen.go index 5cb3f4121..04034b1ab 100644 --- a/ypathgen/pathgen.go +++ b/ypathgen/pathgen.go @@ -37,13 +37,18 @@ import ( // Static default configuration values that differ from the zero value for their types. const ( - // defaultSchemaStructPkgAlias is the package alias for the imported ygen-generated file. - defaultSchemaStructPkgAlias = "oc" // defaultPathPackageName specifies the default name that should be // used for the generated Go package. defaultPathPackageName = "ocpathstructs" // defaultFakeRootName is the default name for the root structure. defaultFakeRootName = "root" + // defaultPathStructSuffix is the default suffix for generated + // PathStructs to distinguish them from the generated GoStructs + defaultPathStructSuffix = "Path" + // schemaStructPkgAlias is the package alias of the schema struct + // package when the path struct package is to be generated in a + // separate package. + schemaStructPkgAlias = "oc" // WildcardSuffix is the suffix given to the wildcard versions of each // node as well as a list's wildcard child constructor methods that // distinguishes each from its non-wildcard counterpart. @@ -58,8 +63,10 @@ const ( BuilderKeyPrefix = "With" ) -// NewDefaultConfig creates a GenConfig with default configuration. schemaStructPkgPath is a -// required configuration parameter. +// NewDefaultConfig creates a GenConfig with default configuration. +// schemaStructPkgPath is a required configuration parameter. It should be set +// to "" when the generated PathStruct package is to be the same package as the +// GoStructs package. func NewDefaultConfig(schemaStructPkgPath string) *GenConfig { return &GenConfig{ PackageName: defaultPathPackageName, @@ -68,9 +75,9 @@ func NewDefaultConfig(schemaStructPkgPath string) *GenConfig { GNMIProtoPath: genutil.GoDefaultGNMIImportPath, YgotImportPath: genutil.GoDefaultYgotImportPath, }, - FakeRootName: defaultFakeRootName, - SchemaStructPkgAlias: defaultSchemaStructPkgAlias, - GeneratingBinary: genutil.CallerName(), + FakeRootName: defaultFakeRootName, + PathStructSuffix: defaultPathStructSuffix, + GeneratingBinary: genutil.CallerName(), } } @@ -90,6 +97,10 @@ type GenConfig struct { // FakeRootName specifies the name of the struct that should be generated // representing the root. FakeRootName string + // PathStructSuffix is the suffix to be appended to generated + // PathStructs to distinguish them from the generated GoStructs, which + // assume a similar name. + PathStructSuffix string // SkipEnumDeduplication specifies whether leaves of type 'enumeration' that // are used in multiple places in the schema should share a common type within // the generated code that is output by ygen. By default (false), a common type @@ -107,8 +118,6 @@ type GenConfig struct { // code generation. This is due to the fact that some schemas (e.g., OpenConfig // interfaces) currently result in overlapping entities (e.g., /interfaces). ExcludeModules []string - // SchemaStructPkgAlias is the package alias of the schema struct package. - SchemaStructPkgAlias string // YANGParseOptions provides the options that should be handed to the // github.com/openconfig/goyang/pkg/yang library. These specify how the // input YANG files should be parsed. @@ -159,10 +168,11 @@ type GoImports struct { // augmentations to the basic generated path code. // If errors are encountered during code generation, they are returned. func (cg *GenConfig) GeneratePathCode(yangFiles, includePaths []string) (*GeneratedPathCode, NodeDataMap, util.Errors) { - if cg.GoImports.SchemaStructPkgPath == "" { - return nil, nil, util.NewErrs(fmt.Errorf("GeneratePathCode: Must specify SchemaStructPkgPath")) - } - + // Note: The input configuration may cause the code to not compile. + // While it's possible to write checks for better error messages, the + // many ways in which compilation may fail, coupled with the plethora + // of configurations, means there is an argument to force the user to + // debug instead of making ypathgen having to catch every error. compressBehaviour := genutil.PreferIntendedConfig if cg.PreferOperationalState { compressBehaviour = genutil.PreferOperationalState @@ -198,6 +208,11 @@ func (cg *GenConfig) GeneratePathCode(yangFiles, includePaths []string) (*Genera return nil, nil, util.AppendErr(errs, err) } + var schemaStructPkgAccessor string + if cg.GoImports.SchemaStructPkgPath != "" { + schemaStructPkgAccessor = schemaStructPkgAlias + "." + } + // Generate struct code. var structSnippets []GoPathStructCodeSnippet for _, directoryName := range orderedDirNames { @@ -207,7 +222,7 @@ func (cg *GenConfig) GeneratePathCode(yangFiles, includePaths []string) (*Genera util.NewErrs(fmt.Errorf("GeneratePathCode: Implementation bug -- node %s not found in dirNameMap", directoryName))) } - structSnippet, es := generateDirectorySnippet(directory, directories, cg.SchemaStructPkgAlias, cg.ListBuilderKeyThreshold) + structSnippet, es := generateDirectorySnippet(directory, directories, schemaStructPkgAccessor, cg.PathStructSuffix, cg.ListBuilderKeyThreshold) if es != nil { errs = util.AppendErrs(errs, es) } @@ -216,7 +231,7 @@ func (cg *GenConfig) GeneratePathCode(yangFiles, includePaths []string) (*Genera genCode.Structs = structSnippets // Get NodeDataMap for the schema. - nodeDataMap, es := getNodeDataMap(directories, leafTypeMap, cg.SchemaStructPkgAlias) + nodeDataMap, es := getNodeDataMap(directories, leafTypeMap, schemaStructPkgAccessor, cg.PathStructSuffix) if es != nil { util.AppendErrs(errs, es) } @@ -317,13 +332,15 @@ type NodeDataMap map[string]*NodeData // NodeData contains information about the ygen-generated code of a YANG schema node. type NodeData struct { - // GoTypeName is the ygen type name of the node, which is qualified by - // the SchemaStructPkgAlias if necessary. + // GoTypeName is the type name of the node as part of the schema + // structs, which is qualified by the SchemaStructPkgAlias if + // necessary. It could be a GoStruct or a leaf type. GoTypeName string // GoFieldName is the field name of the node under its parent struct. GoFieldName string - // ParentGoTypeName is the parent struct's type name. - ParentGoTypeName string + // SubsumingGoStructName is the GoStruct type name corresponding to the node. If + // the node is a leaf, then it is the parent GoStruct's name. + SubsumingGoStructName string // IsLeaf indicates whether this child is a leaf node. IsLeaf bool // IsScalarField indicates a leaf that is stored as a pointer in its @@ -376,7 +393,9 @@ Imported modules were sourced from: package {{ .PackageName }} import ( + {{- if .SchemaStructPkgPath }} {{ .SchemaStructPkgAlias }} "{{ .SchemaStructPkgPath }}" + {{- end }} "{{ .YgotImportPath }}" ) `) @@ -458,7 +477,7 @@ func mustTemplate(name, src string) *template.Template { // every leaf node only, leafTypeMap's value is nil for non-leaf nodes. // If a directory or field doesn't exist in the leafTypeMap, then an error is returned. // Note: Top-level nodes, but *not* the fake root, are part of the output. -func getNodeDataMap(directories map[string]*ygen.Directory, leafTypeMap map[string]map[string]*ygen.MappedType, schemaStructPkgAlias string) (NodeDataMap, util.Errors) { +func getNodeDataMap(directories map[string]*ygen.Directory, leafTypeMap map[string]map[string]*ygen.MappedType, schemaStructPkgAccessor, pathStructSuffix string) (NodeDataMap, util.Errors) { nodeDataMap := NodeDataMap{} var errs util.Errors for path, dir := range directories { @@ -469,7 +488,7 @@ func getNodeDataMap(directories map[string]*ygen.Directory, leafTypeMap map[stri continue } for fieldName, field := range dir.Fields { - pathStructName, err := getFieldTypeName(dir, fieldName, goFieldNameMap[fieldName], directories) + pathStructName, err := getFieldTypeName(dir, fieldName, goFieldNameMap[fieldName], directories, pathStructSuffix) if err != nil { errs = util.AppendErr(errs, err) continue @@ -481,14 +500,20 @@ func getNodeDataMap(directories map[string]*ygen.Directory, leafTypeMap map[stri } isLeaf := mType != nil + + subsumingGoStructName := dir.Name + if !isLeaf { + subsumingGoStructName = directories[dir.Fields[fieldName].Path()].Name + } + var goTypeName string switch { case !isLeaf: - goTypeName = "*" + schemaStructPkgAlias + "." + pathStructName + goTypeName = "*" + schemaStructPkgAccessor + subsumingGoStructName case field.ListAttr != nil && ygen.IsYgenDefinedGoType(mType): - goTypeName = "[]" + schemaStructPkgAlias + "." + mType.NativeType + goTypeName = "[]" + schemaStructPkgAccessor + mType.NativeType case ygen.IsYgenDefinedGoType(mType): - goTypeName = schemaStructPkgAlias + "." + mType.NativeType + goTypeName = schemaStructPkgAccessor + mType.NativeType case field.ListAttr != nil: goTypeName = "[]" + mType.NativeType default: @@ -500,13 +525,13 @@ func getNodeDataMap(directories map[string]*ygen.Directory, leafTypeMap map[stri yangTypeName = field.Type.Name } nodeDataMap[pathStructName] = &NodeData{ - GoTypeName: goTypeName, - GoFieldName: goFieldNameMap[fieldName], - ParentGoTypeName: dir.Name, - IsLeaf: isLeaf, - IsScalarField: ygen.IsScalarField(field, mType), - YANGTypeName: yangTypeName, - YANGPath: field.Path(), + GoTypeName: goTypeName, + GoFieldName: goFieldNameMap[fieldName], + SubsumingGoStructName: subsumingGoStructName, + IsLeaf: isLeaf, + IsScalarField: ygen.IsScalarField(field, mType), + YANGTypeName: yangTypeName, + YANGPath: field.Path(), } } } @@ -538,7 +563,7 @@ func writeHeader(yangFiles, includePaths []string, cg *GenConfig, genCode *Gener GeneratingBinary: cg.GeneratingBinary, YANGFiles: yangFiles, IncludePaths: includePaths, - SchemaStructPkgAlias: cg.SchemaStructPkgAlias, + SchemaStructPkgAlias: schemaStructPkgAlias, PathBaseTypeName: ygot.PathBaseTypeName, PathStructInterfaceName: ygot.PathStructInterfaceName, FakeRootTypeName: yang.CamelCase(cg.FakeRootName), @@ -575,9 +600,9 @@ type goPathStructData struct { // getStructData returns the goPathStructData corresponding to a Directory, // which is used to store the attributes of the template for which code is // being generated. -func getStructData(directory *ygen.Directory) goPathStructData { +func getStructData(directory *ygen.Directory, pathStructSuffix string) goPathStructData { return goPathStructData{ - TypeName: directory.Name, + TypeName: directory.Name + pathStructSuffix, YANGPath: util.SlicePathToString(directory.Path), PathBaseTypeName: ygot.PathBaseTypeName, FakeRootBaseTypeName: ygot.FakeRootBaseTypeName, @@ -605,7 +630,7 @@ type goPathFieldData struct { // the fields of the struct. directory is the parsed information of a schema // node, and directories is a map from path to a parsed schema node for all // nodes in the schema. -func generateDirectorySnippet(directory *ygen.Directory, directories map[string]*ygen.Directory, schemaStructPkgAlias string, listBuilderKeyThreshold uint) (GoPathStructCodeSnippet, util.Errors) { +func generateDirectorySnippet(directory *ygen.Directory, directories map[string]*ygen.Directory, schemaStructPkgAccessor, pathStructSuffix string, listBuilderKeyThreshold uint) (GoPathStructCodeSnippet, util.Errors) { var errs util.Errors // structBuf is used to store the code associated with the struct defined for // the target YANG entity. @@ -613,7 +638,7 @@ func generateDirectorySnippet(directory *ygen.Directory, directories map[string] var methodBuf strings.Builder // Output struct snippets. - structData := getStructData(directory) + structData := getStructData(directory, pathStructSuffix) if ygen.IsFakeRoot(directory.Entry) { // Fakeroot has its unique output. if err := goPathFakeRootTemplate.Execute(&structBuf, structData); err != nil { @@ -635,7 +660,7 @@ func generateDirectorySnippet(directory *ygen.Directory, directories map[string] } goFieldName := goFieldNameMap[fieldName] - if es := generateChildConstructors(&methodBuf, directory, fieldName, goFieldName, directories, schemaStructPkgAlias, listBuilderKeyThreshold); es != nil { + if es := generateChildConstructors(&methodBuf, directory, fieldName, goFieldName, directories, schemaStructPkgAccessor, pathStructSuffix, listBuilderKeyThreshold); es != nil { errs = util.AppendErrs(errs, es) } @@ -643,7 +668,7 @@ func generateDirectorySnippet(directory *ygen.Directory, directories map[string] // to output their struct snippets somewhere, and here is // convenient. if field.IsLeaf() || field.IsLeafList() { - leafTypeName, err := getFieldTypeName(directory, fieldName, goFieldName, directories) + leafTypeName, err := getFieldTypeName(directory, fieldName, goFieldName, directories, pathStructSuffix) if err != nil { errs = util.AppendErr(errs, err) } else { @@ -678,17 +703,17 @@ func generateDirectorySnippet(directory *ygen.Directory, directories map[string] // field name to be used as the generated method's name and the incremental // type name of of the child path struct, and a map of all directories of the // whole schema keyed by their schema paths. -func generateChildConstructors(methodBuf *strings.Builder, directory *ygen.Directory, directoryFieldName string, goFieldName string, directories map[string]*ygen.Directory, schemaStructPkgAlias string, listBuilderKeyThreshold uint) []error { +func generateChildConstructors(methodBuf *strings.Builder, directory *ygen.Directory, directoryFieldName string, goFieldName string, directories map[string]*ygen.Directory, schemaStructPkgAccessor, pathStructSuffix string, listBuilderKeyThreshold uint) []error { field, ok := directory.Fields[directoryFieldName] if !ok { return []error{fmt.Errorf("generateChildConstructors: field %s not found in directory %v", directoryFieldName, directory)} } - fieldTypeName, err := getFieldTypeName(directory, directoryFieldName, goFieldName, directories) + fieldTypeName, err := getFieldTypeName(directory, directoryFieldName, goFieldName, directories, pathStructSuffix) if err != nil { return []error{err} } - structData := getStructData(directory) + structData := getStructData(directory, pathStructSuffix) relPath, err := ygen.FindSchemaPath(directory, directoryFieldName, false) if err != nil { return []error{err} @@ -722,9 +747,9 @@ func generateChildConstructors(methodBuf *strings.Builder, directory *ygen.Direc // If the number of keys is equal to or over the builder API threshold, // then use the builder API format to make the list path API less // confusing for the user. - return generateChildConstructorsForListBuilderFormat(methodBuf, fieldDirectory.ListAttr, fieldData, isUnderFakeRoot, schemaStructPkgAlias) + return generateChildConstructorsForListBuilderFormat(methodBuf, fieldDirectory.ListAttr, fieldData, isUnderFakeRoot, schemaStructPkgAccessor) default: - return generateChildConstructorsForList(methodBuf, fieldDirectory.ListAttr, fieldData, isUnderFakeRoot, schemaStructPkgAlias) + return generateChildConstructorsForList(methodBuf, fieldDirectory.ListAttr, fieldData, isUnderFakeRoot, schemaStructPkgAccessor) } } @@ -757,10 +782,10 @@ func generateChildConstructorsForLeafOrContainer(methodBuf *strings.Builder, fie // the builder API format. fieldData contains the childConstructor template // output information for if the node were a container (which contains a subset // of the basic information required for the list constructor methods). -func generateChildConstructorsForListBuilderFormat(methodBuf *strings.Builder, listAttr *ygen.YangListAttr, fieldData goPathFieldData, isUnderFakeRoot bool, schemaStructPkgAlias string) []error { +func generateChildConstructorsForListBuilderFormat(methodBuf *strings.Builder, listAttr *ygen.YangListAttr, fieldData goPathFieldData, isUnderFakeRoot bool, schemaStructPkgAccessor string) []error { var errors []error // List of function parameters as would appear in the method definition. - keyParams, err := makeKeyParams(listAttr, schemaStructPkgAlias) + keyParams, err := makeKeyParams(listAttr, schemaStructPkgAccessor) if err != nil { return append(errors, err) } @@ -825,10 +850,10 @@ func generateChildConstructorsForListBuilderFormat(methodBuf *strings.Builder, l // childConstructor template output information for if the node were a // container (which contains a subset of the basic information required for // the list constructor methods). -func generateChildConstructorsForList(methodBuf *strings.Builder, listAttr *ygen.YangListAttr, fieldData goPathFieldData, isUnderFakeRoot bool, schemaStructPkgAlias string) []error { +func generateChildConstructorsForList(methodBuf *strings.Builder, listAttr *ygen.YangListAttr, fieldData goPathFieldData, isUnderFakeRoot bool, schemaStructPkgAccessor string) []error { var errors []error // List of function parameters as would appear in the method definition. - keyParams, err := makeKeyParams(listAttr, schemaStructPkgAlias) + keyParams, err := makeKeyParams(listAttr, schemaStructPkgAccessor) if err != nil { return append(errors, err) } @@ -917,7 +942,7 @@ func generateChildConstructorsForList(methodBuf *strings.Builder, listAttr *ygen // leaf. For non-leaves, their corresponding directories' "Name"s, which are the // same names as their corresponding ygen Go struct type names, are re-used as // their type names; for leaves, type names are synthesized. -func getFieldTypeName(directory *ygen.Directory, directoryFieldName string, goFieldName string, directories map[string]*ygen.Directory) (string, error) { +func getFieldTypeName(directory *ygen.Directory, directoryFieldName string, goFieldName string, directories map[string]*ygen.Directory, pathStructSuffix string) (string, error) { field, ok := directory.Fields[directoryFieldName] if !ok { return "", fmt.Errorf("getFieldTypeName: field %s not found in directory %v", directoryFieldName, directory) @@ -928,15 +953,15 @@ func getFieldTypeName(directory *ygen.Directory, directoryFieldName string, goFi if !ok { return "", fmt.Errorf("getFieldTypeName: unexpected - field %s not found in parsed yang structs map: %v", field.Path(), directories) } - return fieldDirectory.Name, nil + return fieldDirectory.Name + pathStructSuffix, nil } // Leaves do not have corresponding Directory entries, so their names need to be constructed. if isTopLevelLeaf := directory.Entry.Parent == nil; isTopLevelLeaf { // When a leaf resides at the root, its type name is its whole name -- we never want fakeroot's name as a prefix. - return goFieldName, nil + return goFieldName + pathStructSuffix, nil } - return directory.Name + "_" + goFieldName, nil + return directory.Name + "_" + goFieldName + pathStructSuffix, nil } type keyParam struct { @@ -957,7 +982,7 @@ type keyParam struct { // KeyElems: []*yang.Entry{{Name: "fluorine"}, {Name: "iodine-liquid"}}, // } // out: [{"fluroine", "Fluorine", "string"}, {"iodine-liquid", "IodineLiquid", "oc.Binary"}] -func makeKeyParams(listAttr *ygen.YangListAttr, schemaStructPkgAlias string) ([]keyParam, error) { +func makeKeyParams(listAttr *ygen.YangListAttr, schemaStructPkgAccessor string) ([]keyParam, error) { if len(listAttr.KeyElems) == 0 { return nil, fmt.Errorf("makeKeyParams: invalid list - has no key; cannot process param list string") } @@ -983,7 +1008,7 @@ func makeKeyParams(listAttr *ygen.YangListAttr, schemaStructPkgAlias string) ([] case mappedType.NativeType == "interface{}": // ygen-unsupported types typeName = "string" case ygen.IsYgenDefinedGoType(mappedType): - typeName = schemaStructPkgAlias + "." + mappedType.NativeType + typeName = schemaStructPkgAccessor + mappedType.NativeType default: typeName = mappedType.NativeType } diff --git a/ypathgen/pathgen_test.go b/ypathgen/pathgen_test.go index 91fb1106e..3fe885492 100644 --- a/ypathgen/pathgen_test.go +++ b/ypathgen/pathgen_test.go @@ -39,426 +39,457 @@ const ( datapath = "../testdata/modules" ) -// yangTestCase describes a test case for which code generation is performed -// through Goyang's API, it provides the input set of parameters in a way that -// can be reused across tests. -type yangTestCase struct { - name string // Name is the identifier for the test. - inFiles []string // inFiles is the set of inputFiles for the test. - inIncludePaths []string // inIncludePaths is the set of paths that should be searched for imports. - inPreferOperationalState bool // inPreferOperationalState says whether to prefer operational state over intended config in the path-building methods. - inListBuilderKeyThreshold uint // inListBuilderKeyThreshold determines the minimum number of keys beyond which the builder API is used for building the paths. - inShortenEnumLeafNames bool // inShortenEnumLeafNames says whether the enum leaf names are shortened (i.e. module name removed) in the generated Go code corresponding to the generated path library. - checkYANGPath bool // checkYANGPath says whether to check for the YANG path in the NodeDataMap. - wantStructsCodeFile string // wantStructsCodeFile is the path of the generated Go code that the output of the test should be compared to. - wantNodeDataMap NodeDataMap // wantNodeDataMap is the expected NodeDataMap to be produced to accompany the path struct outputs. - wantErr bool // wantErr specifies whether the test should expect an error. -} - func TestGeneratePathCode(t *testing.T) { - tests := []yangTestCase{{ + tests := []struct { + // Name is the identifier for the test. + name string + // inFiles is the set of inputFiles for the test. + inFiles []string + // inIncludePaths is the set of paths that should be searched for imports. + inIncludePaths []string + // inPreferOperationalState says whether to prefer operational state over intended config in the path-building methods. + inPreferOperationalState bool + // inListBuilderKeyThreshold determines the minimum number of keys beyond which the builder API is used for building the paths. + inListBuilderKeyThreshold uint + // inShortenEnumLeafNames says whether the enum leaf names are shortened (i.e. module name removed) in the generated Go code corresponding to the generated path library. + inShortenEnumLeafNames bool + inSchemaStructPkgPath string + inPathStructSuffix string + // checkYANGPath says whether to check for the YANG path in the NodeDataMap. + checkYANGPath bool + // wantStructsCodeFile is the path of the generated Go code that the output of the test should be compared to. + wantStructsCodeFile string + // wantNodeDataMap is the expected NodeDataMap to be produced to accompany the path struct outputs. + wantNodeDataMap NodeDataMap + // wantErr specifies whether the test should expect an error. + wantErr bool + }{{ name: "simple openconfig test", inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-simple.path-txt"), inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", checkYANGPath: true, wantNodeDataMap: NodeDataMap{ - "Parent": { - GoTypeName: "*oc.Parent", - GoFieldName: "Parent", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - YANGPath: "/openconfig-simple/parent", - }, - "Parent_Child": { - GoTypeName: "*oc.Parent_Child", - GoFieldName: "Child", - ParentGoTypeName: "Parent", - IsLeaf: false, - IsScalarField: false, - YANGPath: "/openconfig-simple/parent/child", - }, - "Parent_Child_Four": { - GoTypeName: "oc.Binary", - GoFieldName: "Four", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "binary", - YANGPath: "/openconfig-simple/parent/child/state/four", - }, - "Parent_Child_One": { - GoTypeName: "string", - GoFieldName: "One", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "string", - YANGPath: "/openconfig-simple/parent/child/state/one", - }, - "Parent_Child_Three": { - GoTypeName: "oc.E_Child_Three", - GoFieldName: "Three", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumeration", - YANGPath: "/openconfig-simple/parent/child/state/three", - }, - "Parent_Child_Two": { - GoTypeName: "string", - GoFieldName: "Two", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "string", - YANGPath: "/openconfig-simple/parent/child/state/two", - }, - "RemoteContainer": { - GoTypeName: "*oc.RemoteContainer", - GoFieldName: "RemoteContainer", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - YANGPath: "/openconfig-simple/remote-container", - }, - "RemoteContainer_ALeaf": { - GoTypeName: "string", - GoFieldName: "ALeaf", - ParentGoTypeName: "RemoteContainer", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "string", - YANGPath: "/openconfig-simple/remote-container/state/a-leaf", + "ParentPath": { + GoTypeName: "*Parent", + GoFieldName: "Parent", + SubsumingGoStructName: "Parent", + IsLeaf: false, + IsScalarField: false, + YANGPath: "/openconfig-simple/parent", + }, + "Parent_ChildPath": { + GoTypeName: "*Parent_Child", + GoFieldName: "Child", + SubsumingGoStructName: "Parent_Child", + IsLeaf: false, + IsScalarField: false, + YANGPath: "/openconfig-simple/parent/child", + }, + "Parent_Child_FourPath": { + GoTypeName: "Binary", + GoFieldName: "Four", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "binary", + YANGPath: "/openconfig-simple/parent/child/state/four", + }, + "Parent_Child_OnePath": { + GoTypeName: "string", + GoFieldName: "One", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "string", + YANGPath: "/openconfig-simple/parent/child/state/one", + }, + "Parent_Child_ThreePath": { + GoTypeName: "E_Child_Three", + GoFieldName: "Three", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumeration", + YANGPath: "/openconfig-simple/parent/child/state/three", + }, + "Parent_Child_TwoPath": { + GoTypeName: "string", + GoFieldName: "Two", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "string", + YANGPath: "/openconfig-simple/parent/child/state/two", + }, + "RemoteContainerPath": { + GoTypeName: "*RemoteContainer", + GoFieldName: "RemoteContainer", + SubsumingGoStructName: "RemoteContainer", + IsLeaf: false, + IsScalarField: false, + YANGPath: "/openconfig-simple/remote-container", + }, + "RemoteContainer_ALeafPath": { + GoTypeName: "string", + GoFieldName: "ALeaf", + SubsumingGoStructName: "RemoteContainer", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "string", + YANGPath: "/openconfig-simple/remote-container/state/a-leaf", }}, }, { name: "simple openconfig test with preferOperationalState=false", inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, inShortenEnumLeafNames: true, wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-simple-intendedconfig.path-txt"), + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantNodeDataMap: NodeDataMap{ - "Parent": { - GoTypeName: "*oc.Parent", - GoFieldName: "Parent", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "Parent_Child": { - GoTypeName: "*oc.Parent_Child", - GoFieldName: "Child", - ParentGoTypeName: "Parent", - IsLeaf: false, - IsScalarField: false, - }, - "Parent_Child_Four": { - GoTypeName: "oc.Binary", - GoFieldName: "Four", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "binary", - }, - "Parent_Child_One": { - GoTypeName: "string", - GoFieldName: "One", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "string", - }, - "Parent_Child_Three": { - GoTypeName: "oc.E_Child_Three", - GoFieldName: "Three", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumeration", - }, - "Parent_Child_Two": { - GoTypeName: "string", - GoFieldName: "Two", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "string", - }, - "RemoteContainer": { - GoTypeName: "*oc.RemoteContainer", - GoFieldName: "RemoteContainer", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "RemoteContainer_ALeaf": { - GoTypeName: "string", - GoFieldName: "ALeaf", - ParentGoTypeName: "RemoteContainer", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "string", + "ParentPath": { + GoTypeName: "*Parent", + GoFieldName: "Parent", + SubsumingGoStructName: "Parent", + IsLeaf: false, + IsScalarField: false, + }, + "Parent_ChildPath": { + GoTypeName: "*Parent_Child", + GoFieldName: "Child", + SubsumingGoStructName: "Parent_Child", + IsLeaf: false, + IsScalarField: false, + }, + "Parent_Child_FourPath": { + GoTypeName: "Binary", + GoFieldName: "Four", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "binary", + }, + "Parent_Child_OnePath": { + GoTypeName: "string", + GoFieldName: "One", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "string", + }, + "Parent_Child_ThreePath": { + GoTypeName: "E_Child_Three", + GoFieldName: "Three", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumeration", + }, + "Parent_Child_TwoPath": { + GoTypeName: "string", + GoFieldName: "Two", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "string", + }, + "RemoteContainerPath": { + GoTypeName: "*RemoteContainer", + GoFieldName: "RemoteContainer", + SubsumingGoStructName: "RemoteContainer", + IsLeaf: false, + IsScalarField: false, + }, + "RemoteContainer_ALeafPath": { + GoTypeName: "string", + GoFieldName: "ALeaf", + SubsumingGoStructName: "RemoteContainer", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "string", }}, }, { name: "simple openconfig test with list", inFiles: []string{filepath.Join(datapath, "openconfig-withlist.yang")}, inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-withlist.path-txt"), + }, { + name: "simple openconfig test with list", + inFiles: []string{filepath.Join(datapath, "openconfig-withlist.yang")}, + inPreferOperationalState: true, + inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "github.com/openconfig/ygot/ypathgen/testdata/exampleoc", + inPathStructSuffix: "", + wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-withlist-separate-package.path-txt"), }, { name: "simple openconfig test with list in builder API", inFiles: []string{filepath.Join(datapath, "openconfig-withlist.yang")}, inListBuilderKeyThreshold: 2, inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-withlist-builder.path-txt"), }, { name: "simple openconfig test with union & typedef & identity & enum", inFiles: []string{filepath.Join(datapath, "openconfig-unione.yang")}, inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-unione.path-txt"), wantNodeDataMap: NodeDataMap{ - "DupEnum": { - GoTypeName: "*oc.DupEnum", - GoFieldName: "DupEnum", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "DupEnum_A": { - GoTypeName: "oc.E_DupEnum_A", - GoFieldName: "A", - ParentGoTypeName: "DupEnum", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumeration", - }, - "DupEnum_B": { - GoTypeName: "oc.E_DupEnum_B", - GoFieldName: "B", - ParentGoTypeName: "DupEnum", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumeration", - }, - "Platform": { - GoTypeName: "*oc.Platform", - GoFieldName: "Platform", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "Platform_Component": { - GoTypeName: "*oc.Platform_Component", - GoFieldName: "Component", - ParentGoTypeName: "Platform", - IsLeaf: false, - IsScalarField: false, - }, - "Platform_Component_E1": { - GoTypeName: "oc.Platform_Component_E1_Union", - GoFieldName: "E1", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumtypedef", - }, - "Platform_Component_Enumerated": { - GoTypeName: "oc.Platform_Component_Enumerated_Union", - GoFieldName: "Enumerated", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumerated-union-type", - }, - "Platform_Component_Power": { - GoTypeName: "oc.Platform_Component_Power_Union", - GoFieldName: "Power", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "union", - }, - "Platform_Component_R1": { - GoTypeName: "oc.Platform_Component_E1_Union", - GoFieldName: "R1", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "leafref", - }, - "Platform_Component_Type": { - GoTypeName: "oc.Platform_Component_Type_Union", - GoFieldName: "Type", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "union", + "DupEnumPath": { + GoTypeName: "*DupEnum", + GoFieldName: "DupEnum", + SubsumingGoStructName: "DupEnum", + IsLeaf: false, + IsScalarField: false, + }, + "DupEnum_APath": { + GoTypeName: "E_DupEnum_A", + GoFieldName: "A", + SubsumingGoStructName: "DupEnum", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumeration", + }, + "DupEnum_BPath": { + GoTypeName: "E_DupEnum_B", + GoFieldName: "B", + SubsumingGoStructName: "DupEnum", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumeration", + }, + "PlatformPath": { + GoTypeName: "*Platform", + GoFieldName: "Platform", + SubsumingGoStructName: "Platform", + IsLeaf: false, + IsScalarField: false, + }, + "Platform_ComponentPath": { + GoTypeName: "*Platform_Component", + GoFieldName: "Component", + SubsumingGoStructName: "Platform_Component", + IsLeaf: false, + IsScalarField: false, + }, + "Platform_Component_E1Path": { + GoTypeName: "Platform_Component_E1_Union", + GoFieldName: "E1", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumtypedef", + }, + "Platform_Component_EnumeratedPath": { + GoTypeName: "Platform_Component_Enumerated_Union", + GoFieldName: "Enumerated", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumerated-union-type", + }, + "Platform_Component_PowerPath": { + GoTypeName: "Platform_Component_Power_Union", + GoFieldName: "Power", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "union", + }, + "Platform_Component_R1Path": { + GoTypeName: "Platform_Component_E1_Union", + GoFieldName: "R1", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "leafref", + }, + "Platform_Component_TypePath": { + GoTypeName: "Platform_Component_Type_Union", + GoFieldName: "Type", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "union", }}, }, { name: "simple openconfig test with union & typedef & identity & enum, with enum names not shortened", inFiles: []string{filepath.Join(datapath, "openconfig-unione.yang")}, inPreferOperationalState: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-unione.path-txt"), wantNodeDataMap: NodeDataMap{ - "DupEnum": { - GoTypeName: "*oc.DupEnum", - GoFieldName: "DupEnum", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "DupEnum_A": { - GoTypeName: "oc.E_OpenconfigUnione_DupEnum_A", - GoFieldName: "A", - ParentGoTypeName: "DupEnum", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumeration", - }, - "DupEnum_B": { - GoTypeName: "oc.E_OpenconfigUnione_DupEnum_B", - GoFieldName: "B", - ParentGoTypeName: "DupEnum", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumeration", - }, - "Platform": { - GoTypeName: "*oc.Platform", - GoFieldName: "Platform", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "Platform_Component": { - GoTypeName: "*oc.Platform_Component", - GoFieldName: "Component", - ParentGoTypeName: "Platform", - IsLeaf: false, - IsScalarField: false, - }, - "Platform_Component_E1": { - GoTypeName: "oc.Platform_Component_E1_Union", - GoFieldName: "E1", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumtypedef", - }, - "Platform_Component_Enumerated": { - GoTypeName: "oc.Platform_Component_Enumerated_Union", - GoFieldName: "Enumerated", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumerated-union-type", - }, - "Platform_Component_Power": { - GoTypeName: "oc.Platform_Component_Power_Union", - GoFieldName: "Power", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "union", - }, - "Platform_Component_R1": { - GoTypeName: "oc.Platform_Component_E1_Union", - GoFieldName: "R1", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "leafref", - }, - "Platform_Component_Type": { - GoTypeName: "oc.Platform_Component_Type_Union", - GoFieldName: "Type", - ParentGoTypeName: "Platform_Component", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "union", + "DupEnumPath": { + GoTypeName: "*DupEnum", + GoFieldName: "DupEnum", + SubsumingGoStructName: "DupEnum", + IsLeaf: false, + IsScalarField: false, + }, + "DupEnum_APath": { + GoTypeName: "E_OpenconfigUnione_DupEnum_A", + GoFieldName: "A", + SubsumingGoStructName: "DupEnum", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumeration", + }, + "DupEnum_BPath": { + GoTypeName: "E_OpenconfigUnione_DupEnum_B", + GoFieldName: "B", + SubsumingGoStructName: "DupEnum", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumeration", + }, + "PlatformPath": { + GoTypeName: "*Platform", + GoFieldName: "Platform", + SubsumingGoStructName: "Platform", + IsLeaf: false, + IsScalarField: false, + }, + "Platform_ComponentPath": { + GoTypeName: "*Platform_Component", + GoFieldName: "Component", + SubsumingGoStructName: "Platform_Component", + IsLeaf: false, + IsScalarField: false, + }, + "Platform_Component_E1Path": { + GoTypeName: "Platform_Component_E1_Union", + GoFieldName: "E1", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumtypedef", + }, + "Platform_Component_EnumeratedPath": { + GoTypeName: "Platform_Component_Enumerated_Union", + GoFieldName: "Enumerated", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumerated-union-type", + }, + "Platform_Component_PowerPath": { + GoTypeName: "Platform_Component_Power_Union", + GoFieldName: "Power", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "union", + }, + "Platform_Component_R1Path": { + GoTypeName: "Platform_Component_E1_Union", + GoFieldName: "R1", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "leafref", + }, + "Platform_Component_TypePath": { + GoTypeName: "Platform_Component_Type_Union", + GoFieldName: "Type", + SubsumingGoStructName: "Platform_Component", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "union", }}, }, { name: "simple openconfig test with submodule and union list key", inFiles: []string{filepath.Join(datapath, "enum-module.yang")}, inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/enum-module.path-txt"), wantNodeDataMap: NodeDataMap{ - "AList": { - GoTypeName: "*oc.AList", - GoFieldName: "AList", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "AList_Value": { - GoTypeName: "oc.AList_Value_Union", - GoFieldName: "Value", - ParentGoTypeName: "AList", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "td", - }, - "BList": { - GoTypeName: "*oc.BList", - GoFieldName: "BList", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "BList_Value": { - GoTypeName: "oc.BList_Value_Union", - GoFieldName: "Value", - ParentGoTypeName: "BList", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "td", - }, - "C": { - GoTypeName: "*oc.C", - GoFieldName: "C", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "C_Cl": { - GoTypeName: "oc.E_EnumModule_Cl", - GoFieldName: "Cl", - ParentGoTypeName: "C", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "enumeration", - }, - "Parent": { - GoTypeName: "*oc.Parent", - GoFieldName: "Parent", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, - }, - "Parent_Child": { - GoTypeName: "*oc.Parent_Child", - GoFieldName: "Child", - ParentGoTypeName: "Parent", - IsLeaf: false, - IsScalarField: false, - }, - "Parent_Child_Id": { - GoTypeName: "oc.E_EnumTypes_ID", - GoFieldName: "Id", - ParentGoTypeName: "Parent_Child", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "identityref", + "AListPath": { + GoTypeName: "*AList", + GoFieldName: "AList", + SubsumingGoStructName: "AList", + IsLeaf: false, + IsScalarField: false, + }, + "AList_ValuePath": { + GoTypeName: "AList_Value_Union", + GoFieldName: "Value", + SubsumingGoStructName: "AList", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "td", + }, + "BListPath": { + GoTypeName: "*BList", + GoFieldName: "BList", + SubsumingGoStructName: "BList", + IsLeaf: false, + IsScalarField: false, + }, + "BList_ValuePath": { + GoTypeName: "BList_Value_Union", + GoFieldName: "Value", + SubsumingGoStructName: "BList", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "td", + }, + "CPath": { + GoTypeName: "*C", + GoFieldName: "C", + SubsumingGoStructName: "C", + IsLeaf: false, + IsScalarField: false, + }, + "C_ClPath": { + GoTypeName: "E_EnumModule_Cl", + GoFieldName: "Cl", + SubsumingGoStructName: "C", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "enumeration", + }, + "ParentPath": { + GoTypeName: "*Parent", + GoFieldName: "Parent", + SubsumingGoStructName: "Parent", + IsLeaf: false, + IsScalarField: false, + }, + "Parent_ChildPath": { + GoTypeName: "*Parent_Child", + GoFieldName: "Child", + SubsumingGoStructName: "Parent_Child", + IsLeaf: false, + IsScalarField: false, + }, + "Parent_Child_IdPath": { + GoTypeName: "E_EnumTypes_ID", + GoFieldName: "Id", + SubsumingGoStructName: "Parent_Child", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "identityref", }}, }, { name: "simple openconfig test with choice and cases", inFiles: []string{filepath.Join(datapath, "choice-case-example.yang")}, inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/choice-case-example.path-txt"), }, { name: "simple openconfig test with augmentations", @@ -468,67 +499,74 @@ func TestGeneratePathCode(t *testing.T) { }, inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "github.com/openconfig/ygot/ypathgen/testdata/exampleoc", + inPathStructSuffix: "", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-augmented.path-txt"), wantNodeDataMap: NodeDataMap{ "Native": { - GoTypeName: "*oc.Native", - GoFieldName: "Native", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, + GoTypeName: "*oc.Native", + GoFieldName: "Native", + SubsumingGoStructName: "Native", + IsLeaf: false, + IsScalarField: false, }, "Native_A": { - GoTypeName: "string", - GoFieldName: "A", - ParentGoTypeName: "Native", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "string", + GoTypeName: "string", + GoFieldName: "A", + SubsumingGoStructName: "Native", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "string", }, "Target": { - GoTypeName: "*oc.Target", - GoFieldName: "Target", - ParentGoTypeName: "Device", - IsLeaf: false, - IsScalarField: false, + GoTypeName: "*oc.Target", + GoFieldName: "Target", + SubsumingGoStructName: "Target", + IsLeaf: false, + IsScalarField: false, }, "Target_Foo": { - GoTypeName: "*oc.Target_Foo", - GoFieldName: "Foo", - ParentGoTypeName: "Target", - IsLeaf: false, - IsScalarField: false, + GoTypeName: "*oc.Target_Foo", + GoFieldName: "Foo", + SubsumingGoStructName: "Target_Foo", + IsLeaf: false, + IsScalarField: false, }, "Target_Foo_A": { - GoTypeName: "string", - GoFieldName: "A", - ParentGoTypeName: "Target_Foo", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "string", + GoTypeName: "string", + GoFieldName: "A", + SubsumingGoStructName: "Target_Foo", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "string", }}, }, { name: "simple openconfig test with camelcase-name extension", inFiles: []string{filepath.Join(datapath, "openconfig-enumcamelcase.yang")}, inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-enumcamelcase.path-txt"), }, { name: "simple openconfig test with camelcase-name extension in container and leaf", inFiles: []string{filepath.Join(datapath, "openconfig-camelcase.yang")}, inPreferOperationalState: true, inShortenEnumLeafNames: true, + inSchemaStructPkgPath: "", + inPathStructSuffix: "Path", wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/openconfig-camelcase.path-txt"), }} for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name+":"+strings.Join(tt.inFiles, ","), func(t *testing.T) { genCode := func() (string, NodeDataMap, *GenConfig) { - cg := NewDefaultConfig("github.com/openconfig/ygot/ypathgen/testdata/exampleoc") + cg := NewDefaultConfig(tt.inSchemaStructPkgPath) // Set the name of the caller explicitly to avoid issues when // the unit tests are called by external test entities. cg.GeneratingBinary = "pathgen-tests" cg.FakeRootName = "device" + cg.PathStructSuffix = tt.inPathStructSuffix cg.PreferOperationalState = tt.inPreferOperationalState cg.ListBuilderKeyThreshold = tt.inListBuilderKeyThreshold cg.ShortenEnumLeafNames = tt.inShortenEnumLeafNames @@ -582,37 +620,43 @@ func TestGeneratePathCode(t *testing.T) { func TestGeneratePathCodeSplitFiles(t *testing.T) { tests := []struct { - name string // Name is the identifier for the test. - inFiles []string // inFiles is the set of inputFiles for the test. - inIncludePaths []string // inIncludePaths is the set of paths that should be searched for imports. - inFileNumber int // inFileNumber is the number of files into which to split the generated code. - wantStructsCodeFiles []string // wantStructsCodeFiles is the paths of the generated Go code that the output of the test should be compared to. - wantErr bool // whether an error is expected from the SplitFiles call + name string // Name is the identifier for the test. + inFiles []string // inFiles is the set of inputFiles for the test. + inIncludePaths []string // inIncludePaths is the set of paths that should be searched for imports. + inFileNumber int // inFileNumber is the number of files into which to split the generated code. + inSchemaStructPkgPath string + wantStructsCodeFiles []string // wantStructsCodeFiles is the paths of the generated Go code that the output of the test should be compared to. + wantErr bool // whether an error is expected from the SplitFiles call }{{ - name: "fileNumber is higher than total number of structs", - inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, - inFileNumber: 5, - wantErr: true, + name: "fileNumber is higher than total number of structs", + inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, + inFileNumber: 5, + inSchemaStructPkgPath: "", + wantErr: true, }, { - name: "fileNumber is exactly the total number of structs", - inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, - inFileNumber: 4, - wantStructsCodeFiles: []string{filepath.Join(TestRoot, "testdata/structs/openconfig-simple-40.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-41.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-42.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-43.path-txt")}, + name: "fileNumber is exactly the total number of structs", + inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, + inFileNumber: 4, + inSchemaStructPkgPath: "github.com/openconfig/ygot/ypathgen/testdata/exampleoc", + wantStructsCodeFiles: []string{filepath.Join(TestRoot, "testdata/structs/openconfig-simple-40.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-41.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-42.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-43.path-txt")}, }, { - name: "fileNumber is just under the total number of structs", - inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, - inFileNumber: 3, - wantStructsCodeFiles: []string{filepath.Join(TestRoot, "testdata/structs/openconfig-simple-30.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-31.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-32.path-txt")}, + name: "fileNumber is just under the total number of structs", + inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, + inFileNumber: 3, + inSchemaStructPkgPath: "", + wantStructsCodeFiles: []string{filepath.Join(TestRoot, "testdata/structs/openconfig-simple-30.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-31.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-32.path-txt")}, }, { - name: "fileNumber is half the total number of structs", - inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, - inFileNumber: 2, - wantStructsCodeFiles: []string{filepath.Join(TestRoot, "testdata/structs/openconfig-simple-0.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-1.path-txt")}, + name: "fileNumber is half the total number of structs", + inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, + inFileNumber: 2, + inSchemaStructPkgPath: "github.com/openconfig/ygot/ypathgen/testdata/exampleoc", + wantStructsCodeFiles: []string{filepath.Join(TestRoot, "testdata/structs/openconfig-simple-0.path-txt"), filepath.Join(TestRoot, "testdata/structs/openconfig-simple-1.path-txt")}, }, { - name: "single file", - inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, - inFileNumber: 1, - wantStructsCodeFiles: []string{filepath.Join(TestRoot, "testdata/structs/openconfig-simple.path-txt")}, + name: "single file", + inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, + inFileNumber: 1, + inSchemaStructPkgPath: "", + wantStructsCodeFiles: []string{filepath.Join(TestRoot, "testdata/structs/openconfig-simple.path-txt")}, }, { name: "fileNumber is 0", inFiles: []string{filepath.Join(datapath, "openconfig-simple.yang")}, @@ -621,13 +665,18 @@ func TestGeneratePathCodeSplitFiles(t *testing.T) { }} for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run(tt.name+":"+strings.Join(tt.inFiles, ","), func(t *testing.T) { genCode := func() ([]string, *GenConfig) { - cg := NewDefaultConfig("github.com/openconfig/ygot/ypathgen/testdata/exampleoc") + cg := NewDefaultConfig(tt.inSchemaStructPkgPath) // Set the name of the caller explicitly to avoid issues when // the unit tests are called by external test entities. cg.GeneratingBinary = "pathgen-tests" cg.FakeRootName = "device" + if tt.inSchemaStructPkgPath == "" { + cg.PathStructSuffix = "Path" + } else { + cg.PathStructSuffix = "" + } cg.PreferOperationalState = true gotCode, _, err := cg.GeneratePathCode(tt.inFiles, tt.inIncludePaths) @@ -924,9 +973,9 @@ func getSchemaAndDirs() (*yang.Entry, map[string]*ygen.Directory, map[string]map // wantListMethods is the expected child constructor methods for the list node. const wantListMethods = ` -// ListAny returns from Root the path struct for its child "list". -func (n *Root) ListAny() *ListAny { - return &ListAny{ +// ListAny returns from RootPath the path struct for its child "list". +func (n *RootPath) ListAny() *ListPathAny { + return &ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": "*", "key2": "*", "union-key": "*"}, @@ -935,9 +984,9 @@ func (n *Root) ListAny() *ListAny { } } -// ListAnyKey2AnyUnionKey returns from Root the path struct for its child "list". -func (n *Root) ListAnyKey2AnyUnionKey(Key1 string) *ListAny { - return &ListAny{ +// ListAnyKey2AnyUnionKey returns from RootPath the path struct for its child "list". +func (n *RootPath) ListAnyKey2AnyUnionKey(Key1 string) *ListPathAny { + return &ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": Key1, "key2": "*", "union-key": "*"}, @@ -946,9 +995,9 @@ func (n *Root) ListAnyKey2AnyUnionKey(Key1 string) *ListAny { } } -// ListAnyKey1AnyUnionKey returns from Root the path struct for its child "list". -func (n *Root) ListAnyKey1AnyUnionKey(Key2 oc.Binary) *ListAny { - return &ListAny{ +// ListAnyKey1AnyUnionKey returns from RootPath the path struct for its child "list". +func (n *RootPath) ListAnyKey1AnyUnionKey(Key2 oc.Binary) *ListPathAny { + return &ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": "*", "key2": Key2, "union-key": "*"}, @@ -957,9 +1006,9 @@ func (n *Root) ListAnyKey1AnyUnionKey(Key2 oc.Binary) *ListAny { } } -// ListAnyUnionKey returns from Root the path struct for its child "list". -func (n *Root) ListAnyUnionKey(Key1 string, Key2 oc.Binary) *ListAny { - return &ListAny{ +// ListAnyUnionKey returns from RootPath the path struct for its child "list". +func (n *RootPath) ListAnyUnionKey(Key1 string, Key2 oc.Binary) *ListPathAny { + return &ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": Key1, "key2": Key2, "union-key": "*"}, @@ -968,9 +1017,9 @@ func (n *Root) ListAnyUnionKey(Key1 string, Key2 oc.Binary) *ListAny { } } -// ListAnyKey1AnyKey2 returns from Root the path struct for its child "list". -func (n *Root) ListAnyKey1AnyKey2(UnionKey oc.RootModule_List_UnionKey_Union) *ListAny { - return &ListAny{ +// ListAnyKey1AnyKey2 returns from RootPath the path struct for its child "list". +func (n *RootPath) ListAnyKey1AnyKey2(UnionKey oc.RootModule_List_UnionKey_Union) *ListPathAny { + return &ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": "*", "key2": "*", "union-key": UnionKey}, @@ -979,9 +1028,9 @@ func (n *Root) ListAnyKey1AnyKey2(UnionKey oc.RootModule_List_UnionKey_Union) *L } } -// ListAnyKey2 returns from Root the path struct for its child "list". -func (n *Root) ListAnyKey2(Key1 string, UnionKey oc.RootModule_List_UnionKey_Union) *ListAny { - return &ListAny{ +// ListAnyKey2 returns from RootPath the path struct for its child "list". +func (n *RootPath) ListAnyKey2(Key1 string, UnionKey oc.RootModule_List_UnionKey_Union) *ListPathAny { + return &ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": Key1, "key2": "*", "union-key": UnionKey}, @@ -990,9 +1039,9 @@ func (n *Root) ListAnyKey2(Key1 string, UnionKey oc.RootModule_List_UnionKey_Uni } } -// ListAnyKey1 returns from Root the path struct for its child "list". -func (n *Root) ListAnyKey1(Key2 oc.Binary, UnionKey oc.RootModule_List_UnionKey_Union) *ListAny { - return &ListAny{ +// ListAnyKey1 returns from RootPath the path struct for its child "list". +func (n *RootPath) ListAnyKey1(Key2 oc.Binary, UnionKey oc.RootModule_List_UnionKey_Union) *ListPathAny { + return &ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": "*", "key2": Key2, "union-key": UnionKey}, @@ -1001,9 +1050,9 @@ func (n *Root) ListAnyKey1(Key2 oc.Binary, UnionKey oc.RootModule_List_UnionKey_ } } -// List returns from Root the path struct for its child "list". -func (n *Root) List(Key1 string, Key2 oc.Binary, UnionKey oc.RootModule_List_UnionKey_Union) *List { - return &List{ +// List returns from RootPath the path struct for its child "list". +func (n *RootPath) List(Key1 string, Key2 oc.Binary, UnionKey oc.RootModule_List_UnionKey_Union) *ListPath { + return &ListPath{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": Key1, "key2": Key2, "union-key": UnionKey}, @@ -1068,13 +1117,14 @@ func TestGetNodeDataMap(t *testing.T) { } tests := []struct { - name string - inDirectories map[string]*ygen.Directory - inLeafTypeMap map[string]map[string]*ygen.MappedType - inSchemaStructPkgAlias string - wantNodeDataMap NodeDataMap - wantSorted []string - wantErrSubstrings []string + name string + inDirectories map[string]*ygen.Directory + inLeafTypeMap map[string]map[string]*ygen.MappedType + inSchemaStructPkgAccessor string + inPathStructSuffix string + wantNodeDataMap NodeDataMap + wantSorted []string + wantErrSubstrings []string }{{ name: "scalar leaf", inDirectories: map[string]*ygen.Directory{"/root-module/container": directories["/root-module/container"]}, @@ -1083,40 +1133,42 @@ func TestGetNodeDataMap(t *testing.T) { "leaf": leafTypeMap["/root-module/container"]["leaf"], }, }, - inSchemaStructPkgAlias: "struct", + inSchemaStructPkgAccessor: "struct.", + inPathStructSuffix: "Path", wantNodeDataMap: NodeDataMap{ - "Container_Leaf": { - GoTypeName: "int32", - GoFieldName: "Leaf", - ParentGoTypeName: "Container", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "int32", + "Container_LeafPath": { + GoTypeName: "int32", + GoFieldName: "Leaf", + SubsumingGoStructName: "Container", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "int32", }, }, - wantSorted: []string{"Container_Leaf"}, + wantSorted: []string{"Container_LeafPath"}, }, { - name: "non-leaf and non-scalar leaf", - inDirectories: directoryWithBinaryLeaf, - inLeafTypeMap: leafTypeMap2, - inSchemaStructPkgAlias: "struct", + name: "non-leaf and non-scalar leaf", + inDirectories: directoryWithBinaryLeaf, + inLeafTypeMap: leafTypeMap2, + inSchemaStructPkgAccessor: "struct.", + inPathStructSuffix: "_Path", wantNodeDataMap: NodeDataMap{ - "Container": { - GoTypeName: "*struct.Container", - GoFieldName: "Container", - ParentGoTypeName: "Root", - IsLeaf: false, - IsScalarField: false, - }, - "Container_Leaf": { - GoTypeName: "struct.Binary", - GoFieldName: "Leaf", - ParentGoTypeName: "Container", - IsLeaf: true, - IsScalarField: false, + "Container_Path": { + GoTypeName: "*struct.Container", + GoFieldName: "Container", + SubsumingGoStructName: "Container", + IsLeaf: false, + IsScalarField: false, + }, + "Container_Leaf_Path": { + GoTypeName: "struct.Binary", + GoFieldName: "Leaf", + SubsumingGoStructName: "Container", + IsLeaf: true, + IsScalarField: false, }, }, - wantSorted: []string{"Container", "Container_Leaf"}, + wantSorted: []string{"Container_Leaf_Path", "Container_Path"}, }, { name: "non-existent path", inDirectories: map[string]*ygen.Directory{"/root-module/container": directories["/root-module/container"]}, @@ -1128,8 +1180,9 @@ func TestGetNodeDataMap(t *testing.T) { "leaf": {NativeType: "Binary"}, }, }, - inSchemaStructPkgAlias: "oc", - wantErrSubstrings: []string{`path "/root-module/container" does not exist`}, + inSchemaStructPkgAccessor: "oc.", + inPathStructSuffix: "Path", + wantErrSubstrings: []string{`path "/root-module/container" does not exist`}, }, { name: "non-existent field", inDirectories: map[string]*ygen.Directory{"/root-module/container": directories["/root-module/container"]}, @@ -1141,127 +1194,128 @@ func TestGetNodeDataMap(t *testing.T) { "laugh": leafTypeMap["/root-module/container"]["leaf"], }, }, - inSchemaStructPkgAlias: "oc", - wantErrSubstrings: []string{`field name "leaf" does not exist`}, + inSchemaStructPkgAccessor: "oc.", + inPathStructSuffix: "Path", + wantErrSubstrings: []string{`field name "leaf" does not exist`}, }, { - name: "big test with everything", - inDirectories: directories, - inLeafTypeMap: leafTypeMap, - inSchemaStructPkgAlias: "oc", + name: "big test with everything", + inDirectories: directories, + inLeafTypeMap: leafTypeMap, + inPathStructSuffix: "Path", wantNodeDataMap: NodeDataMap{ - "Container": { - GoTypeName: "*oc.Container", - GoFieldName: "Container", - ParentGoTypeName: "Root", - IsLeaf: false, - IsScalarField: false, - }, - "ContainerWithConfig": { - GoTypeName: "*oc.ContainerWithConfig", - GoFieldName: "ContainerWithConfig", - ParentGoTypeName: "Root", - IsLeaf: false, - IsScalarField: false, - }, - "ContainerWithConfig_Leaf": { - GoTypeName: "oc.Binary", - GoFieldName: "Leaf", - ParentGoTypeName: "ContainerWithConfig", - IsLeaf: true, - IsScalarField: false, - }, - "ContainerWithConfig_Leaflist": { - GoTypeName: "[]uint32", - GoFieldName: "Leaflist", - ParentGoTypeName: "ContainerWithConfig", - IsLeaf: true, - IsScalarField: false, - }, - "ContainerWithConfig_Leaflist2": { - GoTypeName: "[]oc.Binary", - GoFieldName: "Leaflist2", - ParentGoTypeName: "ContainerWithConfig", - IsLeaf: true, - IsScalarField: false, - }, - "Container_Leaf": { - GoTypeName: "int32", - GoFieldName: "Leaf", - ParentGoTypeName: "Container", - IsLeaf: true, - IsScalarField: true, - YANGTypeName: "int32", - }, - "Leaf": { - GoTypeName: "oc.Binary", - GoFieldName: "Leaf", - ParentGoTypeName: "Root", - IsLeaf: true, - IsScalarField: false, - YANGTypeName: "ieeefloat32", - }, - "List": { - GoTypeName: "*oc.List", - GoFieldName: "List", - ParentGoTypeName: "Root", - IsLeaf: false, - IsScalarField: false, - }, - "ListWithState": { - GoTypeName: "*oc.ListWithState", - GoFieldName: "ListWithState", - ParentGoTypeName: "Root", - IsLeaf: false, - IsScalarField: false, - }, - "ListWithState_Key": { - GoTypeName: "float64", - GoFieldName: "Key", - ParentGoTypeName: "ListWithState", - IsLeaf: true, - IsScalarField: true, - }, - "List_Key1": { - GoTypeName: "string", - GoFieldName: "Key1", - ParentGoTypeName: "List", - IsLeaf: true, - IsScalarField: true, - }, - "List_Key2": { - GoTypeName: "oc.Binary", - GoFieldName: "Key2", - ParentGoTypeName: "List", - IsLeaf: true, - IsScalarField: false, - }, - "List_UnionKey": { - GoTypeName: "oc.RootModule_List_UnionKey_Union", - GoFieldName: "UnionKey", - ParentGoTypeName: "List", - IsLeaf: true, - IsScalarField: false, + "ContainerPath": { + GoTypeName: "*Container", + GoFieldName: "Container", + SubsumingGoStructName: "Container", + IsLeaf: false, + IsScalarField: false, + }, + "ContainerWithConfigPath": { + GoTypeName: "*ContainerWithConfig", + GoFieldName: "ContainerWithConfig", + SubsumingGoStructName: "ContainerWithConfig", + IsLeaf: false, + IsScalarField: false, + }, + "ContainerWithConfig_LeafPath": { + GoTypeName: "Binary", + GoFieldName: "Leaf", + SubsumingGoStructName: "ContainerWithConfig", + IsLeaf: true, + IsScalarField: false, + }, + "ContainerWithConfig_LeaflistPath": { + GoTypeName: "[]uint32", + GoFieldName: "Leaflist", + SubsumingGoStructName: "ContainerWithConfig", + IsLeaf: true, + IsScalarField: false, + }, + "ContainerWithConfig_Leaflist2Path": { + GoTypeName: "[]Binary", + GoFieldName: "Leaflist2", + SubsumingGoStructName: "ContainerWithConfig", + IsLeaf: true, + IsScalarField: false, + }, + "Container_LeafPath": { + GoTypeName: "int32", + GoFieldName: "Leaf", + SubsumingGoStructName: "Container", + IsLeaf: true, + IsScalarField: true, + YANGTypeName: "int32", + }, + "LeafPath": { + GoTypeName: "Binary", + GoFieldName: "Leaf", + SubsumingGoStructName: "Root", + IsLeaf: true, + IsScalarField: false, + YANGTypeName: "ieeefloat32", + }, + "ListPath": { + GoTypeName: "*List", + GoFieldName: "List", + SubsumingGoStructName: "List", + IsLeaf: false, + IsScalarField: false, + }, + "ListWithStatePath": { + GoTypeName: "*ListWithState", + GoFieldName: "ListWithState", + SubsumingGoStructName: "ListWithState", + IsLeaf: false, + IsScalarField: false, + }, + "ListWithState_KeyPath": { + GoTypeName: "float64", + GoFieldName: "Key", + SubsumingGoStructName: "ListWithState", + IsLeaf: true, + IsScalarField: true, + }, + "List_Key1Path": { + GoTypeName: "string", + GoFieldName: "Key1", + SubsumingGoStructName: "List", + IsLeaf: true, + IsScalarField: true, + }, + "List_Key2Path": { + GoTypeName: "Binary", + GoFieldName: "Key2", + SubsumingGoStructName: "List", + IsLeaf: true, + IsScalarField: false, + }, + "List_UnionKeyPath": { + GoTypeName: "RootModule_List_UnionKey_Union", + GoFieldName: "UnionKey", + SubsumingGoStructName: "List", + IsLeaf: true, + IsScalarField: false, }}, wantSorted: []string{ - "Container", - "ContainerWithConfig", - "ContainerWithConfig_Leaf", - "ContainerWithConfig_Leaflist", - "ContainerWithConfig_Leaflist2", - "Container_Leaf", - "Leaf", - "List", - "ListWithState", - "ListWithState_Key", - "List_Key1", - "List_Key2", - "List_UnionKey", + "ContainerPath", + "ContainerWithConfigPath", + "ContainerWithConfig_LeafPath", + "ContainerWithConfig_Leaflist2Path", + "ContainerWithConfig_LeaflistPath", + "Container_LeafPath", + "LeafPath", + "ListPath", + "ListWithStatePath", + "ListWithState_KeyPath", + "List_Key1Path", + "List_Key2Path", + "List_UnionKeyPath", }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, gotErrs := getNodeDataMap(tt.inDirectories, tt.inLeafTypeMap, tt.inSchemaStructPkgAlias) + got, gotErrs := getNodeDataMap(tt.inDirectories, tt.inLeafTypeMap, tt.inSchemaStructPkgAccessor, tt.inPathStructSuffix) // TODO(wenbli): Enhance gNMI's errdiff with checking a slice of substrings and use here. var gotErrStrs []string for _, err := range gotErrs { @@ -1287,6 +1341,7 @@ func TestGenerateDirectorySnippet(t *testing.T) { name string inDirectory *ygen.Directory inListBuilderKeyThreshold uint + inPathStructSuffix string want GoPathStructCodeSnippet }{{ name: "container-with-config", @@ -1403,35 +1458,36 @@ func (n *ContainerWithConfigAny) Leaflist2() *ContainerWithConfig_Leaflist2Any { `, }, }, { - name: "fakeroot", - inDirectory: directories["/root"], + name: "fakeroot", + inDirectory: directories["/root"], + inPathStructSuffix: "Path", want: GoPathStructCodeSnippet{ - PathStructName: "Root", + PathStructName: "RootPath", StructBase: ` -// Root represents the /root YANG schema element. -type Root struct { +// RootPath represents the /root YANG schema element. +type RootPath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Root { - return &Root{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *RootPath { + return &RootPath{ygot.NewDeviceRootBase(id)} } -// Leaf represents the /root-module/leaf YANG schema element. -type Leaf struct { +// LeafPath represents the /root-module/leaf YANG schema element. +type LeafPath struct { *ygot.NodePath } -// LeafAny represents the wildcard version of the /root-module/leaf YANG schema element. -type LeafAny struct { +// LeafPathAny represents the wildcard version of the /root-module/leaf YANG schema element. +type LeafPathAny struct { *ygot.NodePath } `, ChildConstructors: ` -// Container returns from Root the path struct for its child "container". -func (n *Root) Container() *Container { - return &Container{ +// Container returns from RootPath the path struct for its child "container". +func (n *RootPath) Container() *ContainerPath { + return &ContainerPath{ NodePath: ygot.NewNodePath( []string{"container"}, map[string]interface{}{}, @@ -1440,9 +1496,9 @@ func (n *Root) Container() *Container { } } -// ContainerWithConfig returns from Root the path struct for its child "container-with-config". -func (n *Root) ContainerWithConfig() *ContainerWithConfig { - return &ContainerWithConfig{ +// ContainerWithConfig returns from RootPath the path struct for its child "container-with-config". +func (n *RootPath) ContainerWithConfig() *ContainerWithConfigPath { + return &ContainerWithConfigPath{ NodePath: ygot.NewNodePath( []string{"container-with-config"}, map[string]interface{}{}, @@ -1451,9 +1507,9 @@ func (n *Root) ContainerWithConfig() *ContainerWithConfig { } } -// Leaf returns from Root the path struct for its child "leaf". -func (n *Root) Leaf() *Leaf { - return &Leaf{ +// Leaf returns from RootPath the path struct for its child "leaf". +func (n *RootPath) Leaf() *LeafPath { + return &LeafPath{ NodePath: ygot.NewNodePath( []string{"leaf"}, map[string]interface{}{}, @@ -1462,9 +1518,9 @@ func (n *Root) Leaf() *Leaf { } } ` + wantListMethods + ` -// ListWithStateAny returns from Root the path struct for its child "list-with-state". -func (n *Root) ListWithStateAny() *ListWithStateAny { - return &ListWithStateAny{ +// ListWithStateAny returns from RootPath the path struct for its child "list-with-state". +func (n *RootPath) ListWithStateAny() *ListWithStatePathAny { + return &ListWithStatePathAny{ NodePath: ygot.NewNodePath( []string{"list-container-with-state", "list-with-state"}, map[string]interface{}{"key": "*"}, @@ -1473,9 +1529,9 @@ func (n *Root) ListWithStateAny() *ListWithStateAny { } } -// ListWithState returns from Root the path struct for its child "list-with-state". -func (n *Root) ListWithState(Key float64) *ListWithState { - return &ListWithState{ +// ListWithState returns from RootPath the path struct for its child "list-with-state". +func (n *RootPath) ListWithState(Key float64) *ListWithStatePath { + return &ListWithStatePath{ NodePath: ygot.NewNodePath( []string{"list-container-with-state", "list-with-state"}, map[string]interface{}{"key": Key}, @@ -1603,7 +1659,7 @@ func (n *ListAny) UnionKey() *List_UnionKeyAny { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, gotErr := generateDirectorySnippet(tt.inDirectory, directories, "oc", tt.inListBuilderKeyThreshold) + got, gotErr := generateDirectorySnippet(tt.inDirectory, directories, "oc.", tt.inPathStructSuffix, tt.inListBuilderKeyThreshold) if gotErr != nil { t.Fatalf("func generateDirectorySnippet, unexpected error: %v", gotErr) } @@ -1722,17 +1778,19 @@ func TestGenerateChildConstructor(t *testing.T) { inFieldName string inUniqueFieldName string inListBuilderKeyThreshold uint + inPathStructSuffix string want string }{{ - name: "container method", - inDirectory: directories["/root"], - inDirectories: directories, - inFieldName: "container", - inUniqueFieldName: "Container", + name: "container method", + inDirectory: directories["/root"], + inDirectories: directories, + inFieldName: "container", + inUniqueFieldName: "Container", + inPathStructSuffix: "Path", want: ` -// Container returns from Root the path struct for its child "container". -func (n *Root) Container() *Container { - return &Container{ +// Container returns from RootPath the path struct for its child "container". +func (n *RootPath) Container() *ContainerPath { + return &ContainerPath{ NodePath: ygot.NewNodePath( []string{"container"}, map[string]interface{}{}, @@ -1742,15 +1800,16 @@ func (n *Root) Container() *Container { } `, }, { - name: "container leaf method", - inDirectory: directories["/root-module/container"], - inDirectories: directories, - inFieldName: "leaf", - inUniqueFieldName: "Leaf", + name: "container leaf method", + inDirectory: directories["/root-module/container"], + inDirectories: directories, + inFieldName: "leaf", + inUniqueFieldName: "Leaf", + inPathStructSuffix: "Path", want: ` -// Leaf returns from Container the path struct for its child "leaf". -func (n *Container) Leaf() *Container_Leaf { - return &Container_Leaf{ +// Leaf returns from ContainerPath the path struct for its child "leaf". +func (n *ContainerPath) Leaf() *Container_LeafPath { + return &Container_LeafPath{ NodePath: ygot.NewNodePath( []string{"leaf"}, map[string]interface{}{}, @@ -1759,9 +1818,9 @@ func (n *Container) Leaf() *Container_Leaf { } } -// Leaf returns from ContainerAny the path struct for its child "leaf". -func (n *ContainerAny) Leaf() *Container_LeafAny { - return &Container_LeafAny{ +// Leaf returns from ContainerPathAny the path struct for its child "leaf". +func (n *ContainerPathAny) Leaf() *Container_LeafPathAny { + return &Container_LeafPathAny{ NodePath: ygot.NewNodePath( []string{"leaf"}, map[string]interface{}{}, @@ -1771,15 +1830,16 @@ func (n *ContainerAny) Leaf() *Container_LeafAny { } `, }, { - name: "top-level leaf method", - inDirectory: directories["/root"], - inDirectories: directories, - inFieldName: "leaf", - inUniqueFieldName: "Leaf", + name: "top-level leaf method", + inDirectory: directories["/root"], + inDirectories: directories, + inFieldName: "leaf", + inUniqueFieldName: "Leaf", + inPathStructSuffix: "Path", want: ` -// Leaf returns from Root the path struct for its child "leaf". -func (n *Root) Leaf() *Leaf { - return &Leaf{ +// Leaf returns from RootPath the path struct for its child "leaf". +func (n *RootPath) Leaf() *LeafPath { + return &LeafPath{ NodePath: ygot.NewNodePath( []string{"leaf"}, map[string]interface{}{}, @@ -1789,15 +1849,16 @@ func (n *Root) Leaf() *Leaf { } `, }, { - name: "container-with-config leaf method", - inDirectory: directories["/root-module/container-with-config"], - inDirectories: directories, - inFieldName: "leaf", - inUniqueFieldName: "Leaf", + name: "container-with-config leaf method", + inDirectory: directories["/root-module/container-with-config"], + inDirectories: directories, + inFieldName: "leaf", + inUniqueFieldName: "Leaf", + inPathStructSuffix: "Path", want: ` -// Leaf returns from ContainerWithConfig the path struct for its child "leaf". -func (n *ContainerWithConfig) Leaf() *ContainerWithConfig_Leaf { - return &ContainerWithConfig_Leaf{ +// Leaf returns from ContainerWithConfigPath the path struct for its child "leaf". +func (n *ContainerWithConfigPath) Leaf() *ContainerWithConfig_LeafPath { + return &ContainerWithConfig_LeafPath{ NodePath: ygot.NewNodePath( []string{"state", "leaf"}, map[string]interface{}{}, @@ -1806,9 +1867,9 @@ func (n *ContainerWithConfig) Leaf() *ContainerWithConfig_Leaf { } } -// Leaf returns from ContainerWithConfigAny the path struct for its child "leaf". -func (n *ContainerWithConfigAny) Leaf() *ContainerWithConfig_LeafAny { - return &ContainerWithConfig_LeafAny{ +// Leaf returns from ContainerWithConfigPathAny the path struct for its child "leaf". +func (n *ContainerWithConfigPathAny) Leaf() *ContainerWithConfig_LeafPathAny { + return &ContainerWithConfig_LeafPathAny{ NodePath: ygot.NewNodePath( []string{"state", "leaf"}, map[string]interface{}{}, @@ -1818,15 +1879,16 @@ func (n *ContainerWithConfigAny) Leaf() *ContainerWithConfig_LeafAny { } `, }, { - name: "2nd-level list methods", - inDirectory: deepSchemaDirectories["/root-module/container"], - inDirectories: deepSchemaDirectories, - inFieldName: "list", - inUniqueFieldName: "List", + name: "2nd-level list methods", + inDirectory: deepSchemaDirectories["/root-module/container"], + inDirectories: deepSchemaDirectories, + inFieldName: "list", + inUniqueFieldName: "List", + inPathStructSuffix: "Path", want: ` -// ListAny returns from Container the path struct for its child "list". -func (n *Container) ListAny() *Container_ListAny { - return &Container_ListAny{ +// ListAny returns from ContainerPath the path struct for its child "list". +func (n *ContainerPath) ListAny() *Container_ListPathAny { + return &Container_ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key": "*"}, @@ -1835,9 +1897,9 @@ func (n *Container) ListAny() *Container_ListAny { } } -// ListAny returns from ContainerAny the path struct for its child "list". -func (n *ContainerAny) ListAny() *Container_ListAny { - return &Container_ListAny{ +// ListAny returns from ContainerPathAny the path struct for its child "list". +func (n *ContainerPathAny) ListAny() *Container_ListPathAny { + return &Container_ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key": "*"}, @@ -1846,9 +1908,9 @@ func (n *ContainerAny) ListAny() *Container_ListAny { } } -// List returns from Container the path struct for its child "list". -func (n *Container) List(Key string) *Container_List { - return &Container_List{ +// List returns from ContainerPath the path struct for its child "list". +func (n *ContainerPath) List(Key string) *Container_ListPath { + return &Container_ListPath{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key": Key}, @@ -1857,9 +1919,9 @@ func (n *Container) List(Key string) *Container_List { } } -// List returns from ContainerAny the path struct for its child "list". -func (n *ContainerAny) List(Key string) *Container_ListAny { - return &Container_ListAny{ +// List returns from ContainerPathAny the path struct for its child "list". +func (n *ContainerPathAny) List(Key string) *Container_ListPathAny { + return &Container_ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key": Key}, @@ -1875,10 +1937,11 @@ func (n *ContainerAny) List(Key string) *Container_ListAny { inFieldName: "list", inUniqueFieldName: "List", inListBuilderKeyThreshold: 1, + inPathStructSuffix: "Path", want: ` -// ListAny returns from Container the path struct for its child "list". -func (n *Container) ListAny() *Container_ListAny { - return &Container_ListAny{ +// ListAny returns from ContainerPath the path struct for its child "list". +func (n *ContainerPath) ListAny() *Container_ListPathAny { + return &Container_ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key": "*"}, @@ -1887,9 +1950,9 @@ func (n *Container) ListAny() *Container_ListAny { } } -// ListAny returns from ContainerAny the path struct for its child "list". -func (n *ContainerAny) ListAny() *Container_ListAny { - return &Container_ListAny{ +// ListAny returns from ContainerPathAny the path struct for its child "list". +func (n *ContainerPathAny) ListAny() *Container_ListPathAny { + return &Container_ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key": "*"}, @@ -1898,22 +1961,23 @@ func (n *ContainerAny) ListAny() *Container_ListAny { } } -// WithKey sets Container_ListAny's key "key" to the specified value. -func (n *Container_ListAny) WithKey(Key string) *Container_ListAny { +// WithKey sets Container_ListPathAny's key "key" to the specified value. +func (n *Container_ListPathAny) WithKey(Key string) *Container_ListPathAny { ygot.ModifyKey(n.NodePath, "key", Key) return n } `, }, { - name: "inner container", - inDirectory: deepSchemaDirectories["/root-module/container"], - inDirectories: deepSchemaDirectories, - inFieldName: "inner-container", - inUniqueFieldName: "InnerContainer", + name: "inner container", + inDirectory: deepSchemaDirectories["/root-module/container"], + inDirectories: deepSchemaDirectories, + inFieldName: "inner-container", + inUniqueFieldName: "InnerContainer", + inPathStructSuffix: "Path", want: ` -// InnerContainer returns from Container the path struct for its child "inner-container". -func (n *Container) InnerContainer() *Container_InnerContainer { - return &Container_InnerContainer{ +// InnerContainer returns from ContainerPath the path struct for its child "inner-container". +func (n *ContainerPath) InnerContainer() *Container_InnerContainerPath { + return &Container_InnerContainerPath{ NodePath: ygot.NewNodePath( []string{"inner-container"}, map[string]interface{}{}, @@ -1922,9 +1986,9 @@ func (n *Container) InnerContainer() *Container_InnerContainer { } } -// InnerContainer returns from ContainerAny the path struct for its child "inner-container". -func (n *ContainerAny) InnerContainer() *Container_InnerContainerAny { - return &Container_InnerContainerAny{ +// InnerContainer returns from ContainerPathAny the path struct for its child "inner-container". +func (n *ContainerPathAny) InnerContainer() *Container_InnerContainerPathAny { + return &Container_InnerContainerPathAny{ NodePath: ygot.NewNodePath( []string{"inner-container"}, map[string]interface{}{}, @@ -1934,15 +1998,16 @@ func (n *ContainerAny) InnerContainer() *Container_InnerContainerAny { } `, }, { - name: "list with state method", - inDirectory: directories["/root"], - inDirectories: directories, - inFieldName: "list-with-state", - inUniqueFieldName: "ListWithState", + name: "list with state method", + inDirectory: directories["/root"], + inDirectories: directories, + inFieldName: "list-with-state", + inUniqueFieldName: "ListWithState", + inPathStructSuffix: "Path", want: ` -// ListWithStateAny returns from Root the path struct for its child "list-with-state". -func (n *Root) ListWithStateAny() *ListWithStateAny { - return &ListWithStateAny{ +// ListWithStateAny returns from RootPath the path struct for its child "list-with-state". +func (n *RootPath) ListWithStateAny() *ListWithStatePathAny { + return &ListWithStatePathAny{ NodePath: ygot.NewNodePath( []string{"list-container-with-state", "list-with-state"}, map[string]interface{}{"key": "*"}, @@ -1951,9 +2016,9 @@ func (n *Root) ListWithStateAny() *ListWithStateAny { } } -// ListWithState returns from Root the path struct for its child "list-with-state". -func (n *Root) ListWithState(Key float64) *ListWithState { - return &ListWithState{ +// ListWithState returns from RootPath the path struct for its child "list-with-state". +func (n *RootPath) ListWithState(Key float64) *ListWithStatePath { + return &ListWithStatePath{ NodePath: ygot.NewNodePath( []string{"list-container-with-state", "list-with-state"}, map[string]interface{}{"key": Key}, @@ -1963,12 +2028,13 @@ func (n *Root) ListWithState(Key float64) *ListWithState { } `, }, { - name: "root-level list methods", - inDirectory: directories["/root"], - inDirectories: directories, - inFieldName: "list", - inUniqueFieldName: "List", - want: wantListMethods, + name: "root-level list methods", + inDirectory: directories["/root"], + inDirectories: directories, + inFieldName: "list", + inUniqueFieldName: "List", + inPathStructSuffix: "Path", + want: wantListMethods, }, { name: "root-level list methods with builder API threshold over the number of keys", inDirectory: directories["/root"], @@ -1976,6 +2042,7 @@ func (n *Root) ListWithState(Key float64) *ListWithState { inFieldName: "list", inUniqueFieldName: "List", inListBuilderKeyThreshold: 4, + inPathStructSuffix: "Path", want: wantListMethods, }, { name: "root-level list methods over key threshold -- should use builder API", @@ -1984,10 +2051,11 @@ func (n *Root) ListWithState(Key float64) *ListWithState { inFieldName: "list", inUniqueFieldName: "List", inListBuilderKeyThreshold: 3, + inPathStructSuffix: "Path", want: ` -// ListAny returns from Root the path struct for its child "list". -func (n *Root) ListAny() *ListAny { - return &ListAny{ +// ListAny returns from RootPath the path struct for its child "list". +func (n *RootPath) ListAny() *ListPathAny { + return &ListPathAny{ NodePath: ygot.NewNodePath( []string{"list-container", "list"}, map[string]interface{}{"key1": "*", "key2": "*", "union-key": "*"}, @@ -1996,20 +2064,20 @@ func (n *Root) ListAny() *ListAny { } } -// WithKey1 sets ListAny's key "key1" to the specified value. -func (n *ListAny) WithKey1(Key1 string) *ListAny { +// WithKey1 sets ListPathAny's key "key1" to the specified value. +func (n *ListPathAny) WithKey1(Key1 string) *ListPathAny { ygot.ModifyKey(n.NodePath, "key1", Key1) return n } -// WithKey2 sets ListAny's key "key2" to the specified value. -func (n *ListAny) WithKey2(Key2 oc.Binary) *ListAny { +// WithKey2 sets ListPathAny's key "key2" to the specified value. +func (n *ListPathAny) WithKey2(Key2 oc.Binary) *ListPathAny { ygot.ModifyKey(n.NodePath, "key2", Key2) return n } -// WithUnionKey sets ListAny's key "union-key" to the specified value. -func (n *ListAny) WithUnionKey(UnionKey oc.RootModule_List_UnionKey_Union) *ListAny { +// WithUnionKey sets ListPathAny's key "union-key" to the specified value. +func (n *ListPathAny) WithUnionKey(UnionKey oc.RootModule_List_UnionKey_Union) *ListPathAny { ygot.ModifyKey(n.NodePath, "union-key", UnionKey) return n } @@ -2019,7 +2087,7 @@ func (n *ListAny) WithUnionKey(UnionKey oc.RootModule_List_UnionKey_Union) *List for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var buf strings.Builder - if errs := generateChildConstructors(&buf, tt.inDirectory, tt.inFieldName, tt.inUniqueFieldName, tt.inDirectories, "oc", tt.inListBuilderKeyThreshold); errs != nil { + if errs := generateChildConstructors(&buf, tt.inDirectory, tt.inFieldName, tt.inUniqueFieldName, tt.inDirectories, "oc.", tt.inPathStructSuffix, tt.inListBuilderKeyThreshold); errs != nil { t.Fatal(errs) } @@ -2136,7 +2204,7 @@ func TestMakeKeyParams(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := makeKeyParams(tt.in, "oc") + got, err := makeKeyParams(tt.in, "oc.") if diff := cmp.Diff(tt.want, got, cmp.AllowUnexported(keyParam{})); diff != "" { t.Errorf("(-want, +got):\n%s", diff) } diff --git a/ypathgen/testdata/structs/choice-case-example.path-txt b/ypathgen/testdata/structs/choice-case-example.path-txt index b7850a936..eadb69b4e 100644 --- a/ypathgen/testdata/structs/choice-case-example.path-txt +++ b/ypathgen/testdata/structs/choice-case-example.path-txt @@ -11,43 +11,42 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// ChoiceCaseAnonymousCase represents the /choice-case-example/choice-case-anonymous-case YANG schema element. -type ChoiceCaseAnonymousCase struct { +// ChoiceCaseAnonymousCasePath represents the /choice-case-example/choice-case-anonymous-case YANG schema element. +type ChoiceCaseAnonymousCasePath struct { *ygot.NodePath } -// ChoiceCaseAnonymousCaseAny represents the wildcard version of the /choice-case-example/choice-case-anonymous-case YANG schema element. -type ChoiceCaseAnonymousCaseAny struct { +// ChoiceCaseAnonymousCasePathAny represents the wildcard version of the /choice-case-example/choice-case-anonymous-case YANG schema element. +type ChoiceCaseAnonymousCasePathAny struct { *ygot.NodePath } -// ChoiceCaseAnonymousCase_A represents the /choice-case-example/choice-case-anonymous-case/foo/a/a YANG schema element. -type ChoiceCaseAnonymousCase_A struct { +// ChoiceCaseAnonymousCase_APath represents the /choice-case-example/choice-case-anonymous-case/foo/a/a YANG schema element. +type ChoiceCaseAnonymousCase_APath struct { *ygot.NodePath } -// ChoiceCaseAnonymousCase_AAny represents the wildcard version of the /choice-case-example/choice-case-anonymous-case/foo/a/a YANG schema element. -type ChoiceCaseAnonymousCase_AAny struct { +// ChoiceCaseAnonymousCase_APathAny represents the wildcard version of the /choice-case-example/choice-case-anonymous-case/foo/a/a YANG schema element. +type ChoiceCaseAnonymousCase_APathAny struct { *ygot.NodePath } -// ChoiceCaseAnonymousCase_B represents the /choice-case-example/choice-case-anonymous-case/foo/b/b YANG schema element. -type ChoiceCaseAnonymousCase_B struct { +// ChoiceCaseAnonymousCase_BPath represents the /choice-case-example/choice-case-anonymous-case/foo/b/b YANG schema element. +type ChoiceCaseAnonymousCase_BPath struct { *ygot.NodePath } -// ChoiceCaseAnonymousCase_BAny represents the wildcard version of the /choice-case-example/choice-case-anonymous-case/foo/b/b YANG schema element. -type ChoiceCaseAnonymousCase_BAny struct { +// ChoiceCaseAnonymousCase_BPathAny represents the wildcard version of the /choice-case-example/choice-case-anonymous-case/foo/b/b YANG schema element. +type ChoiceCaseAnonymousCase_BPathAny struct { *ygot.NodePath } -// A returns from ChoiceCaseAnonymousCase the path struct for its child "a". -func (n *ChoiceCaseAnonymousCase) A() *ChoiceCaseAnonymousCase_A { - return &ChoiceCaseAnonymousCase_A{ +// A returns from ChoiceCaseAnonymousCasePath the path struct for its child "a". +func (n *ChoiceCaseAnonymousCasePath) A() *ChoiceCaseAnonymousCase_APath { + return &ChoiceCaseAnonymousCase_APath{ NodePath: ygot.NewNodePath( []string{"a"}, map[string]interface{}{}, @@ -56,9 +55,9 @@ func (n *ChoiceCaseAnonymousCase) A() *ChoiceCaseAnonymousCase_A { } } -// A returns from ChoiceCaseAnonymousCaseAny the path struct for its child "a". -func (n *ChoiceCaseAnonymousCaseAny) A() *ChoiceCaseAnonymousCase_AAny { - return &ChoiceCaseAnonymousCase_AAny{ +// A returns from ChoiceCaseAnonymousCasePathAny the path struct for its child "a". +func (n *ChoiceCaseAnonymousCasePathAny) A() *ChoiceCaseAnonymousCase_APathAny { + return &ChoiceCaseAnonymousCase_APathAny{ NodePath: ygot.NewNodePath( []string{"a"}, map[string]interface{}{}, @@ -67,9 +66,9 @@ func (n *ChoiceCaseAnonymousCaseAny) A() *ChoiceCaseAnonymousCase_AAny { } } -// B returns from ChoiceCaseAnonymousCase the path struct for its child "b". -func (n *ChoiceCaseAnonymousCase) B() *ChoiceCaseAnonymousCase_B { - return &ChoiceCaseAnonymousCase_B{ +// B returns from ChoiceCaseAnonymousCasePath the path struct for its child "b". +func (n *ChoiceCaseAnonymousCasePath) B() *ChoiceCaseAnonymousCase_BPath { + return &ChoiceCaseAnonymousCase_BPath{ NodePath: ygot.NewNodePath( []string{"b"}, map[string]interface{}{}, @@ -78,9 +77,9 @@ func (n *ChoiceCaseAnonymousCase) B() *ChoiceCaseAnonymousCase_B { } } -// B returns from ChoiceCaseAnonymousCaseAny the path struct for its child "b". -func (n *ChoiceCaseAnonymousCaseAny) B() *ChoiceCaseAnonymousCase_BAny { - return &ChoiceCaseAnonymousCase_BAny{ +// B returns from ChoiceCaseAnonymousCasePathAny the path struct for its child "b". +func (n *ChoiceCaseAnonymousCasePathAny) B() *ChoiceCaseAnonymousCase_BPathAny { + return &ChoiceCaseAnonymousCase_BPathAny{ NodePath: ygot.NewNodePath( []string{"b"}, map[string]interface{}{}, @@ -89,39 +88,39 @@ func (n *ChoiceCaseAnonymousCaseAny) B() *ChoiceCaseAnonymousCase_BAny { } } -// ChoiceCaseWithLeafref represents the /choice-case-example/choice-case-with-leafref YANG schema element. -type ChoiceCaseWithLeafref struct { +// ChoiceCaseWithLeafrefPath represents the /choice-case-example/choice-case-with-leafref YANG schema element. +type ChoiceCaseWithLeafrefPath struct { *ygot.NodePath } -// ChoiceCaseWithLeafrefAny represents the wildcard version of the /choice-case-example/choice-case-with-leafref YANG schema element. -type ChoiceCaseWithLeafrefAny struct { +// ChoiceCaseWithLeafrefPathAny represents the wildcard version of the /choice-case-example/choice-case-with-leafref YANG schema element. +type ChoiceCaseWithLeafrefPathAny struct { *ygot.NodePath } -// ChoiceCaseWithLeafref_Ptr represents the /choice-case-example/choice-case-with-leafref/foo/bar/ptr YANG schema element. -type ChoiceCaseWithLeafref_Ptr struct { +// ChoiceCaseWithLeafref_PtrPath represents the /choice-case-example/choice-case-with-leafref/foo/bar/ptr YANG schema element. +type ChoiceCaseWithLeafref_PtrPath struct { *ygot.NodePath } -// ChoiceCaseWithLeafref_PtrAny represents the wildcard version of the /choice-case-example/choice-case-with-leafref/foo/bar/ptr YANG schema element. -type ChoiceCaseWithLeafref_PtrAny struct { +// ChoiceCaseWithLeafref_PtrPathAny represents the wildcard version of the /choice-case-example/choice-case-with-leafref/foo/bar/ptr YANG schema element. +type ChoiceCaseWithLeafref_PtrPathAny struct { *ygot.NodePath } -// ChoiceCaseWithLeafref_Referenced represents the /choice-case-example/choice-case-with-leafref/referenced YANG schema element. -type ChoiceCaseWithLeafref_Referenced struct { +// ChoiceCaseWithLeafref_ReferencedPath represents the /choice-case-example/choice-case-with-leafref/referenced YANG schema element. +type ChoiceCaseWithLeafref_ReferencedPath struct { *ygot.NodePath } -// ChoiceCaseWithLeafref_ReferencedAny represents the wildcard version of the /choice-case-example/choice-case-with-leafref/referenced YANG schema element. -type ChoiceCaseWithLeafref_ReferencedAny struct { +// ChoiceCaseWithLeafref_ReferencedPathAny represents the wildcard version of the /choice-case-example/choice-case-with-leafref/referenced YANG schema element. +type ChoiceCaseWithLeafref_ReferencedPathAny struct { *ygot.NodePath } -// Ptr returns from ChoiceCaseWithLeafref the path struct for its child "ptr". -func (n *ChoiceCaseWithLeafref) Ptr() *ChoiceCaseWithLeafref_Ptr { - return &ChoiceCaseWithLeafref_Ptr{ +// Ptr returns from ChoiceCaseWithLeafrefPath the path struct for its child "ptr". +func (n *ChoiceCaseWithLeafrefPath) Ptr() *ChoiceCaseWithLeafref_PtrPath { + return &ChoiceCaseWithLeafref_PtrPath{ NodePath: ygot.NewNodePath( []string{"ptr"}, map[string]interface{}{}, @@ -130,9 +129,9 @@ func (n *ChoiceCaseWithLeafref) Ptr() *ChoiceCaseWithLeafref_Ptr { } } -// Ptr returns from ChoiceCaseWithLeafrefAny the path struct for its child "ptr". -func (n *ChoiceCaseWithLeafrefAny) Ptr() *ChoiceCaseWithLeafref_PtrAny { - return &ChoiceCaseWithLeafref_PtrAny{ +// Ptr returns from ChoiceCaseWithLeafrefPathAny the path struct for its child "ptr". +func (n *ChoiceCaseWithLeafrefPathAny) Ptr() *ChoiceCaseWithLeafref_PtrPathAny { + return &ChoiceCaseWithLeafref_PtrPathAny{ NodePath: ygot.NewNodePath( []string{"ptr"}, map[string]interface{}{}, @@ -141,9 +140,9 @@ func (n *ChoiceCaseWithLeafrefAny) Ptr() *ChoiceCaseWithLeafref_PtrAny { } } -// Referenced returns from ChoiceCaseWithLeafref the path struct for its child "referenced". -func (n *ChoiceCaseWithLeafref) Referenced() *ChoiceCaseWithLeafref_Referenced { - return &ChoiceCaseWithLeafref_Referenced{ +// Referenced returns from ChoiceCaseWithLeafrefPath the path struct for its child "referenced". +func (n *ChoiceCaseWithLeafrefPath) Referenced() *ChoiceCaseWithLeafref_ReferencedPath { + return &ChoiceCaseWithLeafref_ReferencedPath{ NodePath: ygot.NewNodePath( []string{"referenced"}, map[string]interface{}{}, @@ -152,9 +151,9 @@ func (n *ChoiceCaseWithLeafref) Referenced() *ChoiceCaseWithLeafref_Referenced { } } -// Referenced returns from ChoiceCaseWithLeafrefAny the path struct for its child "referenced". -func (n *ChoiceCaseWithLeafrefAny) Referenced() *ChoiceCaseWithLeafref_ReferencedAny { - return &ChoiceCaseWithLeafref_ReferencedAny{ +// Referenced returns from ChoiceCaseWithLeafrefPathAny the path struct for its child "referenced". +func (n *ChoiceCaseWithLeafrefPathAny) Referenced() *ChoiceCaseWithLeafref_ReferencedPathAny { + return &ChoiceCaseWithLeafref_ReferencedPathAny{ NodePath: ygot.NewNodePath( []string{"referenced"}, map[string]interface{}{}, @@ -163,19 +162,19 @@ func (n *ChoiceCaseWithLeafrefAny) Referenced() *ChoiceCaseWithLeafref_Reference } } -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// ChoiceCaseAnonymousCase returns from Device the path struct for its child "choice-case-anonymous-case". -func (n *Device) ChoiceCaseAnonymousCase() *ChoiceCaseAnonymousCase { - return &ChoiceCaseAnonymousCase{ +// ChoiceCaseAnonymousCase returns from DevicePath the path struct for its child "choice-case-anonymous-case". +func (n *DevicePath) ChoiceCaseAnonymousCase() *ChoiceCaseAnonymousCasePath { + return &ChoiceCaseAnonymousCasePath{ NodePath: ygot.NewNodePath( []string{"choice-case-anonymous-case"}, map[string]interface{}{}, @@ -184,9 +183,9 @@ func (n *Device) ChoiceCaseAnonymousCase() *ChoiceCaseAnonymousCase { } } -// ChoiceCaseWithLeafref returns from Device the path struct for its child "choice-case-with-leafref". -func (n *Device) ChoiceCaseWithLeafref() *ChoiceCaseWithLeafref { - return &ChoiceCaseWithLeafref{ +// ChoiceCaseWithLeafref returns from DevicePath the path struct for its child "choice-case-with-leafref". +func (n *DevicePath) ChoiceCaseWithLeafref() *ChoiceCaseWithLeafrefPath { + return &ChoiceCaseWithLeafrefPath{ NodePath: ygot.NewNodePath( []string{"choice-case-with-leafref"}, map[string]interface{}{}, @@ -195,9 +194,9 @@ func (n *Device) ChoiceCaseWithLeafref() *ChoiceCaseWithLeafref { } } -// SimpleChoiceCase returns from Device the path struct for its child "simple-choice-case". -func (n *Device) SimpleChoiceCase() *SimpleChoiceCase { - return &SimpleChoiceCase{ +// SimpleChoiceCase returns from DevicePath the path struct for its child "simple-choice-case". +func (n *DevicePath) SimpleChoiceCase() *SimpleChoiceCasePath { + return &SimpleChoiceCasePath{ NodePath: ygot.NewNodePath( []string{"simple-choice-case"}, map[string]interface{}{}, @@ -206,39 +205,39 @@ func (n *Device) SimpleChoiceCase() *SimpleChoiceCase { } } -// SimpleChoiceCase represents the /choice-case-example/simple-choice-case YANG schema element. -type SimpleChoiceCase struct { +// SimpleChoiceCasePath represents the /choice-case-example/simple-choice-case YANG schema element. +type SimpleChoiceCasePath struct { *ygot.NodePath } -// SimpleChoiceCaseAny represents the wildcard version of the /choice-case-example/simple-choice-case YANG schema element. -type SimpleChoiceCaseAny struct { +// SimpleChoiceCasePathAny represents the wildcard version of the /choice-case-example/simple-choice-case YANG schema element. +type SimpleChoiceCasePathAny struct { *ygot.NodePath } -// SimpleChoiceCase_A represents the /choice-case-example/simple-choice-case/foo/bar/a YANG schema element. -type SimpleChoiceCase_A struct { +// SimpleChoiceCase_APath represents the /choice-case-example/simple-choice-case/foo/bar/a YANG schema element. +type SimpleChoiceCase_APath struct { *ygot.NodePath } -// SimpleChoiceCase_AAny represents the wildcard version of the /choice-case-example/simple-choice-case/foo/bar/a YANG schema element. -type SimpleChoiceCase_AAny struct { +// SimpleChoiceCase_APathAny represents the wildcard version of the /choice-case-example/simple-choice-case/foo/bar/a YANG schema element. +type SimpleChoiceCase_APathAny struct { *ygot.NodePath } -// SimpleChoiceCase_B represents the /choice-case-example/simple-choice-case/foo/baz/b YANG schema element. -type SimpleChoiceCase_B struct { +// SimpleChoiceCase_BPath represents the /choice-case-example/simple-choice-case/foo/baz/b YANG schema element. +type SimpleChoiceCase_BPath struct { *ygot.NodePath } -// SimpleChoiceCase_BAny represents the wildcard version of the /choice-case-example/simple-choice-case/foo/baz/b YANG schema element. -type SimpleChoiceCase_BAny struct { +// SimpleChoiceCase_BPathAny represents the wildcard version of the /choice-case-example/simple-choice-case/foo/baz/b YANG schema element. +type SimpleChoiceCase_BPathAny struct { *ygot.NodePath } -// A returns from SimpleChoiceCase the path struct for its child "a". -func (n *SimpleChoiceCase) A() *SimpleChoiceCase_A { - return &SimpleChoiceCase_A{ +// A returns from SimpleChoiceCasePath the path struct for its child "a". +func (n *SimpleChoiceCasePath) A() *SimpleChoiceCase_APath { + return &SimpleChoiceCase_APath{ NodePath: ygot.NewNodePath( []string{"a"}, map[string]interface{}{}, @@ -247,9 +246,9 @@ func (n *SimpleChoiceCase) A() *SimpleChoiceCase_A { } } -// A returns from SimpleChoiceCaseAny the path struct for its child "a". -func (n *SimpleChoiceCaseAny) A() *SimpleChoiceCase_AAny { - return &SimpleChoiceCase_AAny{ +// A returns from SimpleChoiceCasePathAny the path struct for its child "a". +func (n *SimpleChoiceCasePathAny) A() *SimpleChoiceCase_APathAny { + return &SimpleChoiceCase_APathAny{ NodePath: ygot.NewNodePath( []string{"a"}, map[string]interface{}{}, @@ -258,9 +257,9 @@ func (n *SimpleChoiceCaseAny) A() *SimpleChoiceCase_AAny { } } -// B returns from SimpleChoiceCase the path struct for its child "b". -func (n *SimpleChoiceCase) B() *SimpleChoiceCase_B { - return &SimpleChoiceCase_B{ +// B returns from SimpleChoiceCasePath the path struct for its child "b". +func (n *SimpleChoiceCasePath) B() *SimpleChoiceCase_BPath { + return &SimpleChoiceCase_BPath{ NodePath: ygot.NewNodePath( []string{"b"}, map[string]interface{}{}, @@ -269,9 +268,9 @@ func (n *SimpleChoiceCase) B() *SimpleChoiceCase_B { } } -// B returns from SimpleChoiceCaseAny the path struct for its child "b". -func (n *SimpleChoiceCaseAny) B() *SimpleChoiceCase_BAny { - return &SimpleChoiceCase_BAny{ +// B returns from SimpleChoiceCasePathAny the path struct for its child "b". +func (n *SimpleChoiceCasePathAny) B() *SimpleChoiceCase_BPathAny { + return &SimpleChoiceCase_BPathAny{ NodePath: ygot.NewNodePath( []string{"b"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/enum-module.path-txt b/ypathgen/testdata/structs/enum-module.path-txt index 7d3135643..ab4b5e279 100644 --- a/ypathgen/testdata/structs/enum-module.path-txt +++ b/ypathgen/testdata/structs/enum-module.path-txt @@ -11,33 +11,32 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// AList represents the /enum-module/a-lists/a-list YANG schema element. -type AList struct { +// AListPath represents the /enum-module/a-lists/a-list YANG schema element. +type AListPath struct { *ygot.NodePath } -// AListAny represents the wildcard version of the /enum-module/a-lists/a-list YANG schema element. -type AListAny struct { +// AListPathAny represents the wildcard version of the /enum-module/a-lists/a-list YANG schema element. +type AListPathAny struct { *ygot.NodePath } -// AList_Value represents the /enum-module/a-lists/a-list/state/value YANG schema element. -type AList_Value struct { +// AList_ValuePath represents the /enum-module/a-lists/a-list/state/value YANG schema element. +type AList_ValuePath struct { *ygot.NodePath } -// AList_ValueAny represents the wildcard version of the /enum-module/a-lists/a-list/state/value YANG schema element. -type AList_ValueAny struct { +// AList_ValuePathAny represents the wildcard version of the /enum-module/a-lists/a-list/state/value YANG schema element. +type AList_ValuePathAny struct { *ygot.NodePath } -// Value returns from AList the path struct for its child "value". -func (n *AList) Value() *AList_Value { - return &AList_Value{ +// Value returns from AListPath the path struct for its child "value". +func (n *AListPath) Value() *AList_ValuePath { + return &AList_ValuePath{ NodePath: ygot.NewNodePath( []string{"state", "value"}, map[string]interface{}{}, @@ -46,9 +45,9 @@ func (n *AList) Value() *AList_Value { } } -// Value returns from AListAny the path struct for its child "value". -func (n *AListAny) Value() *AList_ValueAny { - return &AList_ValueAny{ +// Value returns from AListPathAny the path struct for its child "value". +func (n *AListPathAny) Value() *AList_ValuePathAny { + return &AList_ValuePathAny{ NodePath: ygot.NewNodePath( []string{"state", "value"}, map[string]interface{}{}, @@ -57,29 +56,29 @@ func (n *AListAny) Value() *AList_ValueAny { } } -// BList represents the /enum-module/b-lists/b-list YANG schema element. -type BList struct { +// BListPath represents the /enum-module/b-lists/b-list YANG schema element. +type BListPath struct { *ygot.NodePath } -// BListAny represents the wildcard version of the /enum-module/b-lists/b-list YANG schema element. -type BListAny struct { +// BListPathAny represents the wildcard version of the /enum-module/b-lists/b-list YANG schema element. +type BListPathAny struct { *ygot.NodePath } -// BList_Value represents the /enum-module/b-lists/b-list/state/value YANG schema element. -type BList_Value struct { +// BList_ValuePath represents the /enum-module/b-lists/b-list/state/value YANG schema element. +type BList_ValuePath struct { *ygot.NodePath } -// BList_ValueAny represents the wildcard version of the /enum-module/b-lists/b-list/state/value YANG schema element. -type BList_ValueAny struct { +// BList_ValuePathAny represents the wildcard version of the /enum-module/b-lists/b-list/state/value YANG schema element. +type BList_ValuePathAny struct { *ygot.NodePath } -// Value returns from BList the path struct for its child "value". -func (n *BList) Value() *BList_Value { - return &BList_Value{ +// Value returns from BListPath the path struct for its child "value". +func (n *BListPath) Value() *BList_ValuePath { + return &BList_ValuePath{ NodePath: ygot.NewNodePath( []string{"state", "value"}, map[string]interface{}{}, @@ -88,9 +87,9 @@ func (n *BList) Value() *BList_Value { } } -// Value returns from BListAny the path struct for its child "value". -func (n *BListAny) Value() *BList_ValueAny { - return &BList_ValueAny{ +// Value returns from BListPathAny the path struct for its child "value". +func (n *BListPathAny) Value() *BList_ValuePathAny { + return &BList_ValuePathAny{ NodePath: ygot.NewNodePath( []string{"state", "value"}, map[string]interface{}{}, @@ -99,29 +98,29 @@ func (n *BListAny) Value() *BList_ValueAny { } } -// C represents the /enum-module/c YANG schema element. -type C struct { +// CPath represents the /enum-module/c YANG schema element. +type CPath struct { *ygot.NodePath } -// CAny represents the wildcard version of the /enum-module/c YANG schema element. -type CAny struct { +// CPathAny represents the wildcard version of the /enum-module/c YANG schema element. +type CPathAny struct { *ygot.NodePath } -// C_Cl represents the /enum-module/c/cl YANG schema element. -type C_Cl struct { +// C_ClPath represents the /enum-module/c/cl YANG schema element. +type C_ClPath struct { *ygot.NodePath } -// C_ClAny represents the wildcard version of the /enum-module/c/cl YANG schema element. -type C_ClAny struct { +// C_ClPathAny represents the wildcard version of the /enum-module/c/cl YANG schema element. +type C_ClPathAny struct { *ygot.NodePath } -// Cl returns from C the path struct for its child "cl". -func (n *C) Cl() *C_Cl { - return &C_Cl{ +// Cl returns from CPath the path struct for its child "cl". +func (n *CPath) Cl() *C_ClPath { + return &C_ClPath{ NodePath: ygot.NewNodePath( []string{"cl"}, map[string]interface{}{}, @@ -130,9 +129,9 @@ func (n *C) Cl() *C_Cl { } } -// Cl returns from CAny the path struct for its child "cl". -func (n *CAny) Cl() *C_ClAny { - return &C_ClAny{ +// Cl returns from CPathAny the path struct for its child "cl". +func (n *CPathAny) Cl() *C_ClPathAny { + return &C_ClPathAny{ NodePath: ygot.NewNodePath( []string{"cl"}, map[string]interface{}{}, @@ -141,19 +140,19 @@ func (n *CAny) Cl() *C_ClAny { } } -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// AListAny returns from Device the path struct for its child "a-list". -func (n *Device) AListAny() *AListAny { - return &AListAny{ +// AListAny returns from DevicePath the path struct for its child "a-list". +func (n *DevicePath) AListAny() *AListPathAny { + return &AListPathAny{ NodePath: ygot.NewNodePath( []string{"a-lists", "a-list"}, map[string]interface{}{"value": "*"}, @@ -162,9 +161,9 @@ func (n *Device) AListAny() *AListAny { } } -// AList returns from Device the path struct for its child "a-list". -func (n *Device) AList(Value oc.AList_Value_Union) *AList { - return &AList{ +// AList returns from DevicePath the path struct for its child "a-list". +func (n *DevicePath) AList(Value AList_Value_Union) *AListPath { + return &AListPath{ NodePath: ygot.NewNodePath( []string{"a-lists", "a-list"}, map[string]interface{}{"value": Value}, @@ -173,9 +172,9 @@ func (n *Device) AList(Value oc.AList_Value_Union) *AList { } } -// BListAny returns from Device the path struct for its child "b-list". -func (n *Device) BListAny() *BListAny { - return &BListAny{ +// BListAny returns from DevicePath the path struct for its child "b-list". +func (n *DevicePath) BListAny() *BListPathAny { + return &BListPathAny{ NodePath: ygot.NewNodePath( []string{"b-lists", "b-list"}, map[string]interface{}{"value": "*"}, @@ -184,9 +183,9 @@ func (n *Device) BListAny() *BListAny { } } -// BList returns from Device the path struct for its child "b-list". -func (n *Device) BList(Value oc.BList_Value_Union) *BList { - return &BList{ +// BList returns from DevicePath the path struct for its child "b-list". +func (n *DevicePath) BList(Value BList_Value_Union) *BListPath { + return &BListPath{ NodePath: ygot.NewNodePath( []string{"b-lists", "b-list"}, map[string]interface{}{"value": Value}, @@ -195,9 +194,9 @@ func (n *Device) BList(Value oc.BList_Value_Union) *BList { } } -// C returns from Device the path struct for its child "c". -func (n *Device) C() *C { - return &C{ +// C returns from DevicePath the path struct for its child "c". +func (n *DevicePath) C() *CPath { + return &CPath{ NodePath: ygot.NewNodePath( []string{"c"}, map[string]interface{}{}, @@ -206,9 +205,9 @@ func (n *Device) C() *C { } } -// Parent returns from Device the path struct for its child "parent". -func (n *Device) Parent() *Parent { - return &Parent{ +// Parent returns from DevicePath the path struct for its child "parent". +func (n *DevicePath) Parent() *ParentPath { + return &ParentPath{ NodePath: ygot.NewNodePath( []string{"parent"}, map[string]interface{}{}, @@ -217,19 +216,19 @@ func (n *Device) Parent() *Parent { } } -// Parent represents the /enum-module/parent YANG schema element. -type Parent struct { +// ParentPath represents the /enum-module/parent YANG schema element. +type ParentPath struct { *ygot.NodePath } -// ParentAny represents the wildcard version of the /enum-module/parent YANG schema element. -type ParentAny struct { +// ParentPathAny represents the wildcard version of the /enum-module/parent YANG schema element. +type ParentPathAny struct { *ygot.NodePath } -// Child returns from Parent the path struct for its child "child". -func (n *Parent) Child() *Parent_Child { - return &Parent_Child{ +// Child returns from ParentPath the path struct for its child "child". +func (n *ParentPath) Child() *Parent_ChildPath { + return &Parent_ChildPath{ NodePath: ygot.NewNodePath( []string{"child"}, map[string]interface{}{}, @@ -238,9 +237,9 @@ func (n *Parent) Child() *Parent_Child { } } -// Child returns from ParentAny the path struct for its child "child". -func (n *ParentAny) Child() *Parent_ChildAny { - return &Parent_ChildAny{ +// Child returns from ParentPathAny the path struct for its child "child". +func (n *ParentPathAny) Child() *Parent_ChildPathAny { + return &Parent_ChildPathAny{ NodePath: ygot.NewNodePath( []string{"child"}, map[string]interface{}{}, @@ -249,29 +248,29 @@ func (n *ParentAny) Child() *Parent_ChildAny { } } -// Parent_Child represents the /enum-module/parent/child YANG schema element. -type Parent_Child struct { +// Parent_ChildPath represents the /enum-module/parent/child YANG schema element. +type Parent_ChildPath struct { *ygot.NodePath } -// Parent_ChildAny represents the wildcard version of the /enum-module/parent/child YANG schema element. -type Parent_ChildAny struct { +// Parent_ChildPathAny represents the wildcard version of the /enum-module/parent/child YANG schema element. +type Parent_ChildPathAny struct { *ygot.NodePath } -// Parent_Child_Id represents the /enum-module/parent/child/state/id YANG schema element. -type Parent_Child_Id struct { +// Parent_Child_IdPath represents the /enum-module/parent/child/state/id YANG schema element. +type Parent_Child_IdPath struct { *ygot.NodePath } -// Parent_Child_IdAny represents the wildcard version of the /enum-module/parent/child/state/id YANG schema element. -type Parent_Child_IdAny struct { +// Parent_Child_IdPathAny represents the wildcard version of the /enum-module/parent/child/state/id YANG schema element. +type Parent_Child_IdPathAny struct { *ygot.NodePath } -// Id returns from Parent_Child the path struct for its child "id". -func (n *Parent_Child) Id() *Parent_Child_Id { - return &Parent_Child_Id{ +// Id returns from Parent_ChildPath the path struct for its child "id". +func (n *Parent_ChildPath) Id() *Parent_Child_IdPath { + return &Parent_Child_IdPath{ NodePath: ygot.NewNodePath( []string{"state", "id"}, map[string]interface{}{}, @@ -280,9 +279,9 @@ func (n *Parent_Child) Id() *Parent_Child_Id { } } -// Id returns from Parent_ChildAny the path struct for its child "id". -func (n *Parent_ChildAny) Id() *Parent_Child_IdAny { - return &Parent_Child_IdAny{ +// Id returns from Parent_ChildPathAny the path struct for its child "id". +func (n *Parent_ChildPathAny) Id() *Parent_Child_IdPathAny { + return &Parent_Child_IdPathAny{ NodePath: ygot.NewNodePath( []string{"state", "id"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-camelcase.path-txt b/ypathgen/testdata/structs/openconfig-camelcase.path-txt index 461e0cfcd..d5a69e6cd 100644 --- a/ypathgen/testdata/structs/openconfig-camelcase.path-txt +++ b/ypathgen/testdata/structs/openconfig-camelcase.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// BGP represents the /openconfig-camelcase/bgp YANG schema element. -type BGP struct { +// BGPPath represents the /openconfig-camelcase/bgp YANG schema element. +type BGPPath struct { *ygot.NodePath } -// BGPAny represents the wildcard version of the /openconfig-camelcase/bgp YANG schema element. -type BGPAny struct { +// BGPPathAny represents the wildcard version of the /openconfig-camelcase/bgp YANG schema element. +type BGPPathAny struct { *ygot.NodePath } -// NeighborAny returns from BGP the path struct for its child "neighbor". -func (n *BGP) NeighborAny() *BGP_NeighborAny { - return &BGP_NeighborAny{ +// NeighborAny returns from BGPPath the path struct for its child "neighbor". +func (n *BGPPath) NeighborAny() *BGP_NeighborPathAny { + return &BGP_NeighborPathAny{ NodePath: ygot.NewNodePath( []string{"neighbors", "neighbor"}, map[string]interface{}{"peer-ip": "*"}, @@ -36,9 +35,9 @@ func (n *BGP) NeighborAny() *BGP_NeighborAny { } } -// NeighborAny returns from BGPAny the path struct for its child "neighbor". -func (n *BGPAny) NeighborAny() *BGP_NeighborAny { - return &BGP_NeighborAny{ +// NeighborAny returns from BGPPathAny the path struct for its child "neighbor". +func (n *BGPPathAny) NeighborAny() *BGP_NeighborPathAny { + return &BGP_NeighborPathAny{ NodePath: ygot.NewNodePath( []string{"neighbors", "neighbor"}, map[string]interface{}{"peer-ip": "*"}, @@ -47,9 +46,9 @@ func (n *BGPAny) NeighborAny() *BGP_NeighborAny { } } -// Neighbor returns from BGP the path struct for its child "neighbor". -func (n *BGP) Neighbor(PeerIP string) *BGP_Neighbor { - return &BGP_Neighbor{ +// Neighbor returns from BGPPath the path struct for its child "neighbor". +func (n *BGPPath) Neighbor(PeerIP string) *BGP_NeighborPath { + return &BGP_NeighborPath{ NodePath: ygot.NewNodePath( []string{"neighbors", "neighbor"}, map[string]interface{}{"peer-ip": PeerIP}, @@ -58,9 +57,9 @@ func (n *BGP) Neighbor(PeerIP string) *BGP_Neighbor { } } -// Neighbor returns from BGPAny the path struct for its child "neighbor". -func (n *BGPAny) Neighbor(PeerIP string) *BGP_NeighborAny { - return &BGP_NeighborAny{ +// Neighbor returns from BGPPathAny the path struct for its child "neighbor". +func (n *BGPPathAny) Neighbor(PeerIP string) *BGP_NeighborPathAny { + return &BGP_NeighborPathAny{ NodePath: ygot.NewNodePath( []string{"neighbors", "neighbor"}, map[string]interface{}{"peer-ip": PeerIP}, @@ -69,29 +68,29 @@ func (n *BGPAny) Neighbor(PeerIP string) *BGP_NeighborAny { } } -// BGP_Neighbor represents the /openconfig-camelcase/bgp/neighbors/neighbor YANG schema element. -type BGP_Neighbor struct { +// BGP_NeighborPath represents the /openconfig-camelcase/bgp/neighbors/neighbor YANG schema element. +type BGP_NeighborPath struct { *ygot.NodePath } -// BGP_NeighborAny represents the wildcard version of the /openconfig-camelcase/bgp/neighbors/neighbor YANG schema element. -type BGP_NeighborAny struct { +// BGP_NeighborPathAny represents the wildcard version of the /openconfig-camelcase/bgp/neighbors/neighbor YANG schema element. +type BGP_NeighborPathAny struct { *ygot.NodePath } -// BGP_Neighbor_PeerIP represents the /openconfig-camelcase/bgp/neighbors/neighbor/state/peer-ip YANG schema element. -type BGP_Neighbor_PeerIP struct { +// BGP_Neighbor_PeerIPPath represents the /openconfig-camelcase/bgp/neighbors/neighbor/state/peer-ip YANG schema element. +type BGP_Neighbor_PeerIPPath struct { *ygot.NodePath } -// BGP_Neighbor_PeerIPAny represents the wildcard version of the /openconfig-camelcase/bgp/neighbors/neighbor/state/peer-ip YANG schema element. -type BGP_Neighbor_PeerIPAny struct { +// BGP_Neighbor_PeerIPPathAny represents the wildcard version of the /openconfig-camelcase/bgp/neighbors/neighbor/state/peer-ip YANG schema element. +type BGP_Neighbor_PeerIPPathAny struct { *ygot.NodePath } -// PeerIP returns from BGP_Neighbor the path struct for its child "peer-ip". -func (n *BGP_Neighbor) PeerIP() *BGP_Neighbor_PeerIP { - return &BGP_Neighbor_PeerIP{ +// PeerIP returns from BGP_NeighborPath the path struct for its child "peer-ip". +func (n *BGP_NeighborPath) PeerIP() *BGP_Neighbor_PeerIPPath { + return &BGP_Neighbor_PeerIPPath{ NodePath: ygot.NewNodePath( []string{"state", "peer-ip"}, map[string]interface{}{}, @@ -100,9 +99,9 @@ func (n *BGP_Neighbor) PeerIP() *BGP_Neighbor_PeerIP { } } -// PeerIP returns from BGP_NeighborAny the path struct for its child "peer-ip". -func (n *BGP_NeighborAny) PeerIP() *BGP_Neighbor_PeerIPAny { - return &BGP_Neighbor_PeerIPAny{ +// PeerIP returns from BGP_NeighborPathAny the path struct for its child "peer-ip". +func (n *BGP_NeighborPathAny) PeerIP() *BGP_Neighbor_PeerIPPathAny { + return &BGP_Neighbor_PeerIPPathAny{ NodePath: ygot.NewNodePath( []string{"state", "peer-ip"}, map[string]interface{}{}, @@ -111,19 +110,19 @@ func (n *BGP_NeighborAny) PeerIP() *BGP_Neighbor_PeerIPAny { } } -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// BGP returns from Device the path struct for its child "bgp". -func (n *Device) BGP() *BGP { - return &BGP{ +// BGP returns from DevicePath the path struct for its child "bgp". +func (n *DevicePath) BGP() *BGPPath { + return &BGPPath{ NodePath: ygot.NewNodePath( []string{"bgp"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-enumcamelcase.path-txt b/ypathgen/testdata/structs/openconfig-enumcamelcase.path-txt index e81edbddf..51025e6f3 100644 --- a/ypathgen/testdata/structs/openconfig-enumcamelcase.path-txt +++ b/ypathgen/testdata/structs/openconfig-enumcamelcase.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// Foo returns from Device the path struct for its child "foo". -func (n *Device) Foo() *Foo { - return &Foo{ +// Foo returns from DevicePath the path struct for its child "foo". +func (n *DevicePath) Foo() *FooPath { + return &FooPath{ NodePath: ygot.NewNodePath( []string{"foo"}, map[string]interface{}{}, @@ -36,39 +35,39 @@ func (n *Device) Foo() *Foo { } } -// Foo represents the /openconfig-enumcamelcase/foo YANG schema element. -type Foo struct { +// FooPath represents the /openconfig-enumcamelcase/foo YANG schema element. +type FooPath struct { *ygot.NodePath } -// FooAny represents the wildcard version of the /openconfig-enumcamelcase/foo YANG schema element. -type FooAny struct { +// FooPathAny represents the wildcard version of the /openconfig-enumcamelcase/foo YANG schema element. +type FooPathAny struct { *ygot.NodePath } -// Foo_Bar represents the /openconfig-enumcamelcase/foo/bar YANG schema element. -type Foo_Bar struct { +// Foo_BarPath represents the /openconfig-enumcamelcase/foo/bar YANG schema element. +type Foo_BarPath struct { *ygot.NodePath } -// Foo_BarAny represents the wildcard version of the /openconfig-enumcamelcase/foo/bar YANG schema element. -type Foo_BarAny struct { +// Foo_BarPathAny represents the wildcard version of the /openconfig-enumcamelcase/foo/bar YANG schema element. +type Foo_BarPathAny struct { *ygot.NodePath } -// Foo_Baz represents the /openconfig-enumcamelcase/foo/baz YANG schema element. -type Foo_Baz struct { +// Foo_BazPath represents the /openconfig-enumcamelcase/foo/baz YANG schema element. +type Foo_BazPath struct { *ygot.NodePath } -// Foo_BazAny represents the wildcard version of the /openconfig-enumcamelcase/foo/baz YANG schema element. -type Foo_BazAny struct { +// Foo_BazPathAny represents the wildcard version of the /openconfig-enumcamelcase/foo/baz YANG schema element. +type Foo_BazPathAny struct { *ygot.NodePath } -// Bar returns from Foo the path struct for its child "bar". -func (n *Foo) Bar() *Foo_Bar { - return &Foo_Bar{ +// Bar returns from FooPath the path struct for its child "bar". +func (n *FooPath) Bar() *Foo_BarPath { + return &Foo_BarPath{ NodePath: ygot.NewNodePath( []string{"bar"}, map[string]interface{}{}, @@ -77,9 +76,9 @@ func (n *Foo) Bar() *Foo_Bar { } } -// Bar returns from FooAny the path struct for its child "bar". -func (n *FooAny) Bar() *Foo_BarAny { - return &Foo_BarAny{ +// Bar returns from FooPathAny the path struct for its child "bar". +func (n *FooPathAny) Bar() *Foo_BarPathAny { + return &Foo_BarPathAny{ NodePath: ygot.NewNodePath( []string{"bar"}, map[string]interface{}{}, @@ -88,9 +87,9 @@ func (n *FooAny) Bar() *Foo_BarAny { } } -// Baz returns from Foo the path struct for its child "baz". -func (n *Foo) Baz() *Foo_Baz { - return &Foo_Baz{ +// Baz returns from FooPath the path struct for its child "baz". +func (n *FooPath) Baz() *Foo_BazPath { + return &Foo_BazPath{ NodePath: ygot.NewNodePath( []string{"baz"}, map[string]interface{}{}, @@ -99,9 +98,9 @@ func (n *Foo) Baz() *Foo_Baz { } } -// Baz returns from FooAny the path struct for its child "baz". -func (n *FooAny) Baz() *Foo_BazAny { - return &Foo_BazAny{ +// Baz returns from FooPathAny the path struct for its child "baz". +func (n *FooPathAny) Baz() *Foo_BazPathAny { + return &Foo_BazPathAny{ NodePath: ygot.NewNodePath( []string{"baz"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-simple-30.path-txt b/ypathgen/testdata/structs/openconfig-simple-30.path-txt index 41ec96f21..8286770f1 100644 --- a/ypathgen/testdata/structs/openconfig-simple-30.path-txt +++ b/ypathgen/testdata/structs/openconfig-simple-30.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// Parent returns from Device the path struct for its child "parent". -func (n *Device) Parent() *Parent { - return &Parent{ +// Parent returns from DevicePath the path struct for its child "parent". +func (n *DevicePath) Parent() *ParentPath { + return &ParentPath{ NodePath: ygot.NewNodePath( []string{"parent"}, map[string]interface{}{}, @@ -36,9 +35,9 @@ func (n *Device) Parent() *Parent { } } -// RemoteContainer returns from Device the path struct for its child "remote-container". -func (n *Device) RemoteContainer() *RemoteContainer { - return &RemoteContainer{ +// RemoteContainer returns from DevicePath the path struct for its child "remote-container". +func (n *DevicePath) RemoteContainer() *RemoteContainerPath { + return &RemoteContainerPath{ NodePath: ygot.NewNodePath( []string{"remote-container"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-simple-31.path-txt b/ypathgen/testdata/structs/openconfig-simple-31.path-txt index b4c572d5b..945f05233 100644 --- a/ypathgen/testdata/structs/openconfig-simple-31.path-txt +++ b/ypathgen/testdata/structs/openconfig-simple-31.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Parent represents the /openconfig-simple/parent YANG schema element. -type Parent struct { +// ParentPath represents the /openconfig-simple/parent YANG schema element. +type ParentPath struct { *ygot.NodePath } -// ParentAny represents the wildcard version of the /openconfig-simple/parent YANG schema element. -type ParentAny struct { +// ParentPathAny represents the wildcard version of the /openconfig-simple/parent YANG schema element. +type ParentPathAny struct { *ygot.NodePath } -// Child returns from Parent the path struct for its child "child". -func (n *Parent) Child() *Parent_Child { - return &Parent_Child{ +// Child returns from ParentPath the path struct for its child "child". +func (n *ParentPath) Child() *Parent_ChildPath { + return &Parent_ChildPath{ NodePath: ygot.NewNodePath( []string{"child"}, map[string]interface{}{}, @@ -36,9 +35,9 @@ func (n *Parent) Child() *Parent_Child { } } -// Child returns from ParentAny the path struct for its child "child". -func (n *ParentAny) Child() *Parent_ChildAny { - return &Parent_ChildAny{ +// Child returns from ParentPathAny the path struct for its child "child". +func (n *ParentPathAny) Child() *Parent_ChildPathAny { + return &Parent_ChildPathAny{ NodePath: ygot.NewNodePath( []string{"child"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-simple-32.path-txt b/ypathgen/testdata/structs/openconfig-simple-32.path-txt index bf326ecf1..7ec3f3dab 100644 --- a/ypathgen/testdata/structs/openconfig-simple-32.path-txt +++ b/ypathgen/testdata/structs/openconfig-simple-32.path-txt @@ -11,63 +11,62 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Parent_Child represents the /openconfig-simple/parent/child YANG schema element. -type Parent_Child struct { +// Parent_ChildPath represents the /openconfig-simple/parent/child YANG schema element. +type Parent_ChildPath struct { *ygot.NodePath } -// Parent_ChildAny represents the wildcard version of the /openconfig-simple/parent/child YANG schema element. -type Parent_ChildAny struct { +// Parent_ChildPathAny represents the wildcard version of the /openconfig-simple/parent/child YANG schema element. +type Parent_ChildPathAny struct { *ygot.NodePath } -// Parent_Child_Four represents the /openconfig-simple/parent/child/state/four YANG schema element. -type Parent_Child_Four struct { +// Parent_Child_FourPath represents the /openconfig-simple/parent/child/state/four YANG schema element. +type Parent_Child_FourPath struct { *ygot.NodePath } -// Parent_Child_FourAny represents the wildcard version of the /openconfig-simple/parent/child/state/four YANG schema element. -type Parent_Child_FourAny struct { +// Parent_Child_FourPathAny represents the wildcard version of the /openconfig-simple/parent/child/state/four YANG schema element. +type Parent_Child_FourPathAny struct { *ygot.NodePath } -// Parent_Child_One represents the /openconfig-simple/parent/child/state/one YANG schema element. -type Parent_Child_One struct { +// Parent_Child_OnePath represents the /openconfig-simple/parent/child/state/one YANG schema element. +type Parent_Child_OnePath struct { *ygot.NodePath } -// Parent_Child_OneAny represents the wildcard version of the /openconfig-simple/parent/child/state/one YANG schema element. -type Parent_Child_OneAny struct { +// Parent_Child_OnePathAny represents the wildcard version of the /openconfig-simple/parent/child/state/one YANG schema element. +type Parent_Child_OnePathAny struct { *ygot.NodePath } -// Parent_Child_Three represents the /openconfig-simple/parent/child/state/three YANG schema element. -type Parent_Child_Three struct { +// Parent_Child_ThreePath represents the /openconfig-simple/parent/child/state/three YANG schema element. +type Parent_Child_ThreePath struct { *ygot.NodePath } -// Parent_Child_ThreeAny represents the wildcard version of the /openconfig-simple/parent/child/state/three YANG schema element. -type Parent_Child_ThreeAny struct { +// Parent_Child_ThreePathAny represents the wildcard version of the /openconfig-simple/parent/child/state/three YANG schema element. +type Parent_Child_ThreePathAny struct { *ygot.NodePath } -// Parent_Child_Two represents the /openconfig-simple/parent/child/state/two YANG schema element. -type Parent_Child_Two struct { +// Parent_Child_TwoPath represents the /openconfig-simple/parent/child/state/two YANG schema element. +type Parent_Child_TwoPath struct { *ygot.NodePath } -// Parent_Child_TwoAny represents the wildcard version of the /openconfig-simple/parent/child/state/two YANG schema element. -type Parent_Child_TwoAny struct { +// Parent_Child_TwoPathAny represents the wildcard version of the /openconfig-simple/parent/child/state/two YANG schema element. +type Parent_Child_TwoPathAny struct { *ygot.NodePath } -// Four returns from Parent_Child the path struct for its child "four". -func (n *Parent_Child) Four() *Parent_Child_Four { - return &Parent_Child_Four{ +// Four returns from Parent_ChildPath the path struct for its child "four". +func (n *Parent_ChildPath) Four() *Parent_Child_FourPath { + return &Parent_Child_FourPath{ NodePath: ygot.NewNodePath( []string{"state", "four"}, map[string]interface{}{}, @@ -76,9 +75,9 @@ func (n *Parent_Child) Four() *Parent_Child_Four { } } -// Four returns from Parent_ChildAny the path struct for its child "four". -func (n *Parent_ChildAny) Four() *Parent_Child_FourAny { - return &Parent_Child_FourAny{ +// Four returns from Parent_ChildPathAny the path struct for its child "four". +func (n *Parent_ChildPathAny) Four() *Parent_Child_FourPathAny { + return &Parent_Child_FourPathAny{ NodePath: ygot.NewNodePath( []string{"state", "four"}, map[string]interface{}{}, @@ -87,9 +86,9 @@ func (n *Parent_ChildAny) Four() *Parent_Child_FourAny { } } -// One returns from Parent_Child the path struct for its child "one". -func (n *Parent_Child) One() *Parent_Child_One { - return &Parent_Child_One{ +// One returns from Parent_ChildPath the path struct for its child "one". +func (n *Parent_ChildPath) One() *Parent_Child_OnePath { + return &Parent_Child_OnePath{ NodePath: ygot.NewNodePath( []string{"state", "one"}, map[string]interface{}{}, @@ -98,9 +97,9 @@ func (n *Parent_Child) One() *Parent_Child_One { } } -// One returns from Parent_ChildAny the path struct for its child "one". -func (n *Parent_ChildAny) One() *Parent_Child_OneAny { - return &Parent_Child_OneAny{ +// One returns from Parent_ChildPathAny the path struct for its child "one". +func (n *Parent_ChildPathAny) One() *Parent_Child_OnePathAny { + return &Parent_Child_OnePathAny{ NodePath: ygot.NewNodePath( []string{"state", "one"}, map[string]interface{}{}, @@ -109,9 +108,9 @@ func (n *Parent_ChildAny) One() *Parent_Child_OneAny { } } -// Three returns from Parent_Child the path struct for its child "three". -func (n *Parent_Child) Three() *Parent_Child_Three { - return &Parent_Child_Three{ +// Three returns from Parent_ChildPath the path struct for its child "three". +func (n *Parent_ChildPath) Three() *Parent_Child_ThreePath { + return &Parent_Child_ThreePath{ NodePath: ygot.NewNodePath( []string{"state", "three"}, map[string]interface{}{}, @@ -120,9 +119,9 @@ func (n *Parent_Child) Three() *Parent_Child_Three { } } -// Three returns from Parent_ChildAny the path struct for its child "three". -func (n *Parent_ChildAny) Three() *Parent_Child_ThreeAny { - return &Parent_Child_ThreeAny{ +// Three returns from Parent_ChildPathAny the path struct for its child "three". +func (n *Parent_ChildPathAny) Three() *Parent_Child_ThreePathAny { + return &Parent_Child_ThreePathAny{ NodePath: ygot.NewNodePath( []string{"state", "three"}, map[string]interface{}{}, @@ -131,9 +130,9 @@ func (n *Parent_ChildAny) Three() *Parent_Child_ThreeAny { } } -// Two returns from Parent_Child the path struct for its child "two". -func (n *Parent_Child) Two() *Parent_Child_Two { - return &Parent_Child_Two{ +// Two returns from Parent_ChildPath the path struct for its child "two". +func (n *Parent_ChildPath) Two() *Parent_Child_TwoPath { + return &Parent_Child_TwoPath{ NodePath: ygot.NewNodePath( []string{"state", "two"}, map[string]interface{}{}, @@ -142,9 +141,9 @@ func (n *Parent_Child) Two() *Parent_Child_Two { } } -// Two returns from Parent_ChildAny the path struct for its child "two". -func (n *Parent_ChildAny) Two() *Parent_Child_TwoAny { - return &Parent_Child_TwoAny{ +// Two returns from Parent_ChildPathAny the path struct for its child "two". +func (n *Parent_ChildPathAny) Two() *Parent_Child_TwoPathAny { + return &Parent_Child_TwoPathAny{ NodePath: ygot.NewNodePath( []string{"state", "two"}, map[string]interface{}{}, @@ -153,29 +152,29 @@ func (n *Parent_ChildAny) Two() *Parent_Child_TwoAny { } } -// RemoteContainer represents the /openconfig-simple/remote-container YANG schema element. -type RemoteContainer struct { +// RemoteContainerPath represents the /openconfig-simple/remote-container YANG schema element. +type RemoteContainerPath struct { *ygot.NodePath } -// RemoteContainerAny represents the wildcard version of the /openconfig-simple/remote-container YANG schema element. -type RemoteContainerAny struct { +// RemoteContainerPathAny represents the wildcard version of the /openconfig-simple/remote-container YANG schema element. +type RemoteContainerPathAny struct { *ygot.NodePath } -// RemoteContainer_ALeaf represents the /openconfig-simple/remote-container/state/a-leaf YANG schema element. -type RemoteContainer_ALeaf struct { +// RemoteContainer_ALeafPath represents the /openconfig-simple/remote-container/state/a-leaf YANG schema element. +type RemoteContainer_ALeafPath struct { *ygot.NodePath } -// RemoteContainer_ALeafAny represents the wildcard version of the /openconfig-simple/remote-container/state/a-leaf YANG schema element. -type RemoteContainer_ALeafAny struct { +// RemoteContainer_ALeafPathAny represents the wildcard version of the /openconfig-simple/remote-container/state/a-leaf YANG schema element. +type RemoteContainer_ALeafPathAny struct { *ygot.NodePath } -// ALeaf returns from RemoteContainer the path struct for its child "a-leaf". -func (n *RemoteContainer) ALeaf() *RemoteContainer_ALeaf { - return &RemoteContainer_ALeaf{ +// ALeaf returns from RemoteContainerPath the path struct for its child "a-leaf". +func (n *RemoteContainerPath) ALeaf() *RemoteContainer_ALeafPath { + return &RemoteContainer_ALeafPath{ NodePath: ygot.NewNodePath( []string{"state", "a-leaf"}, map[string]interface{}{}, @@ -184,9 +183,9 @@ func (n *RemoteContainer) ALeaf() *RemoteContainer_ALeaf { } } -// ALeaf returns from RemoteContainerAny the path struct for its child "a-leaf". -func (n *RemoteContainerAny) ALeaf() *RemoteContainer_ALeafAny { - return &RemoteContainer_ALeafAny{ +// ALeaf returns from RemoteContainerPathAny the path struct for its child "a-leaf". +func (n *RemoteContainerPathAny) ALeaf() *RemoteContainer_ALeafPathAny { + return &RemoteContainer_ALeafPathAny{ NodePath: ygot.NewNodePath( []string{"state", "a-leaf"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-simple-intendedconfig.path-txt b/ypathgen/testdata/structs/openconfig-simple-intendedconfig.path-txt index 2a871ec5a..b3008a74f 100644 --- a/ypathgen/testdata/structs/openconfig-simple-intendedconfig.path-txt +++ b/ypathgen/testdata/structs/openconfig-simple-intendedconfig.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// Parent returns from Device the path struct for its child "parent". -func (n *Device) Parent() *Parent { - return &Parent{ +// Parent returns from DevicePath the path struct for its child "parent". +func (n *DevicePath) Parent() *ParentPath { + return &ParentPath{ NodePath: ygot.NewNodePath( []string{"parent"}, map[string]interface{}{}, @@ -36,9 +35,9 @@ func (n *Device) Parent() *Parent { } } -// RemoteContainer returns from Device the path struct for its child "remote-container". -func (n *Device) RemoteContainer() *RemoteContainer { - return &RemoteContainer{ +// RemoteContainer returns from DevicePath the path struct for its child "remote-container". +func (n *DevicePath) RemoteContainer() *RemoteContainerPath { + return &RemoteContainerPath{ NodePath: ygot.NewNodePath( []string{"remote-container"}, map[string]interface{}{}, @@ -47,19 +46,19 @@ func (n *Device) RemoteContainer() *RemoteContainer { } } -// Parent represents the /openconfig-simple/parent YANG schema element. -type Parent struct { +// ParentPath represents the /openconfig-simple/parent YANG schema element. +type ParentPath struct { *ygot.NodePath } -// ParentAny represents the wildcard version of the /openconfig-simple/parent YANG schema element. -type ParentAny struct { +// ParentPathAny represents the wildcard version of the /openconfig-simple/parent YANG schema element. +type ParentPathAny struct { *ygot.NodePath } -// Child returns from Parent the path struct for its child "child". -func (n *Parent) Child() *Parent_Child { - return &Parent_Child{ +// Child returns from ParentPath the path struct for its child "child". +func (n *ParentPath) Child() *Parent_ChildPath { + return &Parent_ChildPath{ NodePath: ygot.NewNodePath( []string{"child"}, map[string]interface{}{}, @@ -68,9 +67,9 @@ func (n *Parent) Child() *Parent_Child { } } -// Child returns from ParentAny the path struct for its child "child". -func (n *ParentAny) Child() *Parent_ChildAny { - return &Parent_ChildAny{ +// Child returns from ParentPathAny the path struct for its child "child". +func (n *ParentPathAny) Child() *Parent_ChildPathAny { + return &Parent_ChildPathAny{ NodePath: ygot.NewNodePath( []string{"child"}, map[string]interface{}{}, @@ -79,59 +78,59 @@ func (n *ParentAny) Child() *Parent_ChildAny { } } -// Parent_Child represents the /openconfig-simple/parent/child YANG schema element. -type Parent_Child struct { +// Parent_ChildPath represents the /openconfig-simple/parent/child YANG schema element. +type Parent_ChildPath struct { *ygot.NodePath } -// Parent_ChildAny represents the wildcard version of the /openconfig-simple/parent/child YANG schema element. -type Parent_ChildAny struct { +// Parent_ChildPathAny represents the wildcard version of the /openconfig-simple/parent/child YANG schema element. +type Parent_ChildPathAny struct { *ygot.NodePath } -// Parent_Child_Four represents the /openconfig-simple/parent/child/config/four YANG schema element. -type Parent_Child_Four struct { +// Parent_Child_FourPath represents the /openconfig-simple/parent/child/config/four YANG schema element. +type Parent_Child_FourPath struct { *ygot.NodePath } -// Parent_Child_FourAny represents the wildcard version of the /openconfig-simple/parent/child/config/four YANG schema element. -type Parent_Child_FourAny struct { +// Parent_Child_FourPathAny represents the wildcard version of the /openconfig-simple/parent/child/config/four YANG schema element. +type Parent_Child_FourPathAny struct { *ygot.NodePath } -// Parent_Child_One represents the /openconfig-simple/parent/child/config/one YANG schema element. -type Parent_Child_One struct { +// Parent_Child_OnePath represents the /openconfig-simple/parent/child/config/one YANG schema element. +type Parent_Child_OnePath struct { *ygot.NodePath } -// Parent_Child_OneAny represents the wildcard version of the /openconfig-simple/parent/child/config/one YANG schema element. -type Parent_Child_OneAny struct { +// Parent_Child_OnePathAny represents the wildcard version of the /openconfig-simple/parent/child/config/one YANG schema element. +type Parent_Child_OnePathAny struct { *ygot.NodePath } -// Parent_Child_Three represents the /openconfig-simple/parent/child/config/three YANG schema element. -type Parent_Child_Three struct { +// Parent_Child_ThreePath represents the /openconfig-simple/parent/child/config/three YANG schema element. +type Parent_Child_ThreePath struct { *ygot.NodePath } -// Parent_Child_ThreeAny represents the wildcard version of the /openconfig-simple/parent/child/config/three YANG schema element. -type Parent_Child_ThreeAny struct { +// Parent_Child_ThreePathAny represents the wildcard version of the /openconfig-simple/parent/child/config/three YANG schema element. +type Parent_Child_ThreePathAny struct { *ygot.NodePath } -// Parent_Child_Two represents the /openconfig-simple/parent/child/state/two YANG schema element. -type Parent_Child_Two struct { +// Parent_Child_TwoPath represents the /openconfig-simple/parent/child/state/two YANG schema element. +type Parent_Child_TwoPath struct { *ygot.NodePath } -// Parent_Child_TwoAny represents the wildcard version of the /openconfig-simple/parent/child/state/two YANG schema element. -type Parent_Child_TwoAny struct { +// Parent_Child_TwoPathAny represents the wildcard version of the /openconfig-simple/parent/child/state/two YANG schema element. +type Parent_Child_TwoPathAny struct { *ygot.NodePath } -// Four returns from Parent_Child the path struct for its child "four". -func (n *Parent_Child) Four() *Parent_Child_Four { - return &Parent_Child_Four{ +// Four returns from Parent_ChildPath the path struct for its child "four". +func (n *Parent_ChildPath) Four() *Parent_Child_FourPath { + return &Parent_Child_FourPath{ NodePath: ygot.NewNodePath( []string{"config", "four"}, map[string]interface{}{}, @@ -140,9 +139,9 @@ func (n *Parent_Child) Four() *Parent_Child_Four { } } -// Four returns from Parent_ChildAny the path struct for its child "four". -func (n *Parent_ChildAny) Four() *Parent_Child_FourAny { - return &Parent_Child_FourAny{ +// Four returns from Parent_ChildPathAny the path struct for its child "four". +func (n *Parent_ChildPathAny) Four() *Parent_Child_FourPathAny { + return &Parent_Child_FourPathAny{ NodePath: ygot.NewNodePath( []string{"config", "four"}, map[string]interface{}{}, @@ -151,9 +150,9 @@ func (n *Parent_ChildAny) Four() *Parent_Child_FourAny { } } -// One returns from Parent_Child the path struct for its child "one". -func (n *Parent_Child) One() *Parent_Child_One { - return &Parent_Child_One{ +// One returns from Parent_ChildPath the path struct for its child "one". +func (n *Parent_ChildPath) One() *Parent_Child_OnePath { + return &Parent_Child_OnePath{ NodePath: ygot.NewNodePath( []string{"config", "one"}, map[string]interface{}{}, @@ -162,9 +161,9 @@ func (n *Parent_Child) One() *Parent_Child_One { } } -// One returns from Parent_ChildAny the path struct for its child "one". -func (n *Parent_ChildAny) One() *Parent_Child_OneAny { - return &Parent_Child_OneAny{ +// One returns from Parent_ChildPathAny the path struct for its child "one". +func (n *Parent_ChildPathAny) One() *Parent_Child_OnePathAny { + return &Parent_Child_OnePathAny{ NodePath: ygot.NewNodePath( []string{"config", "one"}, map[string]interface{}{}, @@ -173,9 +172,9 @@ func (n *Parent_ChildAny) One() *Parent_Child_OneAny { } } -// Three returns from Parent_Child the path struct for its child "three". -func (n *Parent_Child) Three() *Parent_Child_Three { - return &Parent_Child_Three{ +// Three returns from Parent_ChildPath the path struct for its child "three". +func (n *Parent_ChildPath) Three() *Parent_Child_ThreePath { + return &Parent_Child_ThreePath{ NodePath: ygot.NewNodePath( []string{"config", "three"}, map[string]interface{}{}, @@ -184,9 +183,9 @@ func (n *Parent_Child) Three() *Parent_Child_Three { } } -// Three returns from Parent_ChildAny the path struct for its child "three". -func (n *Parent_ChildAny) Three() *Parent_Child_ThreeAny { - return &Parent_Child_ThreeAny{ +// Three returns from Parent_ChildPathAny the path struct for its child "three". +func (n *Parent_ChildPathAny) Three() *Parent_Child_ThreePathAny { + return &Parent_Child_ThreePathAny{ NodePath: ygot.NewNodePath( []string{"config", "three"}, map[string]interface{}{}, @@ -195,9 +194,9 @@ func (n *Parent_ChildAny) Three() *Parent_Child_ThreeAny { } } -// Two returns from Parent_Child the path struct for its child "two". -func (n *Parent_Child) Two() *Parent_Child_Two { - return &Parent_Child_Two{ +// Two returns from Parent_ChildPath the path struct for its child "two". +func (n *Parent_ChildPath) Two() *Parent_Child_TwoPath { + return &Parent_Child_TwoPath{ NodePath: ygot.NewNodePath( []string{"state", "two"}, map[string]interface{}{}, @@ -206,9 +205,9 @@ func (n *Parent_Child) Two() *Parent_Child_Two { } } -// Two returns from Parent_ChildAny the path struct for its child "two". -func (n *Parent_ChildAny) Two() *Parent_Child_TwoAny { - return &Parent_Child_TwoAny{ +// Two returns from Parent_ChildPathAny the path struct for its child "two". +func (n *Parent_ChildPathAny) Two() *Parent_Child_TwoPathAny { + return &Parent_Child_TwoPathAny{ NodePath: ygot.NewNodePath( []string{"state", "two"}, map[string]interface{}{}, @@ -217,29 +216,29 @@ func (n *Parent_ChildAny) Two() *Parent_Child_TwoAny { } } -// RemoteContainer represents the /openconfig-simple/remote-container YANG schema element. -type RemoteContainer struct { +// RemoteContainerPath represents the /openconfig-simple/remote-container YANG schema element. +type RemoteContainerPath struct { *ygot.NodePath } -// RemoteContainerAny represents the wildcard version of the /openconfig-simple/remote-container YANG schema element. -type RemoteContainerAny struct { +// RemoteContainerPathAny represents the wildcard version of the /openconfig-simple/remote-container YANG schema element. +type RemoteContainerPathAny struct { *ygot.NodePath } -// RemoteContainer_ALeaf represents the /openconfig-simple/remote-container/config/a-leaf YANG schema element. -type RemoteContainer_ALeaf struct { +// RemoteContainer_ALeafPath represents the /openconfig-simple/remote-container/config/a-leaf YANG schema element. +type RemoteContainer_ALeafPath struct { *ygot.NodePath } -// RemoteContainer_ALeafAny represents the wildcard version of the /openconfig-simple/remote-container/config/a-leaf YANG schema element. -type RemoteContainer_ALeafAny struct { +// RemoteContainer_ALeafPathAny represents the wildcard version of the /openconfig-simple/remote-container/config/a-leaf YANG schema element. +type RemoteContainer_ALeafPathAny struct { *ygot.NodePath } -// ALeaf returns from RemoteContainer the path struct for its child "a-leaf". -func (n *RemoteContainer) ALeaf() *RemoteContainer_ALeaf { - return &RemoteContainer_ALeaf{ +// ALeaf returns from RemoteContainerPath the path struct for its child "a-leaf". +func (n *RemoteContainerPath) ALeaf() *RemoteContainer_ALeafPath { + return &RemoteContainer_ALeafPath{ NodePath: ygot.NewNodePath( []string{"config", "a-leaf"}, map[string]interface{}{}, @@ -248,9 +247,9 @@ func (n *RemoteContainer) ALeaf() *RemoteContainer_ALeaf { } } -// ALeaf returns from RemoteContainerAny the path struct for its child "a-leaf". -func (n *RemoteContainerAny) ALeaf() *RemoteContainer_ALeafAny { - return &RemoteContainer_ALeafAny{ +// ALeaf returns from RemoteContainerPathAny the path struct for its child "a-leaf". +func (n *RemoteContainerPathAny) ALeaf() *RemoteContainer_ALeafPathAny { + return &RemoteContainer_ALeafPathAny{ NodePath: ygot.NewNodePath( []string{"config", "a-leaf"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-simple.path-txt b/ypathgen/testdata/structs/openconfig-simple.path-txt index 2055e5adf..8c3e9ec77 100644 --- a/ypathgen/testdata/structs/openconfig-simple.path-txt +++ b/ypathgen/testdata/structs/openconfig-simple.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// Parent returns from Device the path struct for its child "parent". -func (n *Device) Parent() *Parent { - return &Parent{ +// Parent returns from DevicePath the path struct for its child "parent". +func (n *DevicePath) Parent() *ParentPath { + return &ParentPath{ NodePath: ygot.NewNodePath( []string{"parent"}, map[string]interface{}{}, @@ -36,9 +35,9 @@ func (n *Device) Parent() *Parent { } } -// RemoteContainer returns from Device the path struct for its child "remote-container". -func (n *Device) RemoteContainer() *RemoteContainer { - return &RemoteContainer{ +// RemoteContainer returns from DevicePath the path struct for its child "remote-container". +func (n *DevicePath) RemoteContainer() *RemoteContainerPath { + return &RemoteContainerPath{ NodePath: ygot.NewNodePath( []string{"remote-container"}, map[string]interface{}{}, @@ -47,19 +46,19 @@ func (n *Device) RemoteContainer() *RemoteContainer { } } -// Parent represents the /openconfig-simple/parent YANG schema element. -type Parent struct { +// ParentPath represents the /openconfig-simple/parent YANG schema element. +type ParentPath struct { *ygot.NodePath } -// ParentAny represents the wildcard version of the /openconfig-simple/parent YANG schema element. -type ParentAny struct { +// ParentPathAny represents the wildcard version of the /openconfig-simple/parent YANG schema element. +type ParentPathAny struct { *ygot.NodePath } -// Child returns from Parent the path struct for its child "child". -func (n *Parent) Child() *Parent_Child { - return &Parent_Child{ +// Child returns from ParentPath the path struct for its child "child". +func (n *ParentPath) Child() *Parent_ChildPath { + return &Parent_ChildPath{ NodePath: ygot.NewNodePath( []string{"child"}, map[string]interface{}{}, @@ -68,9 +67,9 @@ func (n *Parent) Child() *Parent_Child { } } -// Child returns from ParentAny the path struct for its child "child". -func (n *ParentAny) Child() *Parent_ChildAny { - return &Parent_ChildAny{ +// Child returns from ParentPathAny the path struct for its child "child". +func (n *ParentPathAny) Child() *Parent_ChildPathAny { + return &Parent_ChildPathAny{ NodePath: ygot.NewNodePath( []string{"child"}, map[string]interface{}{}, @@ -79,59 +78,59 @@ func (n *ParentAny) Child() *Parent_ChildAny { } } -// Parent_Child represents the /openconfig-simple/parent/child YANG schema element. -type Parent_Child struct { +// Parent_ChildPath represents the /openconfig-simple/parent/child YANG schema element. +type Parent_ChildPath struct { *ygot.NodePath } -// Parent_ChildAny represents the wildcard version of the /openconfig-simple/parent/child YANG schema element. -type Parent_ChildAny struct { +// Parent_ChildPathAny represents the wildcard version of the /openconfig-simple/parent/child YANG schema element. +type Parent_ChildPathAny struct { *ygot.NodePath } -// Parent_Child_Four represents the /openconfig-simple/parent/child/state/four YANG schema element. -type Parent_Child_Four struct { +// Parent_Child_FourPath represents the /openconfig-simple/parent/child/state/four YANG schema element. +type Parent_Child_FourPath struct { *ygot.NodePath } -// Parent_Child_FourAny represents the wildcard version of the /openconfig-simple/parent/child/state/four YANG schema element. -type Parent_Child_FourAny struct { +// Parent_Child_FourPathAny represents the wildcard version of the /openconfig-simple/parent/child/state/four YANG schema element. +type Parent_Child_FourPathAny struct { *ygot.NodePath } -// Parent_Child_One represents the /openconfig-simple/parent/child/state/one YANG schema element. -type Parent_Child_One struct { +// Parent_Child_OnePath represents the /openconfig-simple/parent/child/state/one YANG schema element. +type Parent_Child_OnePath struct { *ygot.NodePath } -// Parent_Child_OneAny represents the wildcard version of the /openconfig-simple/parent/child/state/one YANG schema element. -type Parent_Child_OneAny struct { +// Parent_Child_OnePathAny represents the wildcard version of the /openconfig-simple/parent/child/state/one YANG schema element. +type Parent_Child_OnePathAny struct { *ygot.NodePath } -// Parent_Child_Three represents the /openconfig-simple/parent/child/state/three YANG schema element. -type Parent_Child_Three struct { +// Parent_Child_ThreePath represents the /openconfig-simple/parent/child/state/three YANG schema element. +type Parent_Child_ThreePath struct { *ygot.NodePath } -// Parent_Child_ThreeAny represents the wildcard version of the /openconfig-simple/parent/child/state/three YANG schema element. -type Parent_Child_ThreeAny struct { +// Parent_Child_ThreePathAny represents the wildcard version of the /openconfig-simple/parent/child/state/three YANG schema element. +type Parent_Child_ThreePathAny struct { *ygot.NodePath } -// Parent_Child_Two represents the /openconfig-simple/parent/child/state/two YANG schema element. -type Parent_Child_Two struct { +// Parent_Child_TwoPath represents the /openconfig-simple/parent/child/state/two YANG schema element. +type Parent_Child_TwoPath struct { *ygot.NodePath } -// Parent_Child_TwoAny represents the wildcard version of the /openconfig-simple/parent/child/state/two YANG schema element. -type Parent_Child_TwoAny struct { +// Parent_Child_TwoPathAny represents the wildcard version of the /openconfig-simple/parent/child/state/two YANG schema element. +type Parent_Child_TwoPathAny struct { *ygot.NodePath } -// Four returns from Parent_Child the path struct for its child "four". -func (n *Parent_Child) Four() *Parent_Child_Four { - return &Parent_Child_Four{ +// Four returns from Parent_ChildPath the path struct for its child "four". +func (n *Parent_ChildPath) Four() *Parent_Child_FourPath { + return &Parent_Child_FourPath{ NodePath: ygot.NewNodePath( []string{"state", "four"}, map[string]interface{}{}, @@ -140,9 +139,9 @@ func (n *Parent_Child) Four() *Parent_Child_Four { } } -// Four returns from Parent_ChildAny the path struct for its child "four". -func (n *Parent_ChildAny) Four() *Parent_Child_FourAny { - return &Parent_Child_FourAny{ +// Four returns from Parent_ChildPathAny the path struct for its child "four". +func (n *Parent_ChildPathAny) Four() *Parent_Child_FourPathAny { + return &Parent_Child_FourPathAny{ NodePath: ygot.NewNodePath( []string{"state", "four"}, map[string]interface{}{}, @@ -151,9 +150,9 @@ func (n *Parent_ChildAny) Four() *Parent_Child_FourAny { } } -// One returns from Parent_Child the path struct for its child "one". -func (n *Parent_Child) One() *Parent_Child_One { - return &Parent_Child_One{ +// One returns from Parent_ChildPath the path struct for its child "one". +func (n *Parent_ChildPath) One() *Parent_Child_OnePath { + return &Parent_Child_OnePath{ NodePath: ygot.NewNodePath( []string{"state", "one"}, map[string]interface{}{}, @@ -162,9 +161,9 @@ func (n *Parent_Child) One() *Parent_Child_One { } } -// One returns from Parent_ChildAny the path struct for its child "one". -func (n *Parent_ChildAny) One() *Parent_Child_OneAny { - return &Parent_Child_OneAny{ +// One returns from Parent_ChildPathAny the path struct for its child "one". +func (n *Parent_ChildPathAny) One() *Parent_Child_OnePathAny { + return &Parent_Child_OnePathAny{ NodePath: ygot.NewNodePath( []string{"state", "one"}, map[string]interface{}{}, @@ -173,9 +172,9 @@ func (n *Parent_ChildAny) One() *Parent_Child_OneAny { } } -// Three returns from Parent_Child the path struct for its child "three". -func (n *Parent_Child) Three() *Parent_Child_Three { - return &Parent_Child_Three{ +// Three returns from Parent_ChildPath the path struct for its child "three". +func (n *Parent_ChildPath) Three() *Parent_Child_ThreePath { + return &Parent_Child_ThreePath{ NodePath: ygot.NewNodePath( []string{"state", "three"}, map[string]interface{}{}, @@ -184,9 +183,9 @@ func (n *Parent_Child) Three() *Parent_Child_Three { } } -// Three returns from Parent_ChildAny the path struct for its child "three". -func (n *Parent_ChildAny) Three() *Parent_Child_ThreeAny { - return &Parent_Child_ThreeAny{ +// Three returns from Parent_ChildPathAny the path struct for its child "three". +func (n *Parent_ChildPathAny) Three() *Parent_Child_ThreePathAny { + return &Parent_Child_ThreePathAny{ NodePath: ygot.NewNodePath( []string{"state", "three"}, map[string]interface{}{}, @@ -195,9 +194,9 @@ func (n *Parent_ChildAny) Three() *Parent_Child_ThreeAny { } } -// Two returns from Parent_Child the path struct for its child "two". -func (n *Parent_Child) Two() *Parent_Child_Two { - return &Parent_Child_Two{ +// Two returns from Parent_ChildPath the path struct for its child "two". +func (n *Parent_ChildPath) Two() *Parent_Child_TwoPath { + return &Parent_Child_TwoPath{ NodePath: ygot.NewNodePath( []string{"state", "two"}, map[string]interface{}{}, @@ -206,9 +205,9 @@ func (n *Parent_Child) Two() *Parent_Child_Two { } } -// Two returns from Parent_ChildAny the path struct for its child "two". -func (n *Parent_ChildAny) Two() *Parent_Child_TwoAny { - return &Parent_Child_TwoAny{ +// Two returns from Parent_ChildPathAny the path struct for its child "two". +func (n *Parent_ChildPathAny) Two() *Parent_Child_TwoPathAny { + return &Parent_Child_TwoPathAny{ NodePath: ygot.NewNodePath( []string{"state", "two"}, map[string]interface{}{}, @@ -217,29 +216,29 @@ func (n *Parent_ChildAny) Two() *Parent_Child_TwoAny { } } -// RemoteContainer represents the /openconfig-simple/remote-container YANG schema element. -type RemoteContainer struct { +// RemoteContainerPath represents the /openconfig-simple/remote-container YANG schema element. +type RemoteContainerPath struct { *ygot.NodePath } -// RemoteContainerAny represents the wildcard version of the /openconfig-simple/remote-container YANG schema element. -type RemoteContainerAny struct { +// RemoteContainerPathAny represents the wildcard version of the /openconfig-simple/remote-container YANG schema element. +type RemoteContainerPathAny struct { *ygot.NodePath } -// RemoteContainer_ALeaf represents the /openconfig-simple/remote-container/state/a-leaf YANG schema element. -type RemoteContainer_ALeaf struct { +// RemoteContainer_ALeafPath represents the /openconfig-simple/remote-container/state/a-leaf YANG schema element. +type RemoteContainer_ALeafPath struct { *ygot.NodePath } -// RemoteContainer_ALeafAny represents the wildcard version of the /openconfig-simple/remote-container/state/a-leaf YANG schema element. -type RemoteContainer_ALeafAny struct { +// RemoteContainer_ALeafPathAny represents the wildcard version of the /openconfig-simple/remote-container/state/a-leaf YANG schema element. +type RemoteContainer_ALeafPathAny struct { *ygot.NodePath } -// ALeaf returns from RemoteContainer the path struct for its child "a-leaf". -func (n *RemoteContainer) ALeaf() *RemoteContainer_ALeaf { - return &RemoteContainer_ALeaf{ +// ALeaf returns from RemoteContainerPath the path struct for its child "a-leaf". +func (n *RemoteContainerPath) ALeaf() *RemoteContainer_ALeafPath { + return &RemoteContainer_ALeafPath{ NodePath: ygot.NewNodePath( []string{"state", "a-leaf"}, map[string]interface{}{}, @@ -248,9 +247,9 @@ func (n *RemoteContainer) ALeaf() *RemoteContainer_ALeaf { } } -// ALeaf returns from RemoteContainerAny the path struct for its child "a-leaf". -func (n *RemoteContainerAny) ALeaf() *RemoteContainer_ALeafAny { - return &RemoteContainer_ALeafAny{ +// ALeaf returns from RemoteContainerPathAny the path struct for its child "a-leaf". +func (n *RemoteContainerPathAny) ALeaf() *RemoteContainer_ALeafPathAny { + return &RemoteContainer_ALeafPathAny{ NodePath: ygot.NewNodePath( []string{"state", "a-leaf"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-unione.path-txt b/ypathgen/testdata/structs/openconfig-unione.path-txt index dc000744c..63e1b9e4e 100644 --- a/ypathgen/testdata/structs/openconfig-unione.path-txt +++ b/ypathgen/testdata/structs/openconfig-unione.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// DupEnum returns from Device the path struct for its child "dup-enum". -func (n *Device) DupEnum() *DupEnum { - return &DupEnum{ +// DupEnum returns from DevicePath the path struct for its child "dup-enum". +func (n *DevicePath) DupEnum() *DupEnumPath { + return &DupEnumPath{ NodePath: ygot.NewNodePath( []string{"dup-enum"}, map[string]interface{}{}, @@ -36,9 +35,9 @@ func (n *Device) DupEnum() *DupEnum { } } -// Platform returns from Device the path struct for its child "platform". -func (n *Device) Platform() *Platform { - return &Platform{ +// Platform returns from DevicePath the path struct for its child "platform". +func (n *DevicePath) Platform() *PlatformPath { + return &PlatformPath{ NodePath: ygot.NewNodePath( []string{"platform"}, map[string]interface{}{}, @@ -47,39 +46,39 @@ func (n *Device) Platform() *Platform { } } -// DupEnum represents the /openconfig-unione/dup-enum YANG schema element. -type DupEnum struct { +// DupEnumPath represents the /openconfig-unione/dup-enum YANG schema element. +type DupEnumPath struct { *ygot.NodePath } -// DupEnumAny represents the wildcard version of the /openconfig-unione/dup-enum YANG schema element. -type DupEnumAny struct { +// DupEnumPathAny represents the wildcard version of the /openconfig-unione/dup-enum YANG schema element. +type DupEnumPathAny struct { *ygot.NodePath } -// DupEnum_A represents the /openconfig-unione/dup-enum/state/A YANG schema element. -type DupEnum_A struct { +// DupEnum_APath represents the /openconfig-unione/dup-enum/state/A YANG schema element. +type DupEnum_APath struct { *ygot.NodePath } -// DupEnum_AAny represents the wildcard version of the /openconfig-unione/dup-enum/state/A YANG schema element. -type DupEnum_AAny struct { +// DupEnum_APathAny represents the wildcard version of the /openconfig-unione/dup-enum/state/A YANG schema element. +type DupEnum_APathAny struct { *ygot.NodePath } -// DupEnum_B represents the /openconfig-unione/dup-enum/state/B YANG schema element. -type DupEnum_B struct { +// DupEnum_BPath represents the /openconfig-unione/dup-enum/state/B YANG schema element. +type DupEnum_BPath struct { *ygot.NodePath } -// DupEnum_BAny represents the wildcard version of the /openconfig-unione/dup-enum/state/B YANG schema element. -type DupEnum_BAny struct { +// DupEnum_BPathAny represents the wildcard version of the /openconfig-unione/dup-enum/state/B YANG schema element. +type DupEnum_BPathAny struct { *ygot.NodePath } -// A returns from DupEnum the path struct for its child "A". -func (n *DupEnum) A() *DupEnum_A { - return &DupEnum_A{ +// A returns from DupEnumPath the path struct for its child "A". +func (n *DupEnumPath) A() *DupEnum_APath { + return &DupEnum_APath{ NodePath: ygot.NewNodePath( []string{"state", "A"}, map[string]interface{}{}, @@ -88,9 +87,9 @@ func (n *DupEnum) A() *DupEnum_A { } } -// A returns from DupEnumAny the path struct for its child "A". -func (n *DupEnumAny) A() *DupEnum_AAny { - return &DupEnum_AAny{ +// A returns from DupEnumPathAny the path struct for its child "A". +func (n *DupEnumPathAny) A() *DupEnum_APathAny { + return &DupEnum_APathAny{ NodePath: ygot.NewNodePath( []string{"state", "A"}, map[string]interface{}{}, @@ -99,9 +98,9 @@ func (n *DupEnumAny) A() *DupEnum_AAny { } } -// B returns from DupEnum the path struct for its child "B". -func (n *DupEnum) B() *DupEnum_B { - return &DupEnum_B{ +// B returns from DupEnumPath the path struct for its child "B". +func (n *DupEnumPath) B() *DupEnum_BPath { + return &DupEnum_BPath{ NodePath: ygot.NewNodePath( []string{"state", "B"}, map[string]interface{}{}, @@ -110,9 +109,9 @@ func (n *DupEnum) B() *DupEnum_B { } } -// B returns from DupEnumAny the path struct for its child "B". -func (n *DupEnumAny) B() *DupEnum_BAny { - return &DupEnum_BAny{ +// B returns from DupEnumPathAny the path struct for its child "B". +func (n *DupEnumPathAny) B() *DupEnum_BPathAny { + return &DupEnum_BPathAny{ NodePath: ygot.NewNodePath( []string{"state", "B"}, map[string]interface{}{}, @@ -121,19 +120,19 @@ func (n *DupEnumAny) B() *DupEnum_BAny { } } -// Platform represents the /openconfig-unione/platform YANG schema element. -type Platform struct { +// PlatformPath represents the /openconfig-unione/platform YANG schema element. +type PlatformPath struct { *ygot.NodePath } -// PlatformAny represents the wildcard version of the /openconfig-unione/platform YANG schema element. -type PlatformAny struct { +// PlatformPathAny represents the wildcard version of the /openconfig-unione/platform YANG schema element. +type PlatformPathAny struct { *ygot.NodePath } -// Component returns from Platform the path struct for its child "component". -func (n *Platform) Component() *Platform_Component { - return &Platform_Component{ +// Component returns from PlatformPath the path struct for its child "component". +func (n *PlatformPath) Component() *Platform_ComponentPath { + return &Platform_ComponentPath{ NodePath: ygot.NewNodePath( []string{"component"}, map[string]interface{}{}, @@ -142,9 +141,9 @@ func (n *Platform) Component() *Platform_Component { } } -// Component returns from PlatformAny the path struct for its child "component". -func (n *PlatformAny) Component() *Platform_ComponentAny { - return &Platform_ComponentAny{ +// Component returns from PlatformPathAny the path struct for its child "component". +func (n *PlatformPathAny) Component() *Platform_ComponentPathAny { + return &Platform_ComponentPathAny{ NodePath: ygot.NewNodePath( []string{"component"}, map[string]interface{}{}, @@ -153,69 +152,69 @@ func (n *PlatformAny) Component() *Platform_ComponentAny { } } -// Platform_Component represents the /openconfig-unione/platform/component YANG schema element. -type Platform_Component struct { +// Platform_ComponentPath represents the /openconfig-unione/platform/component YANG schema element. +type Platform_ComponentPath struct { *ygot.NodePath } -// Platform_ComponentAny represents the wildcard version of the /openconfig-unione/platform/component YANG schema element. -type Platform_ComponentAny struct { +// Platform_ComponentPathAny represents the wildcard version of the /openconfig-unione/platform/component YANG schema element. +type Platform_ComponentPathAny struct { *ygot.NodePath } -// Platform_Component_E1 represents the /openconfig-unione/platform/component/state/e1 YANG schema element. -type Platform_Component_E1 struct { +// Platform_Component_E1Path represents the /openconfig-unione/platform/component/state/e1 YANG schema element. +type Platform_Component_E1Path struct { *ygot.NodePath } -// Platform_Component_E1Any represents the wildcard version of the /openconfig-unione/platform/component/state/e1 YANG schema element. -type Platform_Component_E1Any struct { +// Platform_Component_E1PathAny represents the wildcard version of the /openconfig-unione/platform/component/state/e1 YANG schema element. +type Platform_Component_E1PathAny struct { *ygot.NodePath } -// Platform_Component_Enumerated represents the /openconfig-unione/platform/component/state/enumerated YANG schema element. -type Platform_Component_Enumerated struct { +// Platform_Component_EnumeratedPath represents the /openconfig-unione/platform/component/state/enumerated YANG schema element. +type Platform_Component_EnumeratedPath struct { *ygot.NodePath } -// Platform_Component_EnumeratedAny represents the wildcard version of the /openconfig-unione/platform/component/state/enumerated YANG schema element. -type Platform_Component_EnumeratedAny struct { +// Platform_Component_EnumeratedPathAny represents the wildcard version of the /openconfig-unione/platform/component/state/enumerated YANG schema element. +type Platform_Component_EnumeratedPathAny struct { *ygot.NodePath } -// Platform_Component_Power represents the /openconfig-unione/platform/component/state/power YANG schema element. -type Platform_Component_Power struct { +// Platform_Component_PowerPath represents the /openconfig-unione/platform/component/state/power YANG schema element. +type Platform_Component_PowerPath struct { *ygot.NodePath } -// Platform_Component_PowerAny represents the wildcard version of the /openconfig-unione/platform/component/state/power YANG schema element. -type Platform_Component_PowerAny struct { +// Platform_Component_PowerPathAny represents the wildcard version of the /openconfig-unione/platform/component/state/power YANG schema element. +type Platform_Component_PowerPathAny struct { *ygot.NodePath } -// Platform_Component_R1 represents the /openconfig-unione/platform/component/state/r1 YANG schema element. -type Platform_Component_R1 struct { +// Platform_Component_R1Path represents the /openconfig-unione/platform/component/state/r1 YANG schema element. +type Platform_Component_R1Path struct { *ygot.NodePath } -// Platform_Component_R1Any represents the wildcard version of the /openconfig-unione/platform/component/state/r1 YANG schema element. -type Platform_Component_R1Any struct { +// Platform_Component_R1PathAny represents the wildcard version of the /openconfig-unione/platform/component/state/r1 YANG schema element. +type Platform_Component_R1PathAny struct { *ygot.NodePath } -// Platform_Component_Type represents the /openconfig-unione/platform/component/state/type YANG schema element. -type Platform_Component_Type struct { +// Platform_Component_TypePath represents the /openconfig-unione/platform/component/state/type YANG schema element. +type Platform_Component_TypePath struct { *ygot.NodePath } -// Platform_Component_TypeAny represents the wildcard version of the /openconfig-unione/platform/component/state/type YANG schema element. -type Platform_Component_TypeAny struct { +// Platform_Component_TypePathAny represents the wildcard version of the /openconfig-unione/platform/component/state/type YANG schema element. +type Platform_Component_TypePathAny struct { *ygot.NodePath } -// E1 returns from Platform_Component the path struct for its child "e1". -func (n *Platform_Component) E1() *Platform_Component_E1 { - return &Platform_Component_E1{ +// E1 returns from Platform_ComponentPath the path struct for its child "e1". +func (n *Platform_ComponentPath) E1() *Platform_Component_E1Path { + return &Platform_Component_E1Path{ NodePath: ygot.NewNodePath( []string{"state", "e1"}, map[string]interface{}{}, @@ -224,9 +223,9 @@ func (n *Platform_Component) E1() *Platform_Component_E1 { } } -// E1 returns from Platform_ComponentAny the path struct for its child "e1". -func (n *Platform_ComponentAny) E1() *Platform_Component_E1Any { - return &Platform_Component_E1Any{ +// E1 returns from Platform_ComponentPathAny the path struct for its child "e1". +func (n *Platform_ComponentPathAny) E1() *Platform_Component_E1PathAny { + return &Platform_Component_E1PathAny{ NodePath: ygot.NewNodePath( []string{"state", "e1"}, map[string]interface{}{}, @@ -235,9 +234,9 @@ func (n *Platform_ComponentAny) E1() *Platform_Component_E1Any { } } -// Enumerated returns from Platform_Component the path struct for its child "enumerated". -func (n *Platform_Component) Enumerated() *Platform_Component_Enumerated { - return &Platform_Component_Enumerated{ +// Enumerated returns from Platform_ComponentPath the path struct for its child "enumerated". +func (n *Platform_ComponentPath) Enumerated() *Platform_Component_EnumeratedPath { + return &Platform_Component_EnumeratedPath{ NodePath: ygot.NewNodePath( []string{"state", "enumerated"}, map[string]interface{}{}, @@ -246,9 +245,9 @@ func (n *Platform_Component) Enumerated() *Platform_Component_Enumerated { } } -// Enumerated returns from Platform_ComponentAny the path struct for its child "enumerated". -func (n *Platform_ComponentAny) Enumerated() *Platform_Component_EnumeratedAny { - return &Platform_Component_EnumeratedAny{ +// Enumerated returns from Platform_ComponentPathAny the path struct for its child "enumerated". +func (n *Platform_ComponentPathAny) Enumerated() *Platform_Component_EnumeratedPathAny { + return &Platform_Component_EnumeratedPathAny{ NodePath: ygot.NewNodePath( []string{"state", "enumerated"}, map[string]interface{}{}, @@ -257,9 +256,9 @@ func (n *Platform_ComponentAny) Enumerated() *Platform_Component_EnumeratedAny { } } -// Power returns from Platform_Component the path struct for its child "power". -func (n *Platform_Component) Power() *Platform_Component_Power { - return &Platform_Component_Power{ +// Power returns from Platform_ComponentPath the path struct for its child "power". +func (n *Platform_ComponentPath) Power() *Platform_Component_PowerPath { + return &Platform_Component_PowerPath{ NodePath: ygot.NewNodePath( []string{"state", "power"}, map[string]interface{}{}, @@ -268,9 +267,9 @@ func (n *Platform_Component) Power() *Platform_Component_Power { } } -// Power returns from Platform_ComponentAny the path struct for its child "power". -func (n *Platform_ComponentAny) Power() *Platform_Component_PowerAny { - return &Platform_Component_PowerAny{ +// Power returns from Platform_ComponentPathAny the path struct for its child "power". +func (n *Platform_ComponentPathAny) Power() *Platform_Component_PowerPathAny { + return &Platform_Component_PowerPathAny{ NodePath: ygot.NewNodePath( []string{"state", "power"}, map[string]interface{}{}, @@ -279,9 +278,9 @@ func (n *Platform_ComponentAny) Power() *Platform_Component_PowerAny { } } -// R1 returns from Platform_Component the path struct for its child "r1". -func (n *Platform_Component) R1() *Platform_Component_R1 { - return &Platform_Component_R1{ +// R1 returns from Platform_ComponentPath the path struct for its child "r1". +func (n *Platform_ComponentPath) R1() *Platform_Component_R1Path { + return &Platform_Component_R1Path{ NodePath: ygot.NewNodePath( []string{"state", "r1"}, map[string]interface{}{}, @@ -290,9 +289,9 @@ func (n *Platform_Component) R1() *Platform_Component_R1 { } } -// R1 returns from Platform_ComponentAny the path struct for its child "r1". -func (n *Platform_ComponentAny) R1() *Platform_Component_R1Any { - return &Platform_Component_R1Any{ +// R1 returns from Platform_ComponentPathAny the path struct for its child "r1". +func (n *Platform_ComponentPathAny) R1() *Platform_Component_R1PathAny { + return &Platform_Component_R1PathAny{ NodePath: ygot.NewNodePath( []string{"state", "r1"}, map[string]interface{}{}, @@ -301,9 +300,9 @@ func (n *Platform_ComponentAny) R1() *Platform_Component_R1Any { } } -// Type returns from Platform_Component the path struct for its child "type". -func (n *Platform_Component) Type() *Platform_Component_Type { - return &Platform_Component_Type{ +// Type returns from Platform_ComponentPath the path struct for its child "type". +func (n *Platform_ComponentPath) Type() *Platform_Component_TypePath { + return &Platform_Component_TypePath{ NodePath: ygot.NewNodePath( []string{"state", "type"}, map[string]interface{}{}, @@ -312,9 +311,9 @@ func (n *Platform_Component) Type() *Platform_Component_Type { } } -// Type returns from Platform_ComponentAny the path struct for its child "type". -func (n *Platform_ComponentAny) Type() *Platform_Component_TypeAny { - return &Platform_Component_TypeAny{ +// Type returns from Platform_ComponentPathAny the path struct for its child "type". +func (n *Platform_ComponentPathAny) Type() *Platform_Component_TypePathAny { + return &Platform_Component_TypePathAny{ NodePath: ygot.NewNodePath( []string{"state", "type"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-withlist-builder.path-txt b/ypathgen/testdata/structs/openconfig-withlist-builder.path-txt index 03ce926e2..03d79a45e 100644 --- a/ypathgen/testdata/structs/openconfig-withlist-builder.path-txt +++ b/ypathgen/testdata/structs/openconfig-withlist-builder.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// Model returns from Device the path struct for its child "model". -func (n *Device) Model() *Model { - return &Model{ +// Model returns from DevicePath the path struct for its child "model". +func (n *DevicePath) Model() *ModelPath { + return &ModelPath{ NodePath: ygot.NewNodePath( []string{"model"}, map[string]interface{}{}, @@ -36,19 +35,19 @@ func (n *Device) Model() *Model { } } -// Model represents the /openconfig-withlist/model YANG schema element. -type Model struct { +// ModelPath represents the /openconfig-withlist/model YANG schema element. +type ModelPath struct { *ygot.NodePath } -// ModelAny represents the wildcard version of the /openconfig-withlist/model YANG schema element. -type ModelAny struct { +// ModelPathAny represents the wildcard version of the /openconfig-withlist/model YANG schema element. +type ModelPathAny struct { *ygot.NodePath } -// MultiKeyAny returns from Model the path struct for its child "multi-key". -func (n *Model) MultiKeyAny() *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKeyAny returns from ModelPath the path struct for its child "multi-key". +func (n *ModelPath) MultiKeyAny() *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": "*", "key2": "*"}, @@ -57,9 +56,9 @@ func (n *Model) MultiKeyAny() *Model_MultiKeyAny { } } -// MultiKeyAny returns from ModelAny the path struct for its child "multi-key". -func (n *ModelAny) MultiKeyAny() *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKeyAny returns from ModelPathAny the path struct for its child "multi-key". +func (n *ModelPathAny) MultiKeyAny() *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": "*", "key2": "*"}, @@ -68,21 +67,21 @@ func (n *ModelAny) MultiKeyAny() *Model_MultiKeyAny { } } -// WithKey1 sets Model_MultiKeyAny's key "key1" to the specified value. -func (n *Model_MultiKeyAny) WithKey1(Key1 uint32) *Model_MultiKeyAny { +// WithKey1 sets Model_MultiKeyPathAny's key "key1" to the specified value. +func (n *Model_MultiKeyPathAny) WithKey1(Key1 uint32) *Model_MultiKeyPathAny { ygot.ModifyKey(n.NodePath, "key1", Key1) return n } -// WithKey2 sets Model_MultiKeyAny's key "key2" to the specified value. -func (n *Model_MultiKeyAny) WithKey2(Key2 uint64) *Model_MultiKeyAny { +// WithKey2 sets Model_MultiKeyPathAny's key "key2" to the specified value. +func (n *Model_MultiKeyPathAny) WithKey2(Key2 uint64) *Model_MultiKeyPathAny { ygot.ModifyKey(n.NodePath, "key2", Key2) return n } -// SingleKeyAny returns from Model the path struct for its child "single-key". -func (n *Model) SingleKeyAny() *Model_SingleKeyAny { - return &Model_SingleKeyAny{ +// SingleKeyAny returns from ModelPath the path struct for its child "single-key". +func (n *ModelPath) SingleKeyAny() *Model_SingleKeyPathAny { + return &Model_SingleKeyPathAny{ NodePath: ygot.NewNodePath( []string{"a", "single-key"}, map[string]interface{}{"key": "*"}, @@ -91,9 +90,9 @@ func (n *Model) SingleKeyAny() *Model_SingleKeyAny { } } -// SingleKeyAny returns from ModelAny the path struct for its child "single-key". -func (n *ModelAny) SingleKeyAny() *Model_SingleKeyAny { - return &Model_SingleKeyAny{ +// SingleKeyAny returns from ModelPathAny the path struct for its child "single-key". +func (n *ModelPathAny) SingleKeyAny() *Model_SingleKeyPathAny { + return &Model_SingleKeyPathAny{ NodePath: ygot.NewNodePath( []string{"a", "single-key"}, map[string]interface{}{"key": "*"}, @@ -102,9 +101,9 @@ func (n *ModelAny) SingleKeyAny() *Model_SingleKeyAny { } } -// SingleKey returns from Model the path struct for its child "single-key". -func (n *Model) SingleKey(Key string) *Model_SingleKey { - return &Model_SingleKey{ +// SingleKey returns from ModelPath the path struct for its child "single-key". +func (n *ModelPath) SingleKey(Key string) *Model_SingleKeyPath { + return &Model_SingleKeyPath{ NodePath: ygot.NewNodePath( []string{"a", "single-key"}, map[string]interface{}{"key": Key}, @@ -113,9 +112,9 @@ func (n *Model) SingleKey(Key string) *Model_SingleKey { } } -// SingleKey returns from ModelAny the path struct for its child "single-key". -func (n *ModelAny) SingleKey(Key string) *Model_SingleKeyAny { - return &Model_SingleKeyAny{ +// SingleKey returns from ModelPathAny the path struct for its child "single-key". +func (n *ModelPathAny) SingleKey(Key string) *Model_SingleKeyPathAny { + return &Model_SingleKeyPathAny{ NodePath: ygot.NewNodePath( []string{"a", "single-key"}, map[string]interface{}{"key": Key}, @@ -124,39 +123,39 @@ func (n *ModelAny) SingleKey(Key string) *Model_SingleKeyAny { } } -// Model_MultiKey represents the /openconfig-withlist/model/b/multi-key YANG schema element. -type Model_MultiKey struct { +// Model_MultiKeyPath represents the /openconfig-withlist/model/b/multi-key YANG schema element. +type Model_MultiKeyPath struct { *ygot.NodePath } -// Model_MultiKeyAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key YANG schema element. -type Model_MultiKeyAny struct { +// Model_MultiKeyPathAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key YANG schema element. +type Model_MultiKeyPathAny struct { *ygot.NodePath } -// Model_MultiKey_Key1 represents the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. -type Model_MultiKey_Key1 struct { +// Model_MultiKey_Key1Path represents the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. +type Model_MultiKey_Key1Path struct { *ygot.NodePath } -// Model_MultiKey_Key1Any represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. -type Model_MultiKey_Key1Any struct { +// Model_MultiKey_Key1PathAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. +type Model_MultiKey_Key1PathAny struct { *ygot.NodePath } -// Model_MultiKey_Key2 represents the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. -type Model_MultiKey_Key2 struct { +// Model_MultiKey_Key2Path represents the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. +type Model_MultiKey_Key2Path struct { *ygot.NodePath } -// Model_MultiKey_Key2Any represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. -type Model_MultiKey_Key2Any struct { +// Model_MultiKey_Key2PathAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. +type Model_MultiKey_Key2PathAny struct { *ygot.NodePath } -// Key1 returns from Model_MultiKey the path struct for its child "key1". -func (n *Model_MultiKey) Key1() *Model_MultiKey_Key1 { - return &Model_MultiKey_Key1{ +// Key1 returns from Model_MultiKeyPath the path struct for its child "key1". +func (n *Model_MultiKeyPath) Key1() *Model_MultiKey_Key1Path { + return &Model_MultiKey_Key1Path{ NodePath: ygot.NewNodePath( []string{"state", "key1"}, map[string]interface{}{}, @@ -165,9 +164,9 @@ func (n *Model_MultiKey) Key1() *Model_MultiKey_Key1 { } } -// Key1 returns from Model_MultiKeyAny the path struct for its child "key1". -func (n *Model_MultiKeyAny) Key1() *Model_MultiKey_Key1Any { - return &Model_MultiKey_Key1Any{ +// Key1 returns from Model_MultiKeyPathAny the path struct for its child "key1". +func (n *Model_MultiKeyPathAny) Key1() *Model_MultiKey_Key1PathAny { + return &Model_MultiKey_Key1PathAny{ NodePath: ygot.NewNodePath( []string{"state", "key1"}, map[string]interface{}{}, @@ -176,9 +175,9 @@ func (n *Model_MultiKeyAny) Key1() *Model_MultiKey_Key1Any { } } -// Key2 returns from Model_MultiKey the path struct for its child "key2". -func (n *Model_MultiKey) Key2() *Model_MultiKey_Key2 { - return &Model_MultiKey_Key2{ +// Key2 returns from Model_MultiKeyPath the path struct for its child "key2". +func (n *Model_MultiKeyPath) Key2() *Model_MultiKey_Key2Path { + return &Model_MultiKey_Key2Path{ NodePath: ygot.NewNodePath( []string{"state", "key2"}, map[string]interface{}{}, @@ -187,9 +186,9 @@ func (n *Model_MultiKey) Key2() *Model_MultiKey_Key2 { } } -// Key2 returns from Model_MultiKeyAny the path struct for its child "key2". -func (n *Model_MultiKeyAny) Key2() *Model_MultiKey_Key2Any { - return &Model_MultiKey_Key2Any{ +// Key2 returns from Model_MultiKeyPathAny the path struct for its child "key2". +func (n *Model_MultiKeyPathAny) Key2() *Model_MultiKey_Key2PathAny { + return &Model_MultiKey_Key2PathAny{ NodePath: ygot.NewNodePath( []string{"state", "key2"}, map[string]interface{}{}, @@ -198,29 +197,29 @@ func (n *Model_MultiKeyAny) Key2() *Model_MultiKey_Key2Any { } } -// Model_SingleKey represents the /openconfig-withlist/model/a/single-key YANG schema element. -type Model_SingleKey struct { +// Model_SingleKeyPath represents the /openconfig-withlist/model/a/single-key YANG schema element. +type Model_SingleKeyPath struct { *ygot.NodePath } -// Model_SingleKeyAny represents the wildcard version of the /openconfig-withlist/model/a/single-key YANG schema element. -type Model_SingleKeyAny struct { +// Model_SingleKeyPathAny represents the wildcard version of the /openconfig-withlist/model/a/single-key YANG schema element. +type Model_SingleKeyPathAny struct { *ygot.NodePath } -// Model_SingleKey_Key represents the /openconfig-withlist/model/a/single-key/state/key YANG schema element. -type Model_SingleKey_Key struct { +// Model_SingleKey_KeyPath represents the /openconfig-withlist/model/a/single-key/state/key YANG schema element. +type Model_SingleKey_KeyPath struct { *ygot.NodePath } -// Model_SingleKey_KeyAny represents the wildcard version of the /openconfig-withlist/model/a/single-key/state/key YANG schema element. -type Model_SingleKey_KeyAny struct { +// Model_SingleKey_KeyPathAny represents the wildcard version of the /openconfig-withlist/model/a/single-key/state/key YANG schema element. +type Model_SingleKey_KeyPathAny struct { *ygot.NodePath } -// Key returns from Model_SingleKey the path struct for its child "key". -func (n *Model_SingleKey) Key() *Model_SingleKey_Key { - return &Model_SingleKey_Key{ +// Key returns from Model_SingleKeyPath the path struct for its child "key". +func (n *Model_SingleKeyPath) Key() *Model_SingleKey_KeyPath { + return &Model_SingleKey_KeyPath{ NodePath: ygot.NewNodePath( []string{"state", "key"}, map[string]interface{}{}, @@ -229,9 +228,9 @@ func (n *Model_SingleKey) Key() *Model_SingleKey_Key { } } -// Key returns from Model_SingleKeyAny the path struct for its child "key". -func (n *Model_SingleKeyAny) Key() *Model_SingleKey_KeyAny { - return &Model_SingleKey_KeyAny{ +// Key returns from Model_SingleKeyPathAny the path struct for its child "key". +func (n *Model_SingleKeyPathAny) Key() *Model_SingleKey_KeyPathAny { + return &Model_SingleKey_KeyPathAny{ NodePath: ygot.NewNodePath( []string{"state", "key"}, map[string]interface{}{}, diff --git a/ypathgen/testdata/structs/openconfig-withlist-separate-package.path-txt b/ypathgen/testdata/structs/openconfig-withlist-separate-package.path-txt new file mode 100644 index 000000000..eff5c2adb --- /dev/null +++ b/ypathgen/testdata/structs/openconfig-withlist-separate-package.path-txt @@ -0,0 +1,295 @@ +/* +Package ocpathstructs is a generated package which contains definitions +of structs which generate gNMI paths for a YANG schema. The generated paths are +based on a compressed form of the schema. + +This package was generated by pathgen-tests +using the following YANG input files: + - ../testdata/modules/openconfig-withlist.yang +Imported modules were sourced from: +*/ +package ocpathstructs + +import ( + oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" + "github.com/openconfig/ygot/ygot" +) + +// Device represents the /device YANG schema element. +type Device struct { + *ygot.DeviceRootBase +} + +// DeviceRoot returns a new path object from which YANG paths can be constructed. +func DeviceRoot(id string) *Device { + return &Device{ygot.NewDeviceRootBase(id)} +} + +// Model returns from Device the path struct for its child "model". +func (n *Device) Model() *Model { + return &Model{ + NodePath: ygot.NewNodePath( + []string{"model"}, + map[string]interface{}{}, + n, + ), + } +} + +// Model represents the /openconfig-withlist/model YANG schema element. +type Model struct { + *ygot.NodePath +} + +// ModelAny represents the wildcard version of the /openconfig-withlist/model YANG schema element. +type ModelAny struct { + *ygot.NodePath +} + +// MultiKeyAny returns from Model the path struct for its child "multi-key". +func (n *Model) MultiKeyAny() *Model_MultiKeyAny { + return &Model_MultiKeyAny{ + NodePath: ygot.NewNodePath( + []string{"b", "multi-key"}, + map[string]interface{}{"key1": "*", "key2": "*"}, + n, + ), + } +} + +// MultiKeyAny returns from ModelAny the path struct for its child "multi-key". +func (n *ModelAny) MultiKeyAny() *Model_MultiKeyAny { + return &Model_MultiKeyAny{ + NodePath: ygot.NewNodePath( + []string{"b", "multi-key"}, + map[string]interface{}{"key1": "*", "key2": "*"}, + n, + ), + } +} + +// MultiKeyAnyKey2 returns from Model the path struct for its child "multi-key". +func (n *Model) MultiKeyAnyKey2(Key1 uint32) *Model_MultiKeyAny { + return &Model_MultiKeyAny{ + NodePath: ygot.NewNodePath( + []string{"b", "multi-key"}, + map[string]interface{}{"key1": Key1, "key2": "*"}, + n, + ), + } +} + +// MultiKeyAnyKey2 returns from ModelAny the path struct for its child "multi-key". +func (n *ModelAny) MultiKeyAnyKey2(Key1 uint32) *Model_MultiKeyAny { + return &Model_MultiKeyAny{ + NodePath: ygot.NewNodePath( + []string{"b", "multi-key"}, + map[string]interface{}{"key1": Key1, "key2": "*"}, + n, + ), + } +} + +// MultiKeyAnyKey1 returns from Model the path struct for its child "multi-key". +func (n *Model) MultiKeyAnyKey1(Key2 uint64) *Model_MultiKeyAny { + return &Model_MultiKeyAny{ + NodePath: ygot.NewNodePath( + []string{"b", "multi-key"}, + map[string]interface{}{"key1": "*", "key2": Key2}, + n, + ), + } +} + +// MultiKeyAnyKey1 returns from ModelAny the path struct for its child "multi-key". +func (n *ModelAny) MultiKeyAnyKey1(Key2 uint64) *Model_MultiKeyAny { + return &Model_MultiKeyAny{ + NodePath: ygot.NewNodePath( + []string{"b", "multi-key"}, + map[string]interface{}{"key1": "*", "key2": Key2}, + n, + ), + } +} + +// MultiKey returns from Model the path struct for its child "multi-key". +func (n *Model) MultiKey(Key1 uint32, Key2 uint64) *Model_MultiKey { + return &Model_MultiKey{ + NodePath: ygot.NewNodePath( + []string{"b", "multi-key"}, + map[string]interface{}{"key1": Key1, "key2": Key2}, + n, + ), + } +} + +// MultiKey returns from ModelAny the path struct for its child "multi-key". +func (n *ModelAny) MultiKey(Key1 uint32, Key2 uint64) *Model_MultiKeyAny { + return &Model_MultiKeyAny{ + NodePath: ygot.NewNodePath( + []string{"b", "multi-key"}, + map[string]interface{}{"key1": Key1, "key2": Key2}, + n, + ), + } +} + +// SingleKeyAny returns from Model the path struct for its child "single-key". +func (n *Model) SingleKeyAny() *Model_SingleKeyAny { + return &Model_SingleKeyAny{ + NodePath: ygot.NewNodePath( + []string{"a", "single-key"}, + map[string]interface{}{"key": "*"}, + n, + ), + } +} + +// SingleKeyAny returns from ModelAny the path struct for its child "single-key". +func (n *ModelAny) SingleKeyAny() *Model_SingleKeyAny { + return &Model_SingleKeyAny{ + NodePath: ygot.NewNodePath( + []string{"a", "single-key"}, + map[string]interface{}{"key": "*"}, + n, + ), + } +} + +// SingleKey returns from Model the path struct for its child "single-key". +func (n *Model) SingleKey(Key string) *Model_SingleKey { + return &Model_SingleKey{ + NodePath: ygot.NewNodePath( + []string{"a", "single-key"}, + map[string]interface{}{"key": Key}, + n, + ), + } +} + +// SingleKey returns from ModelAny the path struct for its child "single-key". +func (n *ModelAny) SingleKey(Key string) *Model_SingleKeyAny { + return &Model_SingleKeyAny{ + NodePath: ygot.NewNodePath( + []string{"a", "single-key"}, + map[string]interface{}{"key": Key}, + n, + ), + } +} + +// Model_MultiKey represents the /openconfig-withlist/model/b/multi-key YANG schema element. +type Model_MultiKey struct { + *ygot.NodePath +} + +// Model_MultiKeyAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key YANG schema element. +type Model_MultiKeyAny struct { + *ygot.NodePath +} + +// Model_MultiKey_Key1 represents the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. +type Model_MultiKey_Key1 struct { + *ygot.NodePath +} + +// Model_MultiKey_Key1Any represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. +type Model_MultiKey_Key1Any struct { + *ygot.NodePath +} + +// Model_MultiKey_Key2 represents the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. +type Model_MultiKey_Key2 struct { + *ygot.NodePath +} + +// Model_MultiKey_Key2Any represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. +type Model_MultiKey_Key2Any struct { + *ygot.NodePath +} + +// Key1 returns from Model_MultiKey the path struct for its child "key1". +func (n *Model_MultiKey) Key1() *Model_MultiKey_Key1 { + return &Model_MultiKey_Key1{ + NodePath: ygot.NewNodePath( + []string{"state", "key1"}, + map[string]interface{}{}, + n, + ), + } +} + +// Key1 returns from Model_MultiKeyAny the path struct for its child "key1". +func (n *Model_MultiKeyAny) Key1() *Model_MultiKey_Key1Any { + return &Model_MultiKey_Key1Any{ + NodePath: ygot.NewNodePath( + []string{"state", "key1"}, + map[string]interface{}{}, + n, + ), + } +} + +// Key2 returns from Model_MultiKey the path struct for its child "key2". +func (n *Model_MultiKey) Key2() *Model_MultiKey_Key2 { + return &Model_MultiKey_Key2{ + NodePath: ygot.NewNodePath( + []string{"state", "key2"}, + map[string]interface{}{}, + n, + ), + } +} + +// Key2 returns from Model_MultiKeyAny the path struct for its child "key2". +func (n *Model_MultiKeyAny) Key2() *Model_MultiKey_Key2Any { + return &Model_MultiKey_Key2Any{ + NodePath: ygot.NewNodePath( + []string{"state", "key2"}, + map[string]interface{}{}, + n, + ), + } +} + +// Model_SingleKey represents the /openconfig-withlist/model/a/single-key YANG schema element. +type Model_SingleKey struct { + *ygot.NodePath +} + +// Model_SingleKeyAny represents the wildcard version of the /openconfig-withlist/model/a/single-key YANG schema element. +type Model_SingleKeyAny struct { + *ygot.NodePath +} + +// Model_SingleKey_Key represents the /openconfig-withlist/model/a/single-key/state/key YANG schema element. +type Model_SingleKey_Key struct { + *ygot.NodePath +} + +// Model_SingleKey_KeyAny represents the wildcard version of the /openconfig-withlist/model/a/single-key/state/key YANG schema element. +type Model_SingleKey_KeyAny struct { + *ygot.NodePath +} + +// Key returns from Model_SingleKey the path struct for its child "key". +func (n *Model_SingleKey) Key() *Model_SingleKey_Key { + return &Model_SingleKey_Key{ + NodePath: ygot.NewNodePath( + []string{"state", "key"}, + map[string]interface{}{}, + n, + ), + } +} + +// Key returns from Model_SingleKeyAny the path struct for its child "key". +func (n *Model_SingleKeyAny) Key() *Model_SingleKey_KeyAny { + return &Model_SingleKey_KeyAny{ + NodePath: ygot.NewNodePath( + []string{"state", "key"}, + map[string]interface{}{}, + n, + ), + } +} diff --git a/ypathgen/testdata/structs/openconfig-withlist.path-txt b/ypathgen/testdata/structs/openconfig-withlist.path-txt index eff5c2adb..6e2092070 100644 --- a/ypathgen/testdata/structs/openconfig-withlist.path-txt +++ b/ypathgen/testdata/structs/openconfig-withlist.path-txt @@ -11,23 +11,22 @@ Imported modules were sourced from: package ocpathstructs import ( - oc "github.com/openconfig/ygot/ypathgen/testdata/exampleoc" "github.com/openconfig/ygot/ygot" ) -// Device represents the /device YANG schema element. -type Device struct { +// DevicePath represents the /device YANG schema element. +type DevicePath struct { *ygot.DeviceRootBase } // DeviceRoot returns a new path object from which YANG paths can be constructed. -func DeviceRoot(id string) *Device { - return &Device{ygot.NewDeviceRootBase(id)} +func DeviceRoot(id string) *DevicePath { + return &DevicePath{ygot.NewDeviceRootBase(id)} } -// Model returns from Device the path struct for its child "model". -func (n *Device) Model() *Model { - return &Model{ +// Model returns from DevicePath the path struct for its child "model". +func (n *DevicePath) Model() *ModelPath { + return &ModelPath{ NodePath: ygot.NewNodePath( []string{"model"}, map[string]interface{}{}, @@ -36,19 +35,19 @@ func (n *Device) Model() *Model { } } -// Model represents the /openconfig-withlist/model YANG schema element. -type Model struct { +// ModelPath represents the /openconfig-withlist/model YANG schema element. +type ModelPath struct { *ygot.NodePath } -// ModelAny represents the wildcard version of the /openconfig-withlist/model YANG schema element. -type ModelAny struct { +// ModelPathAny represents the wildcard version of the /openconfig-withlist/model YANG schema element. +type ModelPathAny struct { *ygot.NodePath } -// MultiKeyAny returns from Model the path struct for its child "multi-key". -func (n *Model) MultiKeyAny() *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKeyAny returns from ModelPath the path struct for its child "multi-key". +func (n *ModelPath) MultiKeyAny() *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": "*", "key2": "*"}, @@ -57,9 +56,9 @@ func (n *Model) MultiKeyAny() *Model_MultiKeyAny { } } -// MultiKeyAny returns from ModelAny the path struct for its child "multi-key". -func (n *ModelAny) MultiKeyAny() *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKeyAny returns from ModelPathAny the path struct for its child "multi-key". +func (n *ModelPathAny) MultiKeyAny() *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": "*", "key2": "*"}, @@ -68,9 +67,9 @@ func (n *ModelAny) MultiKeyAny() *Model_MultiKeyAny { } } -// MultiKeyAnyKey2 returns from Model the path struct for its child "multi-key". -func (n *Model) MultiKeyAnyKey2(Key1 uint32) *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKeyAnyKey2 returns from ModelPath the path struct for its child "multi-key". +func (n *ModelPath) MultiKeyAnyKey2(Key1 uint32) *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": Key1, "key2": "*"}, @@ -79,9 +78,9 @@ func (n *Model) MultiKeyAnyKey2(Key1 uint32) *Model_MultiKeyAny { } } -// MultiKeyAnyKey2 returns from ModelAny the path struct for its child "multi-key". -func (n *ModelAny) MultiKeyAnyKey2(Key1 uint32) *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKeyAnyKey2 returns from ModelPathAny the path struct for its child "multi-key". +func (n *ModelPathAny) MultiKeyAnyKey2(Key1 uint32) *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": Key1, "key2": "*"}, @@ -90,9 +89,9 @@ func (n *ModelAny) MultiKeyAnyKey2(Key1 uint32) *Model_MultiKeyAny { } } -// MultiKeyAnyKey1 returns from Model the path struct for its child "multi-key". -func (n *Model) MultiKeyAnyKey1(Key2 uint64) *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKeyAnyKey1 returns from ModelPath the path struct for its child "multi-key". +func (n *ModelPath) MultiKeyAnyKey1(Key2 uint64) *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": "*", "key2": Key2}, @@ -101,9 +100,9 @@ func (n *Model) MultiKeyAnyKey1(Key2 uint64) *Model_MultiKeyAny { } } -// MultiKeyAnyKey1 returns from ModelAny the path struct for its child "multi-key". -func (n *ModelAny) MultiKeyAnyKey1(Key2 uint64) *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKeyAnyKey1 returns from ModelPathAny the path struct for its child "multi-key". +func (n *ModelPathAny) MultiKeyAnyKey1(Key2 uint64) *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": "*", "key2": Key2}, @@ -112,9 +111,9 @@ func (n *ModelAny) MultiKeyAnyKey1(Key2 uint64) *Model_MultiKeyAny { } } -// MultiKey returns from Model the path struct for its child "multi-key". -func (n *Model) MultiKey(Key1 uint32, Key2 uint64) *Model_MultiKey { - return &Model_MultiKey{ +// MultiKey returns from ModelPath the path struct for its child "multi-key". +func (n *ModelPath) MultiKey(Key1 uint32, Key2 uint64) *Model_MultiKeyPath { + return &Model_MultiKeyPath{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": Key1, "key2": Key2}, @@ -123,9 +122,9 @@ func (n *Model) MultiKey(Key1 uint32, Key2 uint64) *Model_MultiKey { } } -// MultiKey returns from ModelAny the path struct for its child "multi-key". -func (n *ModelAny) MultiKey(Key1 uint32, Key2 uint64) *Model_MultiKeyAny { - return &Model_MultiKeyAny{ +// MultiKey returns from ModelPathAny the path struct for its child "multi-key". +func (n *ModelPathAny) MultiKey(Key1 uint32, Key2 uint64) *Model_MultiKeyPathAny { + return &Model_MultiKeyPathAny{ NodePath: ygot.NewNodePath( []string{"b", "multi-key"}, map[string]interface{}{"key1": Key1, "key2": Key2}, @@ -134,9 +133,9 @@ func (n *ModelAny) MultiKey(Key1 uint32, Key2 uint64) *Model_MultiKeyAny { } } -// SingleKeyAny returns from Model the path struct for its child "single-key". -func (n *Model) SingleKeyAny() *Model_SingleKeyAny { - return &Model_SingleKeyAny{ +// SingleKeyAny returns from ModelPath the path struct for its child "single-key". +func (n *ModelPath) SingleKeyAny() *Model_SingleKeyPathAny { + return &Model_SingleKeyPathAny{ NodePath: ygot.NewNodePath( []string{"a", "single-key"}, map[string]interface{}{"key": "*"}, @@ -145,9 +144,9 @@ func (n *Model) SingleKeyAny() *Model_SingleKeyAny { } } -// SingleKeyAny returns from ModelAny the path struct for its child "single-key". -func (n *ModelAny) SingleKeyAny() *Model_SingleKeyAny { - return &Model_SingleKeyAny{ +// SingleKeyAny returns from ModelPathAny the path struct for its child "single-key". +func (n *ModelPathAny) SingleKeyAny() *Model_SingleKeyPathAny { + return &Model_SingleKeyPathAny{ NodePath: ygot.NewNodePath( []string{"a", "single-key"}, map[string]interface{}{"key": "*"}, @@ -156,9 +155,9 @@ func (n *ModelAny) SingleKeyAny() *Model_SingleKeyAny { } } -// SingleKey returns from Model the path struct for its child "single-key". -func (n *Model) SingleKey(Key string) *Model_SingleKey { - return &Model_SingleKey{ +// SingleKey returns from ModelPath the path struct for its child "single-key". +func (n *ModelPath) SingleKey(Key string) *Model_SingleKeyPath { + return &Model_SingleKeyPath{ NodePath: ygot.NewNodePath( []string{"a", "single-key"}, map[string]interface{}{"key": Key}, @@ -167,9 +166,9 @@ func (n *Model) SingleKey(Key string) *Model_SingleKey { } } -// SingleKey returns from ModelAny the path struct for its child "single-key". -func (n *ModelAny) SingleKey(Key string) *Model_SingleKeyAny { - return &Model_SingleKeyAny{ +// SingleKey returns from ModelPathAny the path struct for its child "single-key". +func (n *ModelPathAny) SingleKey(Key string) *Model_SingleKeyPathAny { + return &Model_SingleKeyPathAny{ NodePath: ygot.NewNodePath( []string{"a", "single-key"}, map[string]interface{}{"key": Key}, @@ -178,39 +177,39 @@ func (n *ModelAny) SingleKey(Key string) *Model_SingleKeyAny { } } -// Model_MultiKey represents the /openconfig-withlist/model/b/multi-key YANG schema element. -type Model_MultiKey struct { +// Model_MultiKeyPath represents the /openconfig-withlist/model/b/multi-key YANG schema element. +type Model_MultiKeyPath struct { *ygot.NodePath } -// Model_MultiKeyAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key YANG schema element. -type Model_MultiKeyAny struct { +// Model_MultiKeyPathAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key YANG schema element. +type Model_MultiKeyPathAny struct { *ygot.NodePath } -// Model_MultiKey_Key1 represents the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. -type Model_MultiKey_Key1 struct { +// Model_MultiKey_Key1Path represents the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. +type Model_MultiKey_Key1Path struct { *ygot.NodePath } -// Model_MultiKey_Key1Any represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. -type Model_MultiKey_Key1Any struct { +// Model_MultiKey_Key1PathAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key1 YANG schema element. +type Model_MultiKey_Key1PathAny struct { *ygot.NodePath } -// Model_MultiKey_Key2 represents the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. -type Model_MultiKey_Key2 struct { +// Model_MultiKey_Key2Path represents the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. +type Model_MultiKey_Key2Path struct { *ygot.NodePath } -// Model_MultiKey_Key2Any represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. -type Model_MultiKey_Key2Any struct { +// Model_MultiKey_Key2PathAny represents the wildcard version of the /openconfig-withlist/model/b/multi-key/state/key2 YANG schema element. +type Model_MultiKey_Key2PathAny struct { *ygot.NodePath } -// Key1 returns from Model_MultiKey the path struct for its child "key1". -func (n *Model_MultiKey) Key1() *Model_MultiKey_Key1 { - return &Model_MultiKey_Key1{ +// Key1 returns from Model_MultiKeyPath the path struct for its child "key1". +func (n *Model_MultiKeyPath) Key1() *Model_MultiKey_Key1Path { + return &Model_MultiKey_Key1Path{ NodePath: ygot.NewNodePath( []string{"state", "key1"}, map[string]interface{}{}, @@ -219,9 +218,9 @@ func (n *Model_MultiKey) Key1() *Model_MultiKey_Key1 { } } -// Key1 returns from Model_MultiKeyAny the path struct for its child "key1". -func (n *Model_MultiKeyAny) Key1() *Model_MultiKey_Key1Any { - return &Model_MultiKey_Key1Any{ +// Key1 returns from Model_MultiKeyPathAny the path struct for its child "key1". +func (n *Model_MultiKeyPathAny) Key1() *Model_MultiKey_Key1PathAny { + return &Model_MultiKey_Key1PathAny{ NodePath: ygot.NewNodePath( []string{"state", "key1"}, map[string]interface{}{}, @@ -230,9 +229,9 @@ func (n *Model_MultiKeyAny) Key1() *Model_MultiKey_Key1Any { } } -// Key2 returns from Model_MultiKey the path struct for its child "key2". -func (n *Model_MultiKey) Key2() *Model_MultiKey_Key2 { - return &Model_MultiKey_Key2{ +// Key2 returns from Model_MultiKeyPath the path struct for its child "key2". +func (n *Model_MultiKeyPath) Key2() *Model_MultiKey_Key2Path { + return &Model_MultiKey_Key2Path{ NodePath: ygot.NewNodePath( []string{"state", "key2"}, map[string]interface{}{}, @@ -241,9 +240,9 @@ func (n *Model_MultiKey) Key2() *Model_MultiKey_Key2 { } } -// Key2 returns from Model_MultiKeyAny the path struct for its child "key2". -func (n *Model_MultiKeyAny) Key2() *Model_MultiKey_Key2Any { - return &Model_MultiKey_Key2Any{ +// Key2 returns from Model_MultiKeyPathAny the path struct for its child "key2". +func (n *Model_MultiKeyPathAny) Key2() *Model_MultiKey_Key2PathAny { + return &Model_MultiKey_Key2PathAny{ NodePath: ygot.NewNodePath( []string{"state", "key2"}, map[string]interface{}{}, @@ -252,29 +251,29 @@ func (n *Model_MultiKeyAny) Key2() *Model_MultiKey_Key2Any { } } -// Model_SingleKey represents the /openconfig-withlist/model/a/single-key YANG schema element. -type Model_SingleKey struct { +// Model_SingleKeyPath represents the /openconfig-withlist/model/a/single-key YANG schema element. +type Model_SingleKeyPath struct { *ygot.NodePath } -// Model_SingleKeyAny represents the wildcard version of the /openconfig-withlist/model/a/single-key YANG schema element. -type Model_SingleKeyAny struct { +// Model_SingleKeyPathAny represents the wildcard version of the /openconfig-withlist/model/a/single-key YANG schema element. +type Model_SingleKeyPathAny struct { *ygot.NodePath } -// Model_SingleKey_Key represents the /openconfig-withlist/model/a/single-key/state/key YANG schema element. -type Model_SingleKey_Key struct { +// Model_SingleKey_KeyPath represents the /openconfig-withlist/model/a/single-key/state/key YANG schema element. +type Model_SingleKey_KeyPath struct { *ygot.NodePath } -// Model_SingleKey_KeyAny represents the wildcard version of the /openconfig-withlist/model/a/single-key/state/key YANG schema element. -type Model_SingleKey_KeyAny struct { +// Model_SingleKey_KeyPathAny represents the wildcard version of the /openconfig-withlist/model/a/single-key/state/key YANG schema element. +type Model_SingleKey_KeyPathAny struct { *ygot.NodePath } -// Key returns from Model_SingleKey the path struct for its child "key". -func (n *Model_SingleKey) Key() *Model_SingleKey_Key { - return &Model_SingleKey_Key{ +// Key returns from Model_SingleKeyPath the path struct for its child "key". +func (n *Model_SingleKeyPath) Key() *Model_SingleKey_KeyPath { + return &Model_SingleKey_KeyPath{ NodePath: ygot.NewNodePath( []string{"state", "key"}, map[string]interface{}{}, @@ -283,9 +282,9 @@ func (n *Model_SingleKey) Key() *Model_SingleKey_Key { } } -// Key returns from Model_SingleKeyAny the path struct for its child "key". -func (n *Model_SingleKeyAny) Key() *Model_SingleKey_KeyAny { - return &Model_SingleKey_KeyAny{ +// Key returns from Model_SingleKeyPathAny the path struct for its child "key". +func (n *Model_SingleKeyPathAny) Key() *Model_SingleKey_KeyPathAny { + return &Model_SingleKey_KeyPathAny{ NodePath: ygot.NewNodePath( []string{"state", "key"}, map[string]interface{}{},