I'm using NSwag for .NET Core 3.1. Everything works correctly.
I can't determine how to change "My Title" (which is the info title) to something else.
Here is the swagger page:
Here is my registration code:
app.UseOpenApi();
app.UseSwaggerUi3(c => c.DocumentTitle = "My Api");
Any help is very much appreciated. Thanks!
Just set the Title
property when calling AddSwaggerDocument
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerDocument(settings =>
{
settings.Title = "My Own Title";
});
}
As far as I know, if you want to modify the nswagtitle. You should modify AddSwaggerDocument config setting in the ConfigureServices method as below:
Details you could refer to below codes:
services.AddSwaggerDocument(config =>
{
config.PostProcess = document =>
{
//document.Info.Version = "v1";
document.Info.Title = "ToDo API";
//document.Info.Description = "A simple ASP.NET Core web API";
//document.Info.TermsOfService = "None";
//document.Info.Contact = new NSwag.OpenApiContact
//{
// Name = "Shayne Boyer",
// Email = string.Empty,
// Url = "https://twitter.com/spboyer"
//};
//document.Info.License = new NSwag.OpenApiLicense
//{
// Name = "Use under LICX",
// Url = "https://example.com/license"
//};
};
});
Details startup.cs codes:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.Negotiate;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace CoreNormalIssue
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();
services.AddControllersWithViews();
services.AddSwaggerDocument(config =>
{
config.PostProcess = document =>
{
//document.Info.Version = "v1";
document.Info.Title = "ToDo API";
//document.Info.Description = "A simple ASP.NET Core web API";
//document.Info.TermsOfService = "None";
//document.Info.Contact = new NSwag.OpenApiContact
//{
// Name = "Shayne Boyer",
// Email = string.Empty,
// Url = "https://twitter.com/spboyer"
//};
//document.Info.License = new NSwag.OpenApiLicense
//{
// Name = "Use under LICX",
// Url = "https://example.com/license"
//};
};
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseOpenApi();
app.UseSwaggerUi3();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Default}/{action=Index}/{id?}");
});
}
}
}
Result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With