Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,17 @@ internal static bool IsFromBody(this ApiParameterDescription apiParameter)

internal static bool IsFromForm(this ApiParameterDescription apiParameter)
{
bool isEnhancedModelMetadataSupported = true;

#if NET9_0_OR_GREATER
if (AppContext.TryGetSwitch("Microsoft.AspNetCore.Mvc.ApiExplorer.IsEnhancedModelMetadataSupported", out var isEnabled))
{
isEnhancedModelMetadataSupported = isEnabled;
}
#endif

var source = apiParameter.Source;
var elementType = apiParameter.ModelMetadata?.ElementType;
var elementType = isEnhancedModelMetadataSupported ? apiParameter.ModelMetadata?.ElementType : null;

return (source == BindingSource.Form || source == BindingSource.FormFile)
|| (elementType != null && typeof(IFormFile).IsAssignableFrom(elementType));
Expand Down