title: Swagger API breaks when Route attribute is set to Controller Action - ASP.NET Core
body: <p>I am using ASP.NET Core 3.1. In My Web Application I have integrated swagger. Which works fine, shows the endpoints properly in the swagger API documentation. The code in startup is as below:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
              services.AddSwaggerGen( c =&gt; {
                  c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
              });
  }
  
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllerRoute(
                      name: "default",
                      pattern: "{controller=Clients}/{action=Index}/{id?}");
              });
  
              app.UseSwagger();
              app.UseSwaggerUI(c =&gt; {
                  c.SwaggerEndpoint("/swagger/v1/swagger.json", "Push Notification API V1");
              });
  
           }
  </code></pre>
  
  <p>To my Error Controller I just added a HttpStatusCodeHandler method and gave a route as below.
  Then the swagger gives a error as:</p>
  
  <blockquote>
    <p>"Failed to load API definition." Fetch error undefined
    /swagger/v1/swagger.json</p>
  </blockquote>
  
  <p>The method code is as follows.</p>
  
  <pre><code>[Route("Error/Error/{statusCode}")]
  public IActionResult HttpStatusCodeHandler(int statusCode)
  {
      switch (statusCode)
      {
          case 404:
              ViewBag.ErrorMessage = "Sorry, the resource you requested could not be found.";
              break;
      }
      return View("Error");
  }
  </code></pre>
  
  <p>Every time I comment out the Route attribute <code>[Route("Error/Error/{statusCode}")]</code> the swagger API works fine. What could be the error in this?</p>