feat: 完善字段描述获取
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/api-doc/define"
|
||||
"git.zhangdeman.cn/zhangdeman/api-doc/util"
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
)
|
||||
|
||||
@@ -35,10 +37,6 @@ type StructFieldInfo struct {
|
||||
OmitEmpty bool `json:"omit_empty" dc:"是否可控"`
|
||||
}
|
||||
|
||||
func getDesc(field reflect.StructField) string {
|
||||
|
||||
}
|
||||
|
||||
// ParseStructField 解析结构体字段信息
|
||||
func ParseStructField(field reflect.StructField) *StructFieldInfo {
|
||||
if !field.IsExported() {
|
||||
@@ -51,7 +49,7 @@ func ParseStructField(field reflect.StructField) *StructFieldInfo {
|
||||
}
|
||||
|
||||
// 解析 JSON tag
|
||||
jsonTag := field.Tag.Get("json")
|
||||
jsonTag := field.Tag.Get(define.TagJson)
|
||||
if jsonTag != "" {
|
||||
parts := strings.Split(jsonTag, ",")
|
||||
if len(parts) > 0 {
|
||||
@@ -64,7 +62,7 @@ func ParseStructField(field reflect.StructField) *StructFieldInfo {
|
||||
}
|
||||
for _, part := range parts[1:] {
|
||||
switch part {
|
||||
case "omitempty":
|
||||
case define.TagNameOmitempty:
|
||||
info.OmitEmpty = true
|
||||
}
|
||||
}
|
||||
@@ -75,15 +73,11 @@ func ParseStructField(field reflect.StructField) *StructFieldInfo {
|
||||
info.JSONName = info.Name
|
||||
}
|
||||
|
||||
// 解析其他标签
|
||||
if desc := field.Tag.Get("description"); desc != "" {
|
||||
info.Description = desc
|
||||
}
|
||||
|
||||
if example := field.Tag.Get("example"); example != "" {
|
||||
info.Example = parseExampleValue(example, field.Type)
|
||||
}
|
||||
|
||||
// 解析参数描述
|
||||
info.Description = util.ParseStructFieldTag.GetParamDesc(field)
|
||||
// 解析示例值
|
||||
info.Example = util.ParseStructFieldTag.GetExampleValue(field)
|
||||
// 解析验证规则
|
||||
if required := field.Tag.Get("required"); required == "true" {
|
||||
info.Required = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user