title: Asp.Net Core swagger Help Pages for IFormFile
body: <p>I am trying to setup swagger for testing models which have IFormFile properties.
  For example I have next api method</p>
  
  <pre><code>[HttpPost]
  public ApiResult&lt;UserModel&gt; SaveTestFileData([FromForm]TestPostFileArgs args)
  {
      var result = new UserModel() { Id = 1, Name = $"SaveTestFileData {args.UserId} company: {args.CompanyId}, file length: {args.CompanyFile.Length}" };
      return ApiResult.Success(result);
  }
  </code></pre>
  
  <p>And my parameter model</p>
  
  <pre><code>public class TestPostFileArgs
  {
      public int UserId { get; set; }
      public int? CompanyId { get; set; }
      public IFormFile CompanyFile { get; set; }
  }
  </code></pre>
  
  <p>By default swagger generate help page which does not allow to test it
  <a href="https://i.stack.imgur.com/0wnx0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0wnx0.png" alt="Wrong swagger ui"></a>
  To solve this problem I wrote next OperationFilter</p>
  
  <pre><code>public class FormFileOperationFilter: IOperationFilter
  {
      public void Apply(Operation operation, OperationFilterContext context)
      {
          if (operation.Parameters == null)
              return;
  
          var fileParamNames = context.ApiDescription.ActionDescriptor.Parameters
              .SelectMany(x =&gt; x.ParameterType.GetProperties())
              .Where(x =&gt; x.PropertyType.IsAssignableFrom(typeof (IFormFile)))
              .Select(x =&gt; x.Name)
              .ToList();
          if (!fileParamNames.Any())
              return;
  
          var paramsToRemove = new List&lt;IParameter&gt;();
          foreach (var param in operation.Parameters)
          {
              paramsToRemove.AddRange(from fileParamName in fileParamNames where param.Name.StartsWith(fileParamName + ".") select param);
          }
          paramsToRemove.ForEach(x =&gt; operation.Parameters.Remove(x));
          foreach (var paramName in fileParamNames)
          {
              var fileParam = new NonBodyParameter
                  {
                      Type = "file",
                      Name = paramName,
                      In = "formData"
                  };
              operation.Parameters.Add(fileParam);
          }
          foreach (IParameter param in operation.Parameters)
          {
              param.In = "formData";
          }
  
          operation.Consumes = new List&lt;string&gt;() { "multipart/form-data" };
      }
  }
  </code></pre>
  
  <p>And after this everething works as I expect from swagger.
  <a href="https://i.stack.imgur.com/z0dr3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/z0dr3.png" alt="Correct swagger ui"></a></p>
  
  <p>For now this solution works for me, but it feels not right. Maybe I am missing some simple solution for this. Also this approach does not handle List or complex object properties with IFormFile or maybe something else.</p>