RA.Utilities.OpenApi
Version 10.0.0
Updated the project version from 10.0.0-rc.2 to 10.0.0, indicating a transition from release candidate to official stable release.
This change suggests that the OpenAPI utilities have reached a level of stability and feature completeness deemed ready for production use.
Version 10.0.0-rc.2
This release of RA.Utilities.OpenApi provides a robust set of tools to enhance and customize OpenAPI (Swagger) documentation in ASP.NET Core applications. It automates common modifications to your generated OpenAPI specification, reducing boilerplate and enforcing consistency.
✨ Key Features
-
DocumentInfoTransformer: Populates the top-levelinfoobject of your OpenAPI document (title, version, description, etc.) directly from yourappsettings.jsonconfiguration, allowing you to update documentation details without code changes. -
BearerSecuritySchemeTransformer: Automatically adds a "Bearer" security scheme to your OpenAPI document when JWT authentication is detected, enabling the "Authorize" button in Swagger UI for testing protected endpoints. -
HeadersParameterTransformer: Adds common, configurable headers (likex-request-id) to every API operation, ensuring consistent documentation for tracing and correlation in distributed systems. -
ResponsesDocumentTransformer: Automatically adds standardized OpenAPI responses for common HTTP status codes (400,404,409,500), using schema models fromRA.Utilities.Api.Resultsto ensure your error contracts are clearly documented. -
Simplified Setup: Includes an
AddDefaultsDocumentTransformer()extension method to register the most common transformers (DocumentInfo,BearerSecurityScheme, andHeadersParameter) with a single line of code. -
Configuration-Driven: All transformers are configurable via
appsettings.jsonusing strongly-typed settings classes (OpenApiInfoSettings,HeadersParameterSettings), keeping your application code clean and focused.
🚀 Getting Started
- Configure Settings: Add
OpenApiInfoSettingsandOpenApiHeaderssections to yourappsettings.json. - Register Services: In
Program.cs, configure the settings classes:builder.Services.Configure<OpenApiInfoSettings>(builder.Configuration.GetSection(OpenApiInfoSettings.AppSettingsKey));
builder.Services.Configure<HeadersParameterSettings>(builder.Configuration.GetSection("OpenApiHeaders")); - Add Transformers: Use the extension methods to register the transformers:
builder.Services.AddOpenApi()
.AddDefaultsDocumentTransformer(); // Adds Info, Bearer, and Headers transformers
// Register other transformers individually
builder.Services.AddOpenApiDocumentTransformer<ResponsesDocumentTransformer>(); - Map Endpoints: Finally, map the OpenAPI endpoints in your request pipeline:
app.MapOpenApi();