-
Notifications
You must be signed in to change notification settings - Fork 892
/
openrpc.go
55 lines (44 loc) · 1.25 KB
/
openrpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"context"
"encoding/json"
"os"
"github.com/spf13/cobra"
"github.com/celestiaorg/celestia-node/api/docgen"
"github.com/celestiaorg/celestia-node/nodebuilder"
)
var rootCmd = &cobra.Command{
Use: "docgen [packages]",
Short: "docgen generates the openrpc documentation for Celestia Node packages",
RunE: func(_ *cobra.Command, moduleNames []string) error {
// 1. Open the respective nodebuilder/X/service.go files for AST parsing
nodeComments, permComments := docgen.ParseCommentsFromNodebuilderModules(moduleNames...)
// 2. Create an OpenRPC document from the map of comments + hardcoded metadata
doc := docgen.NewOpenRPCDocument(nodeComments, permComments)
// 3. Register the client wrapper interface on the document
for moduleName, module := range nodebuilder.PackageToAPI {
doc.RegisterReceiverName(moduleName, module)
}
// 4. Call doc.Discover()
d, err := doc.Discover()
if err != nil {
return err
}
// 5. Print to Stdout
jsonOut, err := json.MarshalIndent(d, "", " ")
if err != nil {
return err
}
_, err = os.Stdout.Write(jsonOut)
return err
},
}
func main() {
err := run()
if err != nil {
os.Exit(1)
}
}
func run() error {
return rootCmd.ExecuteContext(context.Background())
}