caicloud/nirvana

API docs generation should not rely on a specified project structure

iawia002 opened this issue · 2 comments

现在我们很多 project 的目录结构都是自己定义的比较随意的那种,nirvana api 检测不到任何 descriptor

现在的想法是能不能在 run server 的时候再来生成 api docs,那个时候是已经拿到了所有 descriptor 的,也少了 nirvana api 检测/收集 descriptor 的步骤,把这个做成一个 Configurer,需要的话可以配置在启动 server 的时候生成文档或者直接把文档页面自动注册到当前 server 里,可以直接访问,比如:

$ go run main.go

INFO  0830-17:59:34.608+08 config.go:309 | Listening on :8080
INFO  0830-17:59:35.126+08 nirvana.go:231 | Generated openapi schemes to /Users/mac/iawia002/go/src/github.com/caicloud/nirvana/examples/api-basic
INFO  0830-17:59:35.127+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /api.v1.json
INFO  0830-17:59:35.127+08 builder.go:246 |   Method: Get Consumes: [] Produces: [application/json]
INFO  0830-17:59:35.127+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /api.v2.json
INFO  0830-17:59:35.127+08 builder.go:246 |   Method: Get Consumes: [] Produces: [application/json]
INFO  0830-17:59:35.127+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /docs
INFO  0830-17:59:35.127+08 builder.go:246 |   Method: Get Consumes: [] Produces: [text/html]
INFO  0830-17:59:35.127+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /api/v1/applications
INFO  0830-17:59:35.127+08 builder.go:246 |   Method: Create Consumes: [application/json] Produces: [application/json]
INFO  0830-17:59:35.127+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /api/v2/applications
INFO  0830-17:59:35.127+08 builder.go:246 |   Method: Create Consumes: [application/json] Produces: [application/json]

/docs 就是自动生成的文档的网页版

Screen Shot 2019-08-30 at 18 03 30

/cc @kdada @ddysher @supereagle @bbbmj

SGTM

LGTM

BTW, internally, we should propose a semi-standard structure..