feat: 增加枚举值解析

This commit is contained in:
2026-01-05 18:23:23 +08:00
parent 8ce50fd235
commit 1157973b65
3 changed files with 28 additions and 27 deletions

View File

@@ -20,21 +20,21 @@ import (
// StructFieldInfo 结构体字段信息
type StructFieldInfo struct {
Name string `json:"name" dc:"结构体字段名"`
JSONName string `json:"json_name" dc:"json tag"`
Type reflect.Type `json:"type" dc:"字段类型"`
Description string `json:"description" dc:"参数描述"`
Example any `json:"example" dc:"示例值"`
Default any `json:"default" dc:"默认值"`
Required bool `json:"required" dc:"是否必传"`
Min *float64 `json:"min" dc:"最小值"`
Max *float64 `json:"max" dc:"最大值"`
MinLength *uint64 `json:"min_length" dc:"最小长度"`
MaxLength *uint64 `json:"max_length" dc:"最大长度"`
Pattern string `json:"pattern" dc:"模式"`
Format string `json:"format" dc:"格式"`
Enum []any `json:"enum" dc:"枚举值列表"`
OmitEmpty bool `json:"omit_empty" dc:"是否可控"`
Name string `json:"name" dc:"结构体字段名"`
JSONName string `json:"json_name" dc:"json tag"`
Type reflect.Type `json:"type" dc:"字段类型"`
Description string `json:"description" dc:"参数描述"`
Example any `json:"example" dc:"示例值"`
Default any `json:"default" dc:"默认值"`
Required bool `json:"required" dc:"是否必传"`
Min *float64 `json:"min" dc:"最小值"`
Max *float64 `json:"max" dc:"最大值"`
MinLength *uint64 `json:"min_length" dc:"最小长度"`
MaxLength *uint64 `json:"max_length" dc:"最大长度"`
Pattern string `json:"pattern" dc:"模式"`
Format string `json:"format" dc:"格式"`
Enum []define.EnumValue `json:"enum" dc:"枚举值列表"`
OmitEmpty bool `json:"omit_empty" dc:"是否可控"`
}
// ParseStructField 解析结构体字段信息
@@ -114,12 +114,8 @@ func ParseStructField(field reflect.StructField) *StructFieldInfo {
info.Format = format
}
if enum := field.Tag.Get("enum"); enum != "" {
enums := strings.Split(enum, ",")
for _, e := range enums {
info.Enum = append(info.Enum, strings.TrimSpace(e))
}
}
// 解析枚举值
info.Enum = util.ParseStructFieldTag.EnumDescription(field)
return info
}