internal/mcp: generate method names
Augment the generator to create constants for all method names. Change-Id: I858e516b1afec0aa3cf3b9852cbdfc16aec4c553 Reviewed-on: https://go-review.googlesource.com/c/tools/+/673177 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
This commit is contained in:
parent
9bcc6c758f
commit
74340f088d
1 changed files with 66 additions and 21 deletions
|
|
@ -202,6 +202,24 @@ import (
|
|||
fmt.Fprintln(buf)
|
||||
fmt.Fprint(buf, b.String())
|
||||
}
|
||||
// Write out method names.
|
||||
fmt.Fprintln(buf, `const (`)
|
||||
for name, s := range schema.Definitions {
|
||||
prefix := "method"
|
||||
method, found := strings.CutSuffix(name, "Request")
|
||||
if !found {
|
||||
prefix = "notification"
|
||||
method, found = strings.CutSuffix(name, "Notification")
|
||||
}
|
||||
if found {
|
||||
if ms, ok := s.Properties["method"]; ok {
|
||||
if c := ms.Const; c != nil {
|
||||
fmt.Fprintf(buf, "%s%s = %q\n", prefix, method, *c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(buf, `)`)
|
||||
|
||||
formatted, err := format.Source(buf.Bytes())
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue