diff --git a/endpoint/endpoint.go b/endpoint/endpoint.go index 50c1b94..abb4a06 100644 --- a/endpoint/endpoint.go +++ b/endpoint/endpoint.go @@ -192,6 +192,12 @@ func FormData(name string, typ types.ParameterType, description string, required } } +// BodyR defines a body parameter for the swagger endpoint as would commonly be used for the POST, PUT, and PATCH methods +// prototype should be a struct or a pointer to struct that swag can use to reflect upon the return type +func BodyR(prototype interface{}) Option { + return bodyType(reflect.TypeOf(prototype), "", true) +} + // Body defines a body parameter for the swagger endpoint as would commonly be used for the POST, PUT, and PATCH methods // prototype should be a struct or a pointer to struct that swag can use to reflect upon the return type func Body(prototype interface{}, description string, required bool) Option { diff --git a/endpoint/endpoint_test.go b/endpoint/endpoint_test.go index 380b3c1..17d6416 100644 --- a/endpoint/endpoint_test.go +++ b/endpoint/endpoint_test.go @@ -206,6 +206,27 @@ type Model struct { String string `json:"s"` } +func TestBodyR(t *testing.T) { + expected := swag.Parameter{ + In: "body", + Name: "body", + Required: true, + Schema: &swag.Schema{ + Ref: "#/definitions/endpoint.Model", + Prototype: reflect.TypeOf(Model{}), + }, + } + + e := New( + "get", "/", + Summary("get thing"), + BodyR(Model{}), + ) + + assert.Equal(t, 1, len(e.Parameters)) + assert.Equal(t, expected, e.Parameters[0]) +} + func TestBody(t *testing.T) { expected := swag.Parameter{ In: "body",