feat: 优化参数名称解析

This commit is contained in:
2026-01-05 18:46:53 +08:00
parent f4447d50d6
commit 5ff7dac227
2 changed files with 27 additions and 35 deletions

View File

@@ -10,7 +10,6 @@ package openapi
import (
"reflect"
"strconv"
"strings"
"time"
"git.zhangdeman.cn/zhangdeman/api-doc/define"
@@ -48,30 +47,9 @@ func ParseStructField(field reflect.StructField) *StructFieldInfo {
Type: field.Type,
}
util.ParseStructFieldTag.GetParamName(field)
// 解析 JSON tag
jsonTag := field.Tag.Get(define.TagJson)
if jsonTag != "" {
parts := strings.Split(jsonTag, ",")
if len(parts) > 0 {
if parts[0] == "-" {
return nil // 跳过该字段
}
if parts[0] != "" {
info.JSONName = parts[0]
}
}
for _, part := range parts[1:] {
switch part {
case define.TagNameOmitempty:
info.OmitEmpty = true
}
}
}
if info.JSONName == "" {
// 使用结构体字段名作为默认的 json tag
info.JSONName = info.Name
}
info.JSONName, info.OmitEmpty = util.ParseStructFieldTag.GetParamName(field)
// 解析参数描述
info.Description = util.ParseStructFieldTag.GetParamDesc(field)