57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
// Package api_doc ...
|
|
//
|
|
// Description : api_doc ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 2024-07-19 17:52
|
|
package api_doc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"git.zhangdeman.cn/gateway/api-doc/define"
|
|
"git.zhangdeman.cn/zhangdeman/serialize"
|
|
"net/http"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// Test_parser_Openapi3 测试数据结构定义正确性
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 17:55 2024/7/19
|
|
func Test_parser_Openapi3(t *testing.T) {
|
|
type User struct {
|
|
Name string `json:"name" d:"zhang" desc:"用户姓名" binding:"required"`
|
|
Age int `json:"age" d:"18" desc:"年龄" binding:"required,oneof:12 13 18 90"`
|
|
}
|
|
type List struct {
|
|
Total int64 `json:"total" binding:"required"`
|
|
UserList []User `json:"user_list"`
|
|
}
|
|
var l List
|
|
g := NewOpenapiDoc(nil, nil)
|
|
g.AddApiFromInAndOut(&define.UriBaseConfig{
|
|
Uri: "/ent/user/detail",
|
|
Method: http.MethodPost,
|
|
ContentType: []string{"application/x-www-form-urlencoded"},
|
|
OutputContentType: []string{"application/yml", "application/json", "application/xml"},
|
|
TagList: []string{"测试文档生成"},
|
|
Summary: "测试接口",
|
|
Description: "",
|
|
ParamList: nil,
|
|
ResultList: nil,
|
|
}, reflect.TypeOf(l), reflect.TypeOf(l))
|
|
byteData, _ := json.Marshal(g.docData)
|
|
fmt.Println(string(byteData))
|
|
fmt.Println(g.parseSliceItem("", reflect.TypeOf(l)))
|
|
}
|
|
|
|
func TestParseForSwagger(t *testing.T) {
|
|
docUrl := "https://git.zhangdeman.cn/swagger.v1.json"
|
|
res, _ := Parse(docUrl)
|
|
serialize.JSON.ConsoleOutput(res)
|
|
}
|