2024-07-19 18:01:14 +08:00
|
|
|
// Package api_doc ...
|
|
|
|
//
|
|
|
|
// Description : api_doc ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2024-07-19 17:52
|
|
|
|
package api_doc
|
|
|
|
|
|
|
|
import (
|
2025-02-10 11:15:29 +08:00
|
|
|
"encoding/json"
|
2024-07-19 18:01:14 +08:00
|
|
|
"fmt"
|
|
|
|
"git.zhangdeman.cn/gateway/api-doc/define"
|
2024-12-25 12:04:30 +08:00
|
|
|
"git.zhangdeman.cn/zhangdeman/serialize"
|
2025-02-09 15:00:25 +08:00
|
|
|
"net/http"
|
2025-02-08 21:27:40 +08:00
|
|
|
"reflect"
|
2024-07-19 18:01:14 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Test_parser_Openapi3 测试数据结构定义正确性
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 17:55 2024/7/19
|
|
|
|
func Test_parser_Openapi3(t *testing.T) {
|
2025-02-12 21:55:35 +08:00
|
|
|
type User struct {
|
2025-02-11 22:28:45 +08:00
|
|
|
Name string `json:"name" d:"zhang" desc:"用户姓名"`
|
2025-02-12 21:55:35 +08:00
|
|
|
Age int `json:"age" d:"18" desc:"年龄"`
|
2025-02-08 21:27:40 +08:00
|
|
|
}
|
2025-02-12 21:55:35 +08:00
|
|
|
type List struct {
|
|
|
|
Total int64 `json:"total"`
|
|
|
|
UserList []User `json:"user_list"`
|
2025-02-08 21:27:40 +08:00
|
|
|
}
|
2025-02-12 21:55:35 +08:00
|
|
|
var l List
|
2025-02-09 21:23:58 +08:00
|
|
|
g := NewOpenapiDoc(nil, nil)
|
2025-02-09 15:00:25 +08:00
|
|
|
g.AddApiFromInAndOut(&define.UriBaseConfig{
|
2025-02-10 11:22:40 +08:00
|
|
|
Uri: "/ent/user/detail",
|
2025-02-09 15:00:25 +08:00
|
|
|
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,
|
2025-02-12 21:55:35 +08:00
|
|
|
}, reflect.TypeOf(l), reflect.TypeOf(l))
|
2025-02-10 11:15:29 +08:00
|
|
|
byteData, _ := json.Marshal(g.docData)
|
|
|
|
fmt.Println(string(byteData))
|
2025-02-12 21:55:35 +08:00
|
|
|
fmt.Println(g.parseSliceItem("", reflect.TypeOf(l)))
|
2024-07-19 18:01:14 +08:00
|
|
|
}
|
2024-12-24 10:34:28 +08:00
|
|
|
|
|
|
|
func TestParseForSwagger(t *testing.T) {
|
|
|
|
docUrl := "https://git.zhangdeman.cn/swagger.v1.json"
|
2024-12-25 12:04:30 +08:00
|
|
|
res, _ := Parse(docUrl)
|
|
|
|
serialize.JSON.ConsoleOutput(res)
|
2024-12-24 10:34:28 +08:00
|
|
|
}
|