.NET Core 3.1 Swagger UI Tweaks

  1. Present enums as string. Modify your StartUp.cs, add the highlight part below:
             services.AddMemoryCache().AddMvcCore().AddJsonOptions(opts =>
                 {
                     opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                 })
                 .AddDataAnnotationsLocalization();
    

  1. Enable XML Comments
    1. Manually add the two lines in PropertyGroup below to the .csproj file:
      <PropertyGroup>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
        <NoWarn>$(NoWarn);1591</NoWarn>
      </PropertyGroup>
      
    2. Add the options in the code below
           services.AddSwaggerGen(options =>
           {
               options.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{AppDomain.CurrentDomain.FriendlyName}.xml"), true);
           });