Merge pull request '修复数组指针解析的BUG' (#4) from feature/fix_nested_model into master
Reviewed-on: #4
This commit is contained in:
commit
d70cfe3e50
@ -547,6 +547,9 @@ func (g *Generate) parseSliceItem(rootSchemaName string, inputType reflect.Type)
|
|||||||
}
|
}
|
||||||
sliceValue := reflect.MakeSlice(inputType, 1, 1)
|
sliceValue := reflect.MakeSlice(inputType, 1, 1)
|
||||||
sliceItemType := sliceValue.Index(0).Type()
|
sliceItemType := sliceValue.Index(0).Type()
|
||||||
|
if sliceItemType.Kind() == reflect.Ptr {
|
||||||
|
sliceItemType = sliceItemType.Elem()
|
||||||
|
}
|
||||||
g.AddComponentsSchema(rootSchemaName, sliceItemType.PkgPath(), sliceItemType)
|
g.AddComponentsSchema(rootSchemaName, sliceItemType.PkgPath(), sliceItemType)
|
||||||
if len(sliceItemType.PkgPath()) == 0 {
|
if len(sliceItemType.PkgPath()) == 0 {
|
||||||
return sliceItemType.String()
|
return sliceItemType.String()
|
||||||
@ -563,6 +566,7 @@ func (g *Generate) getSchemaRef(schemaName string) string {
|
|||||||
if "" == schemaName {
|
if "" == schemaName {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
schemaName = strings.ReplaceAll(schemaName, "*", "") // 去除指针类型 *
|
||||||
return "#/components/schemas/" + strings.ReplaceAll(schemaName, "/", "-")
|
return "#/components/schemas/" + strings.ReplaceAll(schemaName, "/", "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ type Meta struct {
|
|||||||
func Test_parser_Openapi3(t *testing.T) {
|
func Test_parser_Openapi3(t *testing.T) {
|
||||||
type User struct {
|
type User struct {
|
||||||
Meta `json:"-" deprecated:"false" 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"`
|
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"`
|
||||||
}
|
}
|
||||||
type UserDelete struct {
|
type UserDelete struct {
|
||||||
Meta `json:"-" deprecated:"false" path:"/user/detail" method:"DELETE" desc:"测试接口" tag:"用户,搜索" content_type:"application/json" output_content_type:"application/json"`
|
Meta `json:"-" deprecated:"false" path:"/user/detail" method:"DELETE" desc:"测试接口" tag:"用户,搜索" content_type:"application/json" output_content_type:"application/json"`
|
||||||
@ -51,15 +51,15 @@ func Test_parser_Openapi3(t *testing.T) {
|
|||||||
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"`
|
||||||
}
|
}
|
||||||
type List struct {
|
type List struct {
|
||||||
Total int64 `json:"total" binding:"required"`
|
Total int64 `json:"total" binding:"required"`
|
||||||
UserList []User `json:"user_list"`
|
UserList []*User `json:"user_list"`
|
||||||
}
|
}
|
||||||
var o List
|
var o *List
|
||||||
var f User
|
var f *User
|
||||||
var fd UserDelete
|
var fd *UserDelete
|
||||||
var up UserPut
|
var up *UserPut
|
||||||
var ug UserGet
|
var ug *UserGet
|
||||||
var uh UserHead
|
var uh *UserHead
|
||||||
g := NewOpenapiDoc(nil, []*define.ServerItem{
|
g := NewOpenapiDoc(nil, []*define.ServerItem{
|
||||||
&define.ServerItem{
|
&define.ServerItem{
|
||||||
Url: "http://127.0.0.1/v1",
|
Url: "http://127.0.0.1/v1",
|
||||||
@ -78,11 +78,11 @@ func Test_parser_Openapi3(t *testing.T) {
|
|||||||
Variables: nil,
|
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))
|
g.AddApiFromInAndOut("", reflect.TypeOf(fd), reflect.TypeOf(o))
|
||||||
g.AddApiFromInAndOut(reflect.TypeOf(up), reflect.TypeOf(o))
|
g.AddApiFromInAndOut("", reflect.TypeOf(up), reflect.TypeOf(o))
|
||||||
g.AddApiFromInAndOut(reflect.TypeOf(ug), reflect.TypeOf(o))
|
g.AddApiFromInAndOut("", reflect.TypeOf(ug), reflect.TypeOf(o))
|
||||||
g.AddApiFromInAndOut(reflect.TypeOf(uh), reflect.TypeOf(o))
|
g.AddApiFromInAndOut("", reflect.TypeOf(uh), reflect.TypeOf(o))
|
||||||
byteData, _ := json.Marshal(g.docData)
|
byteData, _ := json.Marshal(g.docData)
|
||||||
fmt.Println(string(byteData))
|
fmt.Println(string(byteData))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user