feat: 完成基础文档生成
This commit is contained in:
@@ -10,8 +10,11 @@ package openapi
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/api-doc/define"
|
||||
)
|
||||
|
||||
func TestGenerate_AddApiDoc(t *testing.T) {
|
||||
@@ -20,7 +23,7 @@ func TestGenerate_AddApiDoc(t *testing.T) {
|
||||
Name string `json:"name" description:"分类名称"`
|
||||
}
|
||||
type Product struct {
|
||||
ID int64 `json:"id" description:"产品ID" example:"1001" required:"true"`
|
||||
ID int64 `json:"id,omitempty" description:"产品ID" example:"1001" required:"true" binding:"required"`
|
||||
Name string `json:"name" description:"产品名称" example:"iPhone 13" minLength:"2" maxLength:"100" required:"true"`
|
||||
Price float64 `json:"price" description:"价格" example:"6999.99" min:"0"`
|
||||
Stock int `json:"stock" description:"库存" example:"100" min:"0"`
|
||||
@@ -31,7 +34,12 @@ func TestGenerate_AddApiDoc(t *testing.T) {
|
||||
Category *Category `json:"category,omitempty" description:"分类"`
|
||||
}
|
||||
instance := NewGenerate()
|
||||
instance.AddApiDoc(Category{}, Product{})
|
||||
instance.AddApiDoc(define.UriConfig{
|
||||
Path: "/a/b/c",
|
||||
RequestMethod: http.MethodGet,
|
||||
TagList: []string{"test"},
|
||||
Desc: "测试接口",
|
||||
}, Category{}, Product{})
|
||||
// 输出 JSON
|
||||
data, _ := json.MarshalIndent(instance.doc, "", " ")
|
||||
fmt.Println(string(data))
|
||||
|
||||
Reference in New Issue
Block a user