openapi格式的文档基础生成 #3
@ -264,6 +264,8 @@ func (g *Generate) AddApiFromInAndOut(paramType reflect.Type, resultType reflect
|
|||||||
g.docData.Paths[baseCfg.Uri].Options = cfg
|
g.docData.Paths[baseCfg.Uri].Options = cfg
|
||||||
case http.MethodTrace:
|
case http.MethodTrace:
|
||||||
g.docData.Paths[baseCfg.Uri].Trace = cfg
|
g.docData.Paths[baseCfg.Uri].Trace = cfg
|
||||||
|
default:
|
||||||
|
panic("unknown method: " + baseCfg.Method)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ package api_doc
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -25,7 +26,12 @@ type Meta struct {
|
|||||||
// Date : 17:55 2024/7/19
|
// Date : 17:55 2024/7/19
|
||||||
func Test_parser_Openapi3(t *testing.T) {
|
func Test_parser_Openapi3(t *testing.T) {
|
||||||
type User struct {
|
type User struct {
|
||||||
Meta `json:"-" deprecated:"true" path:"/user/detail" method:"POST" desc:"测试接口" tag:"用户,搜索" content_type:"application/json" output_content_type:"application/json"`
|
Meta `json:"-" deprecated:"false" path:"/user/detail" method:"POST" desc:"测试接口" tag:"用户,搜索" content_type:"application/json" output_content_type:"application/json"`
|
||||||
|
Name string `json:"name" d:"zhang" desc:"用户姓名" binding:"required"`
|
||||||
|
Age string `json:"age" d:"18" desc:"年龄" binding:"required,oneof=12 13 18 90"`
|
||||||
|
}
|
||||||
|
type UserDelete struct {
|
||||||
|
Meta `json:"-" deprecated:"false" path:"/user/detail" method:"DELETE" desc:"测试接口" tag:"用户,搜索" content_type:"application/json" output_content_type:"application/json"`
|
||||||
Name string `json:"name" d:"zhang" desc:"用户姓名" binding:"required"`
|
Name string `json:"name" d:"zhang" desc:"用户姓名" binding:"required"`
|
||||||
Age string `json:"age" d:"18" desc:"年龄" binding:"required,oneof=12 13 18 90"`
|
Age string `json:"age" d:"18" desc:"年龄" binding:"required,oneof=12 13 18 90"`
|
||||||
}
|
}
|
||||||
@ -35,11 +41,23 @@ func Test_parser_Openapi3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var o List
|
var o List
|
||||||
var f User
|
var f User
|
||||||
g := NewOpenapiDoc(nil, nil)
|
var fd UserDelete
|
||||||
|
g := NewOpenapiDoc(nil, []*define.ServerItem{
|
||||||
|
&define.ServerItem{
|
||||||
|
Url: "http://127.0.0.1/v1",
|
||||||
|
Description: "v1接口",
|
||||||
|
Variables: nil,
|
||||||
|
},
|
||||||
|
&define.ServerItem{
|
||||||
|
Url: "http://127.0.0.1/v2",
|
||||||
|
Description: "v2接口",
|
||||||
|
Variables: nil,
|
||||||
|
},
|
||||||
|
})
|
||||||
g.AddApiFromInAndOut(reflect.TypeOf(f), reflect.TypeOf(o))
|
g.AddApiFromInAndOut(reflect.TypeOf(f), reflect.TypeOf(o))
|
||||||
|
g.AddApiFromInAndOut(reflect.TypeOf(fd), reflect.TypeOf(o))
|
||||||
byteData, _ := json.Marshal(g.docData)
|
byteData, _ := json.Marshal(g.docData)
|
||||||
fmt.Println(string(byteData))
|
fmt.Println(string(byteData))
|
||||||
fmt.Println(g.parseSliceItem("", reflect.TypeOf(o)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseForSwagger(t *testing.T) {
|
func TestParseForSwagger(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user