如何使用查询参数中的枚举名称发送 HTTP 请求

How to send an HTTP Request by using name of the Enum in query parameter

我试图将枚举值作为查询参数传递给 Post 请求,但它不接受该值?当我尝试从 Swagger 发送请求时,它甚至没有发送请求。

注意:我使用 Newtonsof.Json 库并且我还在启动中添加了配置

services.AddMvc(opt =>
{
    ...
})
.AddNewtonsoftJson(options =>
{
     options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
     options.SerializerSettings.Converters.Add(new StringEnumConverter());
});

public enum CardBrand
{
     [Description("MASTER")]
     MASTER,
     [Description("PAYPAL")]
     PAYPAL,
     [Description("VISA")]
     VISA
}

[HttpPost("{orderId}")]        
public async Task<ResponseModel<bool>> RandomTask(string orderId, CardBrand cardBrand)
{
    return await _orderService.UpdatePayment(orderId, cardBrand);
}

Swagger screenshot

Swagger 具有 DescribeAllEnumsAsStrings 函数,该函数在版本 5.0.0 上可用。我通过使用此功能解决了我的问题。我希望它也适用于其他人