From 167f77669f982f6559980e0193aa090b600d46c7 Mon Sep 17 00:00:00 2001 From: caixw Date: Mon, 25 Nov 2024 14:24:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(openapi):=20=E5=85=81=E8=AE=B8=20Opera?= =?UTF-8?q?tion.Response=20=E7=9A=84=20resp=20=E4=B8=BA=20nil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi/middleware.go | 8 +++++--- openapi/openapi.go | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/openapi/middleware.go b/openapi/middleware.go index f61eb45e..be41de1a 100644 --- a/openapi/middleware.go +++ b/openapi/middleware.go @@ -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) } diff --git a/openapi/openapi.go b/openapi/openapi.go index 993e3922..c787e159 100644 --- a/openapi/openapi.go +++ b/openapi/openapi.go @@ -45,6 +45,8 @@ const ( ) const ( + FormatBinary = "binary" + FormatByte = "byte" FormatInt32 = "int32" FormatInt64 = "int64" FormatFloat = "float"