From 4ae6e20112b610648f983f57d178d066f7bd97eb Mon Sep 17 00:00:00 2001 From: Siva Sivakumar Date: Tue, 25 Jun 2024 22:51:49 +0200 Subject: [PATCH 1/4] support for rpc & action - draft1 --- pkg/app/path.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pkg/app/path.go b/pkg/app/path.go index b606e3bb..514ec573 100644 --- a/pkg/app/path.go +++ b/pkg/app/path.go @@ -47,6 +47,8 @@ type generatedPath struct { IsState bool `json:"is-state,omitempty"` Namespace string `json:"namespace,omitempty"` FeatureList []string `json:"if-features,omitempty"` + Rpc bool `json:"rpc,omitempty"` + Action bool `json:"action,omitempty"` } func (a *App) PathCmdRun(d, f, e []string, pgo pathGenOpts) error { @@ -234,6 +236,25 @@ func collectSchemaNodes(e *yang.Entry, leafOnly bool) []*yang.Entry { collectSchemaNodes(child, leafOnly)...) } + // Support for RPC & Action + if e.RPC != nil { + kind := e.Node.Kind() + if e.RPC.Input != nil { + if e.RPC.Input.Extra == nil { + e.RPC.Input.Extra = make(map[string][]interface{}) + } + e.RPC.Input.Extra[kind] = []interface{}{true} + collected = append(collected, collectSchemaNodes(e.RPC.Input, leafOnly)...) + } + if e.RPC.Output != nil { + if e.RPC.Output.Extra == nil { + e.RPC.Output.Extra = make(map[string][]interface{}) + } + e.RPC.Output.Extra[kind] = []interface{}{true} + collected = append(collected, collectSchemaNodes(e.RPC.Output, leafOnly)...) + } + } + if e.Parent != nil { switch { case e.Dir == nil && e.ListAttr != nil: // leaf-list @@ -291,6 +312,23 @@ func collectSchemaNodes(e *yang.Entry, leafOnly bool) []*yang.Entry { } } } + + // Support for RPC + if len(e.Extra["rpc"]) > 0 { + for _, myleaf := range collected { + if myleaf.Extra["rpc"] == nil { + myleaf.Extra["rpc"] = e.Extra["rpc"] + } + } + } + // Support for Action + if len(e.Extra["action"]) > 0 { + for _, myleaf := range collected { + if myleaf.Extra["action"] == nil { + myleaf.Extra["action"] = e.Extra["action"] + } + } + } } } return collected @@ -334,6 +372,15 @@ func (a *App) generatePath(entry *yang.Entry, pType string) *generatedPath { } } + // Support for RPC + if len(entry.Extra["rpc"]) == 1 { + gp.Rpc = true + } + // Support for Action + if len(entry.Extra["action"]) == 1 { + gp.Action = true + } + gp.Description = entry.Description if entry.Type != nil { gp.Type = entry.Type.Name From a8c14f6515f9532ff1d12e5249cb3b1b0e1a52cc Mon Sep 17 00:00:00 2001 From: Siva Sivakumar Date: Wed, 26 Jun 2024 09:58:30 +0200 Subject: [PATCH 2/4] support for notification --- pkg/app/path.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/app/path.go b/pkg/app/path.go index 514ec573..13282635 100644 --- a/pkg/app/path.go +++ b/pkg/app/path.go @@ -49,6 +49,7 @@ type generatedPath struct { FeatureList []string `json:"if-features,omitempty"` Rpc bool `json:"rpc,omitempty"` Action bool `json:"action,omitempty"` + Notification bool `json:"notification,omitempty"` } func (a *App) PathCmdRun(d, f, e []string, pgo pathGenOpts) error { @@ -236,6 +237,15 @@ func collectSchemaNodes(e *yang.Entry, leafOnly bool) []*yang.Entry { collectSchemaNodes(child, leafOnly)...) } + // Support for Notification + if e.Node.Kind() == "notification" { + fmt.Println(e.Name) + if e.Extra == nil { + e.Extra = make(map[string][]interface{}) + } + e.Extra["notification"] = []interface{}{true} + } + // Support for RPC & Action if e.RPC != nil { kind := e.Node.Kind() @@ -312,7 +322,14 @@ func collectSchemaNodes(e *yang.Entry, leafOnly bool) []*yang.Entry { } } } - + // Support for Notification + if len(e.Extra["notification"]) > 0 { + for _, myleaf := range collected { + if myleaf.Extra["notification"] == nil { + myleaf.Extra["notification"] = e.Extra["notification"] + } + } + } // Support for RPC if len(e.Extra["rpc"]) > 0 { for _, myleaf := range collected { @@ -372,6 +389,10 @@ func (a *App) generatePath(entry *yang.Entry, pType string) *generatedPath { } } + // Support for Notification + if len(entry.Extra["notification"]) == 1 { + gp.Notification = true + } // Support for RPC if len(entry.Extra["rpc"]) == 1 { gp.Rpc = true From 97f14243e96308aaa6ff0302a2bf5be163466b4b Mon Sep 17 00:00:00 2001 From: Siva Sivakumar Date: Wed, 26 Jun 2024 10:00:43 +0200 Subject: [PATCH 3/4] cleanup fmt.Println --- pkg/app/path.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/app/path.go b/pkg/app/path.go index 13282635..fc09a101 100644 --- a/pkg/app/path.go +++ b/pkg/app/path.go @@ -239,7 +239,6 @@ func collectSchemaNodes(e *yang.Entry, leafOnly bool) []*yang.Entry { // Support for Notification if e.Node.Kind() == "notification" { - fmt.Println(e.Name) if e.Extra == nil { e.Extra = make(map[string][]interface{}) } From d02ed905ede9306548ba9599c3d4ef006582cb0b Mon Sep 17 00:00:00 2001 From: Siva Sivakumar Date: Wed, 26 Jun 2024 19:00:19 +0200 Subject: [PATCH 4/4] isRpc isAction isNotification --- pkg/app/path.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/app/path.go b/pkg/app/path.go index fc09a101..e78a3d9e 100644 --- a/pkg/app/path.go +++ b/pkg/app/path.go @@ -47,9 +47,9 @@ type generatedPath struct { IsState bool `json:"is-state,omitempty"` Namespace string `json:"namespace,omitempty"` FeatureList []string `json:"if-features,omitempty"` - Rpc bool `json:"rpc,omitempty"` - Action bool `json:"action,omitempty"` - Notification bool `json:"notification,omitempty"` + IsNotification bool `json:"is-notification,omitempty"` + IsRpc bool `json:"is-rpc,omitempty"` + IsAction bool `json:"is-action,omitempty"` } func (a *App) PathCmdRun(d, f, e []string, pgo pathGenOpts) error { @@ -390,15 +390,15 @@ func (a *App) generatePath(entry *yang.Entry, pType string) *generatedPath { // Support for Notification if len(entry.Extra["notification"]) == 1 { - gp.Notification = true + gp.IsNotification = true } // Support for RPC if len(entry.Extra["rpc"]) == 1 { - gp.Rpc = true + gp.IsRpc = true } // Support for Action if len(entry.Extra["action"]) == 1 { - gp.Action = true + gp.IsAction = true } gp.Description = entry.Description