[ApiVersion(ApiControllerVersion.Version1)]
public class PaymentControllerV1
{
[HttpPost]
[Produces("application/json")]
[SwaggerOperation("POST: make payment")]
[Route("payments/")]
public async Task<IActionResult> PostPayment([FromBody] PaymentRequestDto paymentRequest)
{
}
[HttpGet]
[Produces("application/json")]
[SwaggerOperation("GET: get payment by id")]
[Route("payments/{paymentId}")]
public virtual async Task<IActionResult> GetPayment([FromRoute] int paymentId)
{
}
}
[ApiVersion(ApiControllerVersion.Version2)]
public class PaymentControllerV2: PaymentControllerV1
{
[HttpPost]
[Produces("application/json")]
[SwaggerOperation("POST: make payment")]
[Route("payments/")]
public override async Task<IActionResult> PostPayment([FromBody] PaymentRequestV2Dto paymentRequest)
{
}
}
在第二种情况下,我们使用POST PaymentRequestV2Dto的更多字段更新了请求。
现在,为了避免冗余代码,我们继承了PaymentControllerV1。
如果我运行该应用程序并尝试为V1加载swagger,但对于V2则显示错误500。
如果我从POSTMAN打给v2的电话,则工作正常。
如何解决挥舞错误?