diff --git a/responses/validate_body_test.go b/responses/validate_body_test.go index f9c30ed..af6c80b 100644 --- a/responses/validate_body_test.go +++ b/responses/validate_body_test.go @@ -532,7 +532,9 @@ paths: response := &http.Response{ Header: http.Header{}, StatusCode: http.StatusOK, - Body: nil, // invalid response body + // The http Client and Transport guarantee that Body is always non-nil + // and will be set to [http.NoBody] if no body is present. + Body: http.NoBody, } response.Header.Set(helpers.ContentTypeHeader, helpers.JSONContentType) diff --git a/responses/validate_response.go b/responses/validate_response.go index a93fe7b..e73deff 100644 --- a/responses/validate_response.go +++ b/responses/validate_response.go @@ -45,7 +45,7 @@ func ValidateResponseSchema( var validationErrors []*errors.ValidationError - if response == nil || response.Body == nil { + if response == nil || response.Body == http.NoBody { // cannot decode the response body, so it's not valid violation := &errors.SchemaValidationFailure{ Reason: "response is empty",