如何在 webapi 和客户端之间共享 ActionName?

How to share ActionName between webapi and client?

有什么方法可以在客户端和 api 之间共享 webapi ActionNames 吗? 我在以下地方尝试过这样的事情:

public static class Orders
{
    public const string GetAllOrders = "GetOrders";
    public const string GetUserOrders = "GetUserOrders";
    public const string GetCustomerOrders = "GetCustomerOrders";
}

然后在api:

    [HttpGet]
    [ActionName(Orders.GetAllOrders)]
    public IActionResult GetAllOrders()
    {

        return BadRequest("No records found");
    }

    [HttpGet]
    [ActionName(Orders.GetUserOrders)]
    public IActionResult GetUserOrders(int id)
    {
        return BadRequest("No records found");
    }

    [HttpGet]
    [ActionName(Orders.GetCustomerOrders)]
    public IActionResult GetCustomerOrders(int id)
    {
        return BadRequest("No records found");
    }

但是我收到这个错误:

Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination "GET api/Order" for actions - LPD_Api.Controllers.OrderController.GetAllOrders (LPD_Api),LPD_Api.Controllers.OrderController.GetUserOrders (LPD_Api),LPD_Api.Controllers.OrderController.GetCustomerOrders (LPD_Api). Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround

关于如何共享名称以避免在客户端出现命名错误的任何提示?

感谢 Serhii 我解决了这样的问题:

    [HttpGet(Orders.GetAllOrders)]
    public IActionResult GetAllOrders()
    {
        return BadRequest("No records found");
    }

    [HttpGet(Orders.GetUserOrders)]
    public IActionResult GetUserOrders(int id)
    {
        return BadRequest("No records found");
    }

    [HttpGet(Orders.GetCustomerOrders)]
    public IActionResult GetCustomerOrders(int id)
    {
        return BadRequest("No records found");
    }