From 55bd2cca151b0f857b61fb1a9919cb929de9c631 Mon Sep 17 00:00:00 2001 From: Kiyan Date: Fri, 2 Aug 2024 09:36:40 +0800 Subject: [PATCH] fix(schema): default value --- schema.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/schema.go b/schema.go index bfbc33af..4c11a643 100644 --- a/schema.go +++ b/schema.go @@ -515,7 +515,9 @@ func SchemaFromField(registry Registry, f reflect.StructField, hint string) *Sch if enc := f.Tag.Get("encoding"); enc != "" { fs.ContentEncoding = enc } - fs.Default = jsonTag(registry, f, fs, "default") + if defaultValue := jsonTag(registry, f, fs, "default"); defaultValue != nil { + fs.Default = defaultValue + } if value := f.Tag.Get("example"); value != "" { if e := jsonTagValue(registry, f.Name, fs, value); e != nil {