I have an api app where the controller method takes a class as input. I'm using Swagger to show the user what variables are in that class. I used the class for other purposes so for certain methods I'd like Swagger not to show certain objects. I tried the attribute [IgnoreDataMember] mentioned here, but it didn't seem to do anything. How can I prevent Swagger from showing every object in the input class?
So here is the method definition:
[HttpPost("Receive")]
[Produces("application/json", Type = typeof(APIResponse))]
public APIResponse Receive(MyClass item)
{....}
MyClass is defined with 4 objects:
public class MyClass
{
[IgnoreDataMember]
public int itemID { get; set; }
[IgnoreDataMember]
public int quantity { get; set; }
public int vendor_id { get; set; }
public string ship_name { get; set; }
}
Right now, Swagger shows all 4 objects as parameters:
For this method, I'd like to only show 2 of the 4 class objects as parameters. For other methods, I'll need to show all 4. Is there a way to do this or will I need to create a class for each method?