From f4447d50d66e0f319b9f4a2dcc6d33cab55d7f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 5 Jan 2026 18:28:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E5=80=BC=E8=B5=8B=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi/schema.go | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/openapi/schema.go b/openapi/schema.go index a9920d4..20b192b 100644 --- a/openapi/schema.go +++ b/openapi/schema.go @@ -120,27 +120,6 @@ func ParseStructField(field reflect.StructField) *StructFieldInfo { return info } -func parseExampleValue(example string, t reflect.Type) interface{} { - // 根据类型解析示例值 - switch t.Kind() { - case reflect.String: - return example - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - if val, err := strconv.ParseInt(example, 10, 64); err == nil { - return val - } - case reflect.Float32, reflect.Float64: - if val, err := strconv.ParseFloat(example, 64); err == nil { - return val - } - case reflect.Bool: - if val, err := strconv.ParseBool(example); err == nil { - return val - } - } - return example -} - // GenerateOpenAPISchema 生成完整的 OpenAPI Schema func GenerateOpenAPISchema(s interface{}) *openapi3.SchemaRef { t := reflect.TypeOf(s) @@ -267,7 +246,10 @@ func applyFieldInfoToSchema(schema *openapi3.Schema, info *StructFieldInfo) { schema.Format = info.Format } if len(info.Enum) > 0 { - schema.Enum = info.Enum + schema.Enum = make([]any, 0) + for _, item := range info.Enum { + schema.Enum = append(schema.Enum, item.Value) + } } }