ApiExplorer expanding IFormFile into multiple ParameterDescriptions #5673
Description
This behavior was added by #2502. As far as I can tell it expands complex types into multiple ParameterDescriptions unless the parameter has a BindingSource of "body". While the expansion is really convenient for documenting complex types with a BindingSource of "query" or "form", it makes it very tricky for ApiExplorer consumers (e.g. Swashbuckle.AspNetCore) to document parameters of type IFormFile. In this case it would be ideal to have a single parameter of type IFormFile.
In fact, this is a problem for other "special" parameter types as well. For example, CancellationToken. A tool like Swashbuckle needs to omit this parameter from API docs (e.g. Swagger). But, rather than omitting ParameterDescriptions with a type CancellationToken it needs to omit all params that are likely "part of" an expanded CancellationToken. Today, it uses the following code for this:
public static bool IsPartOfCancellationToken(this ApiParameterDescription parameterDescription)
{
if (parameterDescription.Source != BindingSource.ModelBinding) return false;
var name = parameterDescription.Name;
return name == "CanBeCanceled"
|| name == "IsCancellationRequested"
|| name.StartsWith("WaitHandle.");
}
}
Not sure if I've explained this well. Let me know if it makes sense