Skip to content

Commit 167f776

Browse files
committed
refactor(openapi): 允许 Operation.Response 的 resp 为 nil
1 parent a7cd7c4 commit 167f776

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

openapi/middleware.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,12 @@ func (o *Operation) BodyRef(ref string, summary, description web.LocaleStringer)
268268
//
269269
// f 如果不为空,则要以对根据 resp 生成的对象做二次修改。
270270
func (o *Operation) Response(status string, resp any, desc web.LocaleStringer, f func(*Response)) *Operation {
271-
r := &Response{
272-
Description: desc,
273-
Body: o.d.newSchema(reflect.TypeOf(resp)),
271+
r := &Response{Description: desc}
272+
273+
if resp != nil {
274+
r.Body = o.d.newSchema(reflect.TypeOf(resp))
274275
}
276+
275277
if f != nil {
276278
f(r)
277279
}

openapi/openapi.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const (
4545
)
4646

4747
const (
48+
FormatBinary = "binary"
49+
FormatByte = "byte"
4850
FormatInt32 = "int32"
4951
FormatInt64 = "int64"
5052
FormatFloat = "float"

0 commit comments

Comments
 (0)