Empty Body Parameter Showing

Given a service interface:

[Route("/Hello2/{Id}", "POST", Summary = "Creates a new hello.")]
    public class CreateHelloReq2 : IReturn<string>
        [ApiMember(IsRequired = true, ParameterType = "path", ExcludeInSchema = true)]
        public string Id { get; set; }

the resultant Swagger UI shows a row for body with an empty set {} expected. In a situation, such as this, we would like for that body row not to be visible at all in the documentation since it adds nothing (the user doesn’t understand what they are supposed to send for the body param). How can we remove it with the OpenApiParameter? In this situation, we don’t want to disable the body for all calls - just this one (or, even better, any call which has an empty body).


Currently you can remove it by using OperationFilter

Plugins.Add(new OpenApiFeature { 
    OperationFilter = (verb, op) =>
        if (op.OperationId == "CreateHelloReq2Id_Post") 
            op.Parameters.RemoveAll(p => p.Name == "body");

Or just wait next build when we’ll add controlling operation body via attributes.

Thanks for the quick response.

There is no remove method that takes an empty on the Parameters collection. Also, to be clear, we do wan’t the Id param showing - just not the body one…

My bad. It should be .Clear() to remove all parameters or RemoveAll(p => p.Name == "body") for removing body parameter only.

I updated the code snippet in the above post.