title: ASP.NET Core 2.2 - ProblemDetails
body: <p>I've upgraded my ASP.NET Core project with Swagger support to 2.2 recently. I noticed that all my error responses now show with a ProblemDetails response body.</p>
  
  <pre><code>{
    "type": "string",
    "title": "string",
    "status": 0,
    "detail": "string",
    "instance": "string",
    "additionalProp1": {},
    "additionalProp2": {},
    "additionalProp3": {}
  }
  </code></pre>
  
  <p>According to <a href="https://docs.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-2.2?view=aspnetcore-2.2" rel="nofollow noreferrer">Microsoft</a> this is expected - and I'm happy with it. </p>
  
  <p>However, for some reason my project does not return these for some default return codes such as 401. This is (what I believe is) the relevant part of my startup config.</p>
  
  <pre><code>    services
          .AddAuthentication(options =&gt; {
              options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
          })
          .AddJwtBearer(jwtOptions =&gt; {
              jwtOptions.Authority = jwtConfiguration.Authority;
              jwtOptions.TokenValidationParameters.ValidAudiences = jwtConfiguration.Audiences;
          });
  
      // Add framework services.
      services
          .AddMvcCore(options =&gt; {
              options.Filters.Add&lt;OperationCancelledExceptionFilterAttribute&gt;();
          })
          .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
          .AddAuthorization()
          .AddApiExplorer()
          .AddJsonFormatters()
          .AddCors()
          .AddJsonOptions(options =&gt; options.SerializerSettings.Converters.Add(new StringEnumConverter()));
  
      services.AddVersionedApiExplorer(
          options =&gt; {
              //The format of the version added to the route URL  
              options.GroupNameFormat = "'v'VVV";
              //Tells swagger to replace the version in the controller route  
              options.SubstituteApiVersionInUrl = true;
          });
  
      services.AddApiVersioning(option =&gt; {
          option.ReportApiVersions = true;
      });
  
      // Add data protection
      services.AddDataProtection();
  
      //Add swagger
      services.AddSwaggerGen(c =&gt; {
          c.SwaggerDoc("v1", new Info { Version = "1.0", ...});
          c.SwaggerDoc("v2", new Info { Version = "2.0", ...});
          c.AddSecurityDefinition("Bearer", ...});
          c.AddSecurityRequirement(...);
          c.DescribeAllEnumsAsStrings();
          c.EnableAnnotations();
      });
  
      //Add documentation for end point
      services.AddSwaggerGen(...});
  </code></pre>
  
  <p>With this setup any unauthorized request ends up in a 401, but without any problem details attached. That's not what I understood should happen, and I cannot figure out which switch I need to press to make it happen. </p>