How can I use inheritance and swagger mechanisms in my API at the same time?

265 Views Asked by At

Most of my methods in the API are implemented according to the following scheme:

[Route("api/[controller]")]
public class SomeController : ApiContriollerBase<SomeRequestModel>
{
    public override void Method1() => throw new NotImplementedException();
}


[Produces("application/json")]
public abstract class ApiContriollerBase<TRequest> : ControllerBase
    where TRequest : new()
{
    TRequest ApiRequest = new TRequest();

    ApiResponse ApiResponse = new ApiResponse();

    [HttpPost]
    public ApiResponse EntryPoint([FromBody] TRequest request)
    {
        // Do something. Method1(), Method2()...

        return ApiResponse;
    }

    // Some virtual methods
    public virtual void Method1() => throw new NotImplementedException();
    public virtual object Method2() => throw new NotImplementedException();
}

When I try to use swagger, it fails to generate swagger.json and gives an error: "Fetch errorundefined /swagger/v1/swagger.json". As far as I understand, swagger cannot understand my request mechanism. I really don't want to change this circuit because of swagger. Is there any other way to fix the error?

0

There are 0 best solutions below