title: How use OData filters with swagger in an asp.net core WebApi project?
body: <p>I have an web API written using C# on the top of ASP.NET 5/core with EntityFrameworkCore.</p>
  <p>I am using <a href="https://www.nuget.org/packages/Microsoft.AspNetCore.OData/" rel="nofollow noreferrer">OData</a> to apply filters on when querying the database.</p>
  <p>I need to manually apply the <code>ODataQueryOptions</code> to my <code>DbSet&lt;&gt;</code> to generate paged info.</p>
  <p>Here is my code</p>
  <pre><code>[Route(&quot;api/[controller]&quot;)]
  [ApiController]
  public class ProductsController : ControllerBase
  {
      private readonly DbContext _db;
  
      public ProductsController(DbContext db)
      {
          _db = db;
      }
  
      [HttpGet]
      [EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All, AllowedFunctions = AllowedFunctions.AllFunctions, MaxTop = 500)]
      public PagedProduct Search(ODataQueryOptions&lt;Product&gt; queryOptions)
      {
          // create a query for that would count the total rows
          var countQuery = queryOptions.ApplyTo(Repository.Query(),  AllowedQueryOptions.Top | AllowedQueryOptions.Skip) as IQueryable&lt;Product&gt;;
  
          // create a query to pull the data
          var query = queryOptions.ApplyTo(Repository.Query()) as IQueryable&lt;Product&gt;;
  
          var result = new PagedProduct()
          {
              CurrentPage = 1, // TODO get the current page value from the queryOptions
              PageSize = 100,  // TODO get the page size value from the queryOptions
          };
  
          result.TotalRecords = await countQuery.Count();
          result.Data = await query.ToList();
  
          return result;
      }
  }
  </code></pre>
  <p>But the above code cause Swagger UI to fail. I get the following error</p>
  <blockquote>
  <p>Fetch error
  undefined /swagger/v1/swagger.json</p>
  </blockquote>
  <p>That error is caused by using <code>ODataQueryOptions</code> as parameter into the Search action.</p>
  <p>How can I get the Swagger UI to work with <code>ODataQueryOptions</code>?</p>