Skip to content

Commit

Permalink
refactor(openapi): 允许 Operation.Response 的 resp 为 nil
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Nov 25, 2024
1 parent a7cd7c4 commit 167f776
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions openapi/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ func (o *Operation) BodyRef(ref string, summary, description web.LocaleStringer)
//
// f 如果不为空,则要以对根据 resp 生成的对象做二次修改。
func (o *Operation) Response(status string, resp any, desc web.LocaleStringer, f func(*Response)) *Operation {
r := &Response{
Description: desc,
Body: o.d.newSchema(reflect.TypeOf(resp)),
r := &Response{Description: desc}

if resp != nil {
r.Body = o.d.newSchema(reflect.TypeOf(resp))
}

if f != nil {
f(r)
}
Expand Down
2 changes: 2 additions & 0 deletions openapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
)

const (
FormatBinary = "binary"
FormatByte = "byte"
FormatInt32 = "int32"
FormatInt64 = "int64"
FormatFloat = "float"
Expand Down

0 comments on commit 167f776

Please sign in to comment.