diff --git a/Makefile b/Makefile index 000d01fa02..32f2a640f4 100644 --- a/Makefile +++ b/Makefile @@ -176,7 +176,7 @@ pb-gen: ## openrpc-gen: Generate OpenRPC spec for Celestia-Node's RPC api openrpc-gen: @echo "--> Generating OpenRPC spec" - @go run ./cmd/docgen fraud header state share das p2p node blob da + @go run ${LDFLAGS} ./cmd/celestia docgen .PHONY: openrpc-gen ## lint-imports: Lint only Go imports. diff --git a/cmd/docgen/openrpc.go b/cmd/celestia/docgen.go similarity index 50% rename from cmd/docgen/openrpc.go rename to cmd/celestia/docgen.go index ef8b706ec5..ae7ea79d01 100644 --- a/cmd/docgen/openrpc.go +++ b/cmd/celestia/docgen.go @@ -1,38 +1,44 @@ package main import ( - "context" "encoding/json" "os" "github.com/spf13/cobra" "github.com/celestiaorg/celestia-node/api/docgen" + "github.com/celestiaorg/celestia-node/api/rpc/client" "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 +var docgenCmd = &cobra.Command{ + Use: "docgen", + Short: "docgen generates the openrpc documentation for all Celestia Node packages", + RunE: func(_ *cobra.Command, _ []string) error { + // 1. Collect all node's modules + moduleNames := make([]string, 0, len(client.Modules)) + for module := range client.Modules { + moduleNames = append(moduleNames, module) + } + + // 2. 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 + // 3. 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 + // 4. Register the client wrapper interface on the document for moduleName, module := range nodebuilder.PackageToAPI { doc.RegisterReceiverName(moduleName, module) } - // 4. Call doc.Discover() + // 5. Call doc.Discover() d, err := doc.Discover() if err != nil { return err } - // 5. Print to Stdout + // 6. Print to Stdout jsonOut, err := json.MarshalIndent(d, "", " ") if err != nil { return err @@ -42,14 +48,3 @@ var rootCmd = &cobra.Command{ return err }, } - -func main() { - err := run() - if err != nil { - os.Exit(1) - } -} - -func run() error { - return rootCmd.ExecuteContext(context.Background()) -} diff --git a/cmd/celestia/main.go b/cmd/celestia/main.go index 76287d998f..86d31c0ee5 100644 --- a/cmd/celestia/main.go +++ b/cmd/celestia/main.go @@ -31,6 +31,7 @@ func init() { bridgeCmd, lightCmd, fullCmd, + docgenCmd, versionCmd, ) rootCmd.SetHelpCommand(&cobra.Command{}) diff --git a/nodebuilder/node/admin.go b/nodebuilder/node/admin.go index f71af66081..387bb0408b 100644 --- a/nodebuilder/node/admin.go +++ b/nodebuilder/node/admin.go @@ -10,7 +10,7 @@ import ( "github.com/celestiaorg/celestia-node/libs/authtoken" ) -const APIVersion = "v0.11.0" +var APIVersion = GetBuildInfo().SemanticVersion type module struct { tp Type