Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/febelery/go-apidoc

通过访问接口上下文自动生成文档
https://github.com/febelery/go-apidoc

api apidoc auto docs document go node

Last synced: 5 days ago
JSON representation

通过访问接口上下文自动生成文档

Awesome Lists containing this project

README

        

# go-apidoc

API 文档生成
该项目使用 `apidoc` 工具自动生成 API 文档。通过自动抓取在 Go 语言的 API 接口上下文生成符合 `apidoc`
要求的文档。

## 安装

```shell
go get -u github.com/febelery/go-apidoc
npm install -g apidoc
```

## 使用

- gofiber 框架
```golang
app.Static("/doc", "doc/api")
app.Static("/assets", "doc/api/assets")

app.Use(func(c *fiber.Ctx) error {
err := c.Next()
skip := string(c.Response().Header.Peek("Content-Type")) != "application/json" ||
strings.ToLower(os.Getenv("SKIP_DOC")) == "true"

headers := make(map[string]string)
if auth := c.GetReqHeaders()["Authorization"]; len(auth) > 0 {
headers["Authorization"] = auth[0]
}

go goapidoc.New(goapidoc.ApiDef{
Method: c.Method(),
Path: c.Route().Path,
Params: c.AllParams(),
Headers: headers,
Queries: c.Queries(),
StatusCode: c.Response().StatusCode(),
ResponseBody: c.Response().Body(),
Skip: skip,
})

return err
})
```

## 依赖

- Go >= 1.21
- Node.js
- apidoc:https://github.com/apidoc/apidoc