title: Swashbuckle blocked by middleware authentication
body: <p>I'm creating a minimal API in dotnet 6. I have the default implementation of Swagger/Swashbuckle and everything was fine until I added a simple, custom authentication middleware (see code below).</p>
  <p>The problem is, the middleware runs against <code>/swagger/index.html</code> which doesn't contain the API Key in the header and returns a 400 error (per the first <code>if</code> statement below). How can I fix this?</p>
  <p><code>Program.cs</code></p>
  <pre><code>app.UseMiddleware&lt;Auth&gt;();
  </code></pre>
  <p><code>Auth.cs</code></p>
  <pre><code>    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
      {
          if (!context.Request.Headers.ContainsKey(&quot;ApiKey&quot;))
          {
              context.Response.StatusCode = StatusCodes.Status400BadRequest;
  
              await context.Response.WriteAsync(&quot;No ApiKey provided in headers&quot;);
          }
  
          if (!Guid.TryParse(context.Request.Headers[&quot;ApiKey&quot;], out var apiKey))
          {
              context.Response.StatusCode = StatusCodes.Status400BadRequest;
  
              await context.Response.WriteAsync(&quot;Unable to parse the ApiKey&quot;);
          }
  
          try
          {
              /* Look in DB for API Key yada yada yada */
          }
          catch
          {
              context.Response.StatusCode = StatusCodes.Status401Unauthorized;
  
              await context.Response.WriteAsync(&quot;Unauthorized&quot;);
          }
  
          await next(context);
      }
  </code></pre>