.NET Core 3.1 Swagger UI Tweaks
- 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();
- Enable XML Comments
- Manually add the two lines in PropertyGroup below to the .csproj file:
<PropertyGroup> <GenerateDocumentationFile>true</GenerateDocumentationFile> <NoWarn>$(NoWarn);1591</NoWarn> </PropertyGroup>
- Add the options in the code below
services.AddSwaggerGen(options => { options.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{AppDomain.CurrentDomain.FriendlyName}.xml"), true); });
- Manually add the two lines in PropertyGroup below to the .csproj file: