caicloud / nirvana

Golang Restful API Framework for Productivity
https://caicloud.github.io/nirvana/
Apache License 2.0
519 stars 106 forks source link

[API generation] we need better api generation #259

Open tskdsb opened 5 years ago

tskdsb commented 5 years ago

/kind feature

What happened: I'm glad to see the feature: api-auto-generation, it looks like: image it seems good, but I want more.

What you expected to happen: I wrote an API documentation a few days ago, and I suffered a lot. So, I hope that the ability of API-generation can be more complete:

可能废话有点多,所以这里在总结一下,要求一共两点:

tskdsb commented 5 years ago

/assign @ddysher

ddysher commented 5 years ago

Thanks for bringing this up.

Most of the questions here are related to representation of API docs, which are actually not part of nirvana. We use https://github.com/Rebilly/ReDoc for navigating APIs, can u explore it and see if it solves ur problem?

If so, then we can either upgrade ReDoc, or we put some rules in nirvana to force people writing more documentations (and thus better API docs).

ddysher commented 5 years ago

/cc @kdada

kdada commented 5 years ago

Q: Required or Default? A: If a parameter has a default value, it shows the default value in the field frame. Otherwise it shows Required.

Q: Where is parameter descriptions? A: In Parameter.Description and Result.Description. Also you can write comments for your struct fields. These comments will be shown at the right side of struct fields.

Q: How to set examples? A: In Definition.Examples. You can put response struct examples here now (No requests support).

I think we can improve the user experiences via implementing these features:

tskdsb commented 5 years ago

Q: Required or Default? A: If a parameter has a default value, it shows the default value in the field frame. Otherwise it shows Required.

Q: Where is parameter descriptions? A: In Parameter.Description and Result.Description. Also you can write comments for your struct fields. These comments will be shown at the right side of struct fields.

Q: How to set examples? A: In Definition.Examples. You can put response struct examples here now (No requests support).

I think we can improve the user experiences via implementing these features:

  • Implement documents server to proxy test requests to backend server.
  • Refine Definition.Examples to support parameters. (Depends on ReDoc)
kdada commented 5 years ago

For comments:

type Tsk2 struct {
    // Write comments here.
    A string `json:"a"`
}
kdada commented 5 years ago

If you are interesting in extending doc server for Nirvana, please write down your proposal.

tskdsb commented 5 years ago

经过 @kdada 的指导,更深入的使用后,发现nirvana的API生成已经足够完备,至少信息展示方面已经足够了。

那只剩【交互】方面的问题了,简单的说需要以下功能:

结构图: image

方案:

待补充

ddysher commented 5 years ago

@kdada

Can we update the docs so people can understand how to create useful API generation without asking :)

经过 @kdada 的指导,更深入的使用后,发现nirvana的API生成已经足够完备,至少信息展示方面已经足够了。

zcong1993 commented 5 years ago

可以考虑一下 https://github.com/swagger-api/swagger-ui

简单支持这样就行 https://github.com/zcong1993/nirvana/blob/master/cmd/nirvana/api/api.go#L339

kdada commented 5 years ago

@zcong1993 How does it implement proxy and mock APIs?

@ddysher I'll update the doc when I'm free.