@@ -16,6 +16,7 @@ package endpoint
1616
1717import (
1818 "net/http"
19+ "reflect"
1920 "strconv"
2021 "strings"
2122
@@ -113,17 +114,24 @@ func Query(name, typ, description string, required bool) Option {
113114
114115// Body defines a body parameter for the swagger endpoint as would commonly be used for the POST, PUT, and PATCH methods
115116// prototype should be a struct or a pointer to struct that swag can use to reflect upon the return type
116- func Body (prototype interface {}, description string , required bool ) Option {
117+ // t represents the Type of the body
118+ func BodyType (t reflect.Type , description string , required bool ) Option {
117119 p := swagger.Parameter {
118120 In : "body" ,
119121 Name : "body" ,
120122 Description : description ,
121- Schema : swagger .MakeSchema (prototype ),
123+ Schema : swagger .MakeSchema (t ),
122124 Required : required ,
123125 }
124126 return parameter (p )
125127}
126128
129+ // Body defines a body parameter for the swagger endpoint as would commonly be used for the POST, PUT, and PATCH methods
130+ // prototype should be a struct or a pointer to struct that swag can use to reflect upon the return type
131+ func Body (prototype interface {}, description string , required bool ) Option {
132+ return BodyType (reflect .TypeOf (prototype ), description , required )
133+ }
134+
127135// Tags allows one or more tags to be associated with the endpoint
128136func Tags (tags ... string ) Option {
129137 return func (b * Builder ) {
@@ -180,16 +188,17 @@ func Header(name, typ, format, description string) ResponseOption {
180188 }
181189}
182190
183- // Response sets the endpoint response for the specified code; may be used multiple times with different status codes
184- func Response (code int , prototype interface {}, description string , opts ... ResponseOption ) Option {
191+ // ResponseType sets the endpoint response for the specified code; may be used multiple times with different status codes
192+ // t represents the Type of the response
193+ func ResponseType (code int , t reflect.Type , description string , opts ... ResponseOption ) Option {
185194 return func (b * Builder ) {
186195 if b .Endpoint .Responses == nil {
187196 b .Endpoint .Responses = map [string ]swagger.Response {}
188197 }
189198
190199 r := swagger.Response {
191200 Description : description ,
192- Schema : swagger .MakeSchema (prototype ),
201+ Schema : swagger .MakeSchema (t ),
193202 }
194203
195204 for _ , opt := range opts {
@@ -200,6 +209,11 @@ func Response(code int, prototype interface{}, description string, opts ...Respo
200209 }
201210}
202211
212+ // Response sets the endpoint response for the specified code; may be used multiple times with different status codes
213+ func Response (code int , prototype interface {}, description string , opts ... ResponseOption ) Option {
214+ return ResponseType (code , reflect .TypeOf (prototype ), description , opts ... )
215+ }
216+
203217// New constructs a new swagger endpoint using the fields and functional options provided
204218func New (method , path , summary string , options ... Option ) * swagger.Endpoint {
205219 method = strings .ToUpper (method )
0 commit comments