I'm trying to integrate Swagger into a somewhat big vanilla ASP.NET MVC app. I was going to use Swashbuckle or NSwag after reading this article. The problem is my controllers are inhereted from the generic base class like this:
public class BookController : BaseController<Book>
And then I have a GET method in a base class:
public abstract class BaseController<T> : ApiController where T : SomeEntityConstraint
{
...
public virtual IHttpActionResult Get(int id)
{
T queryResult = _repository.Get(id)
...
return Ok(queryResult);
}
}
I was planning to add [SwaggerResponse(HttpStatusCode.OK, typeof(T))]
attribute to a method and this is where I got CSharp'd hard. Apparetnly one can't simply use generic type parameters in an attribute. They must be known at compile time.
I can see from here that ASP.NET Core has a neat ActionResult<TValue>
class. But I can't find a substitute in a vanilla ASP.NET. I wonder what I can do in situation like this without introducing unwanted coupling and methods overriding in concrete Controller classes implementation or moving the project to a brand new ASP.NET Core.