api-doc/parser_test.go

50 lines
1.3 KiB
Go
Raw Normal View History

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"
2024-12-25 12:04:30 +08:00
"git.zhangdeman.cn/zhangdeman/serialize"
"reflect"
2024-07-19 18:01:14 +08:00
"testing"
)
type Meta struct {
}
2024-07-19 18:01:14 +08:00
// 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 {
Meta `json:"-" deprecated:"true" path:"/user/detail" method:"POST" desc:"测试接口" tag:"用户,搜索" content_type:"application/json" output_content_type:"application/json"`
2025-02-13 16:03:31 +08:00
Name string `json:"name" d:"zhang" desc:"用户姓名" binding:"required"`
Age string `json:"age" d:"18" desc:"年龄" binding:"required,oneof=12 13 18 90"`
}
2025-02-12 21:55:35 +08:00
type List struct {
Total int64 `json:"total" binding:"required"`
UserList []User `json:"user_list"`
}
var o List
var f User
2025-02-09 21:23:58 +08:00
g := NewOpenapiDoc(nil, nil)
g.AddApiFromInAndOut(reflect.TypeOf(f), reflect.TypeOf(o))
2025-02-10 11:15:29 +08:00
byteData, _ := json.Marshal(g.docData)
fmt.Println(string(byteData))
fmt.Println(g.parseSliceItem("", reflect.TypeOf(o)))
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
}