Fast.Swagger
Public members, parameters, returns, and exceptions
Targets: net8.0;net9.0;net10.0.
Contract and constraints
Swagger JSON, grouping and UI integration. AddSwaggerDocuments() defaults to SwaggerSettings. Configuration-section registration applies PostConfigure, whereas the callback overload does not automatically do so. UseSwaggerDocuments() enables middleware according to Enable. Defaults include Enable=true, DocumentTitle="Specification Api Document", DefaultGroupName="Default", FormatAsV2=false and RouteTemplate="swagger/{documentName}/swagger.json". An unset RoutePrefix places the UI at the site root. EnableAuthorized configures documentation security definitions; it does not secure access to the documentation. SwaggerDocumentBuilder grouping APIs depend on initialized MVC descriptions. SchemaIdAttribute and OperationIdAttribute control generated identifiers. Response metadata documents a contract but does not verify the runtime actually returns that response.
Installation and examples
Install the package
dotnet add package Fast.SwaggerExample 1
using Fast.Swagger;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddSwaggerDocuments(builder.Configuration);
var app = builder.Build();
app.UseSwaggerDocuments();
app.MapControllers();
app.Run();Example 2
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/catalog")]
public sealed class CatalogController : ControllerBase
{
[HttpGet("{id:int}")]
[ProducesResponseType(typeof(CatalogItem), 200)]
public ActionResult<CatalogItem> Get(int id) => new CatalogItem(id, "示例商品");
}
public sealed record CatalogItem(int Id, string Name);Web-host examples belong in a consumer project using Microsoft.NET.Sdk.Web and a supported .NET target. IaaS examples can be used in an ordinary class library. Registration precedes builder.Build(); configure middleware and endpoints before app.Run(). Samples retain their original code and comments. No host, external service, database operation or client generator was run, and these snippets have not been compiled in this update.
