Skip to content

Commit

Permalink
remove params from docgen cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Apr 29, 2024
1 parent 0a05cbd commit b886feb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pb-gen:
## openrpc-gen: Generate OpenRPC spec for Celestia-Node's RPC api
openrpc-gen:
@echo "--> Generating OpenRPC spec"
@go run ${LDFLAGS} ./cmd/celestia 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.
Expand Down
23 changes: 15 additions & 8 deletions cmd/celestia/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,38 @@ import (
"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 docgenCmd = &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
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
Expand Down

0 comments on commit b886feb

Please sign in to comment.