api-doc/parser_test.go

55 lines
1.4 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 A struct {
Name string `json:"name"`
}
type B struct {
List []A `json:"list"`
}
var bArr *B
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(bArr), reflect.TypeOf(bArr))
byteData, _ := json.Marshal(g.docData)
fmt.Println(string(byteData))
fmt.Println(g.parseSliceItem("", reflect.TypeOf(bArr)))
}
func TestParseForSwagger(t *testing.T) {
docUrl := "https://git.zhangdeman.cn/swagger.v1.json"
res, _ := Parse(docUrl)
serialize.JSON.ConsoleOutput(res)
}