4,826 questions
Swagger UI How to generate documentation

Cenk
1,036
Reputation points
Hi there,
In my ASP.NET Core 6 Web API application I am using Swagger UI. I wonder if I can somehow generate a PDF document from Swagger? Or any other ways to do it?
Thank you.
builder.Services.AddSwaggerGen(c =>
{
c.EnableAnnotations();
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Palas API",
Version = "v1",
Description = "Online Game Code Transactions",
Contact = new OpenApiContact
{
Name = "Palas Support",
Email = "******@destek.com"
}
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "bearer"
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
//builder.Services.Configure<ApiBehaviorOptions>(options
// => options.SuppressModelStateInvalidFilter = true);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment() || app.Environment.IsProduction())
{
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger(option =>
{
option.RouteTemplate = "Palas/{documentName}/swagger.json";
});
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/Palas/v1/swagger.json", "Palas API");
c.InjectStylesheet("/swagger-ui/theme-material.css");
c.RoutePrefix = "Palas";
c.DefaultModelsExpandDepth(-1);
});
}
Developer technologies | ASP.NET | ASP.NET Core
Sign in to answer