After adding a new method to a controller, my OpenAPI(Swagger) endpoint started to complain with the following error message:
Conflicting method/path combination "POST api/Orders" for actions - eShopExample.Web.Controllers.OrdersController.CreateOrder (eShopExample),eShopExample.Web.Controllers.OrdersController.ProcessOrders (eShopExample). Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround
I find the error message itself not very insightful but taking a look at my OrdersController made it all clear:
public class OrderController: Controller | |
{ | |
// POST api/order | |
[HttpPost] | |
[ProducesResponseType(StatusCodes.Status200OK)] | |
[ProducesResponseType(StatusCodes.Status400BadRequest)] | |
public async Task<ActionResult> CreateOrder(OrderProductCommand command) | |
{ | |
var order = await _orderService.OrderProduct(command); | |
await _publishEndpoint.Publish(new PlaceOrderMessage { OrderId = order.Id }); | |
return Ok(); | |
} | |
[HttpPost] | |
[ProducesResponseType(StatusCodes.Status200OK)] | |
[ProducesResponseType(StatusCodes.Status400BadRequest)] | |
public async Task<ActionResult> ProcessOrders(ICollection<Guid> orderIds) | |
{ | |
var serviceClient = _busControl.CreateServiceClient(); | |
var requestClient = serviceClient.CreateRequestClient<ProcessOrdersJob>(); | |
var response = await requestClient.GetResponse<JobSubmissionAccepted>(new ProcessOrdersJob | |
{ | |
JobId = Guid.NewGuid(), | |
OrderIds = new List<Guid>(orderIds) | |
}); | |
return Ok(response); | |
} | |
} |
The problem was that I had 2 methods that were both using attribute based routing(through the [HttpPost] attribute) but where resolved to the same URI; āapi/ordersā. To fix it I had to use an overload of the [HttpPost] attribute and specify an alternative URI:
[HttpPost("processorders")] | |
[ProducesResponseType(StatusCodes.Status200OK)] | |
[ProducesResponseType(StatusCodes.Status400BadRequest)] | |
public async Task<ActionResult> ProcessOrders(ICollection<Guid> orderIds) | |
{ | |
var serviceClient = _busControl.CreateServiceClient(); | |
var requestClient = serviceClient.CreateRequestClient<ProcessOrdersJob>(); | |
var response = await requestClient.GetResponse<JobSubmissionAccepted>(new ProcessOrdersJob | |
{ | |
JobId = Guid.NewGuid(), | |
OrderIds = new List<Guid>(orderIds) | |
}); | |
return Ok(response); | |
} |