make docsgen work with versioned api

This commit is contained in:
Łukasz Magiera 2021-03-23 17:20:56 +01:00
parent 3fe4b50a13
commit d198cf456e
11 changed files with 5602 additions and 18 deletions

View File

@ -341,20 +341,21 @@ docsgen-openrpc-bin:
docsgen-md: docsgen-md-full docsgen-md-storage docsgen-md-worker
docsgen-md-full: docsgen-md-bin
./docgen-md "api/api_full.go" "FullNode" > documentation/en/api-methods.md
./docgen-md "api/api_full.go" "FullNode" "api" "./api" > documentation/en/api-v1-unstable-methods.md
./docgen-md "api/v0api/full.go" "FullNode" "v0api" "./api/v0api" > documentation/en/api-v0-methods.md
docsgen-md-storage: docsgen-md-bin
./docgen-md "api/api_storage.go" "StorageMiner" > documentation/en/api-methods-miner.md
./docgen-md "api/api_storage.go" "StorageMiner" "api" "./api" > documentation/en/api-v0-methods-miner.md
docsgen-md-worker: docsgen-md-bin
./docgen-md "api/api_worker.go" "Worker" > documentation/en/api-methods-worker.md
./docgen-md "api/api_worker.go" "Worker" "api" "./api" > documentation/en/api-v0-methods-worker.md
docsgen-openrpc: docsgen-openrpc-full docsgen-openrpc-storage docsgen-openrpc-worker
docsgen-openrpc-full: docsgen-openrpc-bin
./docgen-openrpc "api/api_full.go" "FullNode" -gzip > build/openrpc/full.json.gz
./docgen-openrpc "api/api_full.go" "FullNode" "api" "./api" -gzip > build/openrpc/full.json.gz
docsgen-openrpc-storage: docsgen-openrpc-bin
./docgen-openrpc "api/api_storage.go" "StorageMiner" -gzip > build/openrpc/miner.json.gz
./docgen-openrpc "api/api_storage.go" "StorageMiner" "api" "./api" -gzip > build/openrpc/miner.json.gz
docsgen-openrpc-worker: docsgen-openrpc-bin
./docgen-openrpc "api/api_worker.go" "Worker" -gzip > build/openrpc/worker.json.gz
./docgen-openrpc "api/api_worker.go" "Worker" "api" "./api" -gzip > build/openrpc/worker.json.gz
.PHONY: docsgen docsgen-md-bin docsgen-openrpc-bin

View File

@ -52,7 +52,7 @@ func main() {
// Could use flags package to handle this more cleanly, but that requires changes elsewhere
// the scope of which just isn't warranted by this one use case which will usually be run
// programmatically anyways.
if len(os.Args) > 3 && os.Args[3] == "-gzip" {
if len(os.Args) > 5 && os.Args[5] == "-gzip" {
jsonOut, err = json.Marshal(out)
if err != nil {
log.Fatalln(err)

View File

@ -22,7 +22,7 @@ var Comments map[string]string
var GroupDocs map[string]string
func init() {
Comments, GroupDocs = docgen.ParseApiASTInfo(os.Args[1], os.Args[2])
Comments, GroupDocs = docgen.ParseApiASTInfo(os.Args[1], os.Args[2], os.Args[3], os.Args[4])
}
// schemaDictEntry represents a type association passed to the jsonschema reflector.

View File

@ -14,7 +14,7 @@ import (
)
func main() {
comments, groupComments := docgen.ParseApiASTInfo(os.Args[1], os.Args[2])
comments, groupComments := docgen.ParseApiASTInfo(os.Args[1], os.Args[2], os.Args[3], os.Args[4])
groups := make(map[string]*docgen.MethodGroup)

View File

@ -342,9 +342,9 @@ func (v *Visitor) Visit(node ast.Node) ast.Visitor {
const NoComment = "There are not yet any comments for this method."
func ParseApiASTInfo(apiFile, iface string) (comments map[string]string, groupDocs map[string]string) { //nolint:golint
func ParseApiASTInfo(apiFile, iface, pkg, dir string) (comments map[string]string, groupDocs map[string]string) { //nolint:golint
fset := token.NewFileSet()
apiDir, err := filepath.Abs("./api")
apiDir, err := filepath.Abs(dir)
if err != nil {
fmt.Println("./api filepath absolute error: ", err)
return
@ -360,14 +360,14 @@ func ParseApiASTInfo(apiFile, iface string) (comments map[string]string, groupDo
return
}
ap := pkgs["api"]
ap := pkgs[pkg]
f := ap.Files[apiFile]
cmap := ast.NewCommentMap(fset, f, f.Comments)
v := &Visitor{iface, make(map[string]ast.Node)}
ast.Walk(v, pkgs["api"])
ast.Walk(v, ap)
comments = make(map[string]string)
groupDocs = make(map[string]string)

View File

@ -4,7 +4,7 @@ import (
"github.com/filecoin-project/lotus/api/v1api"
)
type WrapperV1 struct {
type WrapperV1Full struct {
v1api.FullNode
}
@ -12,11 +12,11 @@ type WrapperV1 struct {
- dropped StateGetReceipt
- tsk param for StateSearchMsg
func (w *WrapperV1) StateSearchMsg(ctx context.Context, c cid.Cid) (*api.MsgLookup, error) {
func (w *WrapperV1Full) StateSearchMsg(ctx context.Context, c cid.Cid) (*api.MsgLookup, error) {
return w.FullNode.StateSearchMsg(ctx, c, types.EmptyTSK)
}
func (w *WrapperV1) StateGetReceipt(ctx context.Context, cid cid.Cid, key types.TipSetKey) (*types.MessageReceipt, error) {
func (w *WrapperV1Full) StateGetReceipt(ctx context.Context, cid cid.Cid, key types.TipSetKey) (*types.MessageReceipt, error) {
m, err := w.FullNode.StateSearchMsg(ctx, cid, key)
if err != nil {
return nil, err
@ -29,4 +29,4 @@ func (w *WrapperV1) StateGetReceipt(ctx context.Context, cid cid.Cid, key types.
return &m.Receipt, nil
}*/
var _ FullNode = &WrapperV1{}
var _ FullNode = &WrapperV1Full{}

View File

@ -51,7 +51,7 @@ func serveRPC(a v1api.FullNode, stop node.StopFunc, addr multiaddr.Multiaddr, sh
pma := apistruct.PermissionedFullAPI(metrics.MetricedFullAPI(a))
serveRpc("/rpc/v1", pma)
serveRpc("/rpc/v0", &v0api.WrapperV1{FullNode: pma})
serveRpc("/rpc/v0", &v0api.WrapperV1Full{FullNode: pma})
importAH := &auth.Handler{
Verify: a.AuthVerify,

File diff suppressed because it is too large Load Diff