Skip to content

Commit f57ebdc

Browse files
nearyipnearyip
nearyip
authored and
nearyip
committed
apidoc body的example value使用的是结构体的字段名,如UserName,但是实际开发过程中,会存在大家使用json注释的情况,即user_name,目前body里面的example value即使加了json注释也仍然是使用结构体的字段名,实际调试起来还要对example value进行修改,非常不方便,所以这里需要增加一个判断条件,如果存在json注释的话,property的key改为json的值
1 parent fbd11bf commit f57ebdc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ samples/demo/demo
3535

3636
ext/services
3737
.DS_Store
38+
.idea

swagger/swagger.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,12 @@ func CreateProperties(obj interface{}) map[string]*Property {
302302
fv = reflect.New(ft).Elem()
303303
}
304304
p.Default = fv.Interface()
305-
ps[field.Name] = p
305+
n := field.Tag.Get("json")
306+
if n == "" {
307+
ps[field.Name] = p
308+
} else {
309+
ps[n] = p
310+
}
306311
}
307312
return ps
308313

0 commit comments

Comments
 (0)