Skip to content

Commit

Permalink
apidoc body的example value使用的是结构体的字段名,如UserName,但是实际开发过程中,会存在大家使用json注…
Browse files Browse the repository at this point in the history
…释的情况,即user_name,目前body里面的example value即使加了json注释也仍然是使用结构体的字段名,实际调试起来还要对example value进行修改,非常不方便,所以这里需要增加一个判断条件,如果存在json注释的话,property的key改为json的值
  • Loading branch information
nearyip authored and nearyip committed Sep 2, 2019
1 parent fbd11bf commit f57ebdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ samples/demo/demo

ext/services
.DS_Store
.idea
7 changes: 6 additions & 1 deletion swagger/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,12 @@ func CreateProperties(obj interface{}) map[string]*Property {
fv = reflect.New(ft).Elem()
}
p.Default = fv.Interface()
ps[field.Name] = p
n := field.Tag.Get("json")
if n == "" {
ps[field.Name] = p
} else {
ps[n] = p
}
}
return ps

Expand Down

0 comments on commit f57ebdc

Please sign in to comment.