Swashbuckle.AspNetCore
Swashbuckle.AspNetCore copied to clipboard
How to define base url in swashbuckle 5.0 within asp.net core 3.1
I am using asp.net core 3.1 with swashbuckle 5. I am not able tofind the way for defining base url. RootUrl option seem to be not coming or (may be i am not able to call it)
Please let me know how to define it
private static void SwaggerInjection(IServiceCollection services)
{
services.AddSwaggerGen(x =>
{
x.SwaggerDoc("v1", new OpenApiInfo { Title = "Portal Backend APIs", Version = "v1" });
x.DescribeAllEnumsAsStrings();
x.TagActionsBy(api =>
{
if (api.GroupName != null)
{
return new[] { api.GroupName };
}
var controllerActionDescriptor = api.ActionDescriptor as ControllerActionDescriptor;
if (controllerActionDescriptor != null)
{
return new[] { controllerActionDescriptor.ControllerName };
}
throw new InvalidOperationException("Unable to determine tag for endpoint.");
});
x.DocInclusionPredicate((name, api) => true);
x.AddSecurityDefinition("Bearer", // name the security scheme
new OpenApiSecurityScheme
{
Description = "JWT Authorization header using the Bearer scheme.",
Type = SecuritySchemeType.Http, // we set the scheme type to http since we're using bearer authentication
Scheme = "bearer" // the name of the HTTP Authorization scheme to be used in the Authorization header. In this case "bearer".
});
x.AddSecurityRequirement(new OpenApiSecurityRequirement{
{
new OpenApiSecurityScheme{
Reference = new OpenApiReference{
Id = "Bearer", // the name of the previously defined security scheme.
Type = ReferenceType.SecurityScheme
}
},new List<string>()
}
});
// to show API description and other stuff on swagger
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
x.IncludeXmlComments(xmlPath);
});
}