Error: Action has more than one parameter bound from request body

前端 未结 6 1199
死守一世寂寞
死守一世寂寞 2021-01-11 14:15

I wrote a new method into my Controller of my ASP.Net MVC project and getting error below. I think InvalidOperationException coming from with Swagger. I marked

6条回答
  •  误落风尘
    2021-01-11 14:33

    Another possible solution is to nest the complex data types in a tuple:

    [ApiExplorerSettings(IgnoreApi = true)]
    public decimal CalculatePriceWithCampaign((BeverageCapacityCampaign campaign, BeverageCapacity capacity) data, int count = 1)
    {
        switch (data.campaign.DiscountType)
        {
            case DiscountType.Fixed:
                return (data.capacity.CapacityPrice - data.campaign.DiscountValue) * count;
            case DiscountType.Percentage:
                return (data.capacity.CapacityPrice * count) * data.campaign.DiscountValue;
            default:
                return data.capacity.CapacityPrice;
        }
    }
    

    However, NSwag (Swagger) does not seems to be able to automatically parse this case because a non-valid example gets generated. NSwagStudio recognizes the case correctly and generates valid client code.

提交回复
热议问题