Skip to content

Commit

Permalink
fix underlying type pointer resolution problem
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Feb 20, 2022
1 parent b4e0f20 commit e7be3a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 8 additions & 7 deletions examples/builtin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ func handle(w http.ResponseWriter, req *http.Request) {

// Category example from the swagger pet store
type Category struct {
ID int64 `json:"category"`
Name string `json:"name" enum:"dog,cat" required:""`
ID int64 `json:"category"`
Name string `json:"name" enum:"dog,cat" required:""`
Exists *bool `json:"exists" required:""`
}

// Pet example from the swagger pet store
type Pet struct {
ID int64 `json:"id"`
Category Category `json:"category" desc:"分类"`
Name string `json:"name" required:"" example:"张三" desc:"名称"`
PhotoUrls []string `json:"photoUrls"`
Tags []string `json:"tags" desc:"标签"`
ID int64 `json:"id"`
Category *Category `json:"category" desc:"分类"`
Name string `json:"name" required:"" example:"张三" desc:"名称"`
PhotoUrls []string `json:"photoUrls"`
Tags []string `json:"tags" desc:"标签"`
Test
}

Expand Down
4 changes: 4 additions & 0 deletions swagger/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func inspect(t reflect.Type, jsonTag string) Property {
return p
}

if p.GoType.Kind() == reflect.Ptr {
p.GoType = p.GoType.Elem()
}

switch p.GoType.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint8, reflect.Uint16, reflect.Uint32:
p.Type = TypeInteger
Expand Down

0 comments on commit e7be3a1

Please sign in to comment.