TinyHelpers.AspNetCore.Swashbuckle
4.0.46
See the version list below for details.
dotnet add package TinyHelpers.AspNetCore.Swashbuckle --version 4.0.46
NuGet\Install-Package TinyHelpers.AspNetCore.Swashbuckle -Version 4.0.46
<PackageReference Include="TinyHelpers.AspNetCore.Swashbuckle" Version="4.0.46" />
<PackageVersion Include="TinyHelpers.AspNetCore.Swashbuckle" Version="4.0.46" />
<PackageReference Include="TinyHelpers.AspNetCore.Swashbuckle" />
paket add TinyHelpers.AspNetCore.Swashbuckle --version 4.0.46
#r "nuget: TinyHelpers.AspNetCore.Swashbuckle, 4.0.46"
#:package TinyHelpers.AspNetCore.Swashbuckle@4.0.46
#addin nuget:?package=TinyHelpers.AspNetCore.Swashbuckle&version=4.0.46
#tool nuget:?package=TinyHelpers.AspNetCore.Swashbuckle&version=4.0.46
Tiny Helpers for Swashbuckle ASP.NET Core
TinyHelpers.AspNetCore.Swashbuckle is a small collection of practical helpers for Swashbuckle ASP.NET Core applications. It keeps common Swagger configuration in one place so applications can reuse the same OpenAPI conventions without duplicating setup code across startup files.
Compatibility
The package targets:
- .NET 8
- .NET 9
- .NET 10
It is designed to be used with Swashbuckle.AspNetCore
and AddSwaggerGen(...).
Installation
Install the package from NuGet:
dotnet add package TinyHelpers.AspNetCore.Swashbuckle
Or search for TinyHelpers.AspNetCore.Swashbuckle in the Visual Studio Package Manager.
Contents
Swagger and OpenAPI helpers
SwaggerExtensions
| Method | What it does | When to use it |
|---|---|---|
AddAcceptLanguageHeader() |
Adds the Accept-Language header to documented operations when the app has supported cultures. |
When your API uses request localization and you want consumers to discover the supported culture values. |
AddDefaultProblemDetailsResponse() |
Adds a default application/problem+json response to operations. |
When you want a consistent error contract in Swagger UI and generated documents. |
AddTimeSpanTypeMapping(bool useCurrentTimeAsExample = false) |
Maps TimeSpan to a string schema and optionally adds a readable example. |
When your API exposes TimeSpan values and you want a clearer schema. |
AddTimeSpanTypeMapping(string? example) |
Maps TimeSpan to a string schema using a custom example value. |
When you want a precise sample that matches your API format. |
AddSwaggerOperationParameters(Action<OpenApiOperationOptions> setupAction) |
Registers reusable OpenAPI parameters in the dependency injection container. | When you want to define shared parameters once and reuse them in Swagger generation. |
AddOperationParameters() |
Adds the parameters configured through OpenApiOperationOptions. |
When you want the shared parameters to appear in the generated Swagger operations. |
Example
using Microsoft.OpenApi;
using TinyHelpers.AspNetCore.Swagger;
builder.Services.AddSwaggerGen(options =>
{
options.AddAcceptLanguageHeader();
options.AddDefaultProblemDetailsResponse();
options.AddTimeSpanTypeMapping(useCurrentTimeAsExample: true);
options.AddOperationParameters();
});
builder.Services.AddSwaggerOperationParameters(parameters =>
{
parameters.Parameters.Add(new OpenApiParameter
{
Name = "X-Correlation-Id",
In = ParameterLocation.Header,
Required = false,
Description = "Identifier used to correlate requests"
});
});
Schema helpers
OpenApiSchemaHelper
This helper provides ready-to-use schema fragments that can be reused when building custom Swagger filters or other OpenAPI customizations.
| Method | What it does | When to use it |
|---|---|---|
CreateStringSchema(string? defaultValue = null) |
Creates a string schema with an optional default value. | When you want a simple reusable string schema. |
CreateSchema<TValue>(JsonSchemaType type, string? format = null) |
Creates a schema with an explicit OpenAPI type and format. | When you want a primitive schema and prefer the typed helper overload. |
CreateSchema<TValue>(JsonSchemaType type, string? format, TValue? defaultValue = null) |
Creates a schema with a typed default value. | When you want to document a primitive value and its default. |
CreateSchema(IEnumerable<string> values, string? defaultValue = null) |
Creates a string schema with an enumeration of allowed values. | When the field is constrained to a fixed set of strings. |
CreateSchema<TEnum>(TEnum? defaultValue = null) |
Creates a string schema from an enum type. | When you want the enum names to appear as OpenAPI values. |
Example
using TinyHelpers.AspNetCore.Swagger;
var cultureSchema = OpenApiSchemaHelper.CreateSchema(["it-IT", "en-US"], "it-IT");
var durationSchema = OpenApiSchemaHelper.CreateStringSchema("00:30:00");
Example with an enum
public enum ExportFormat
{
Csv,
Json,
Xml
}
var schema = OpenApiSchemaHelper.CreateSchema<ExportFormat>(ExportFormat.Json);
Quick examples
Minimal API with Swagger helpers
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;
using TinyHelpers.AspNetCore.Swagger;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSwaggerGen(options =>
{
options.AddAcceptLanguageHeader();
options.AddDefaultProblemDetailsResponse();
options.AddTimeSpanTypeMapping("00:15:00");
options.AddOperationParameters();
});
builder.Services.AddSwaggerOperationParameters(parameters =>
{
parameters.Parameters.Add(new OpenApiParameter
{
Name = "X-Request-Id",
In = ParameterLocation.Header,
Required = false,
Description = "Optional request correlation identifier"
});
});
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.Run();
Building a reusable schema
using Microsoft.OpenApi;
using TinyHelpers.AspNetCore.Swagger;
var schema = OpenApiSchemaHelper.CreateSchema<string>(JsonSchemaType.String, "uuid");
Contribute
The project is continuously evolving. Contributions, issues, and pull requests are welcome.
Work on the develop branch, not on master. Pull requests should target develop.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Swashbuckle.AspNetCore.SwaggerGen (>= 10.2.1)
-
net8.0
- Swashbuckle.AspNetCore.SwaggerGen (>= 10.2.1)
-
net9.0
- Swashbuckle.AspNetCore.SwaggerGen (>= 10.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.50 | 303 | 6/18/2026 |
| 4.0.46 | 116 | 6/11/2026 |
| 4.0.40 | 146 | 4/15/2026 |
| 4.0.38 | 152 | 3/11/2026 |
| 4.0.37 | 123 | 2/11/2026 |
| 4.0.35 | 160 | 1/8/2026 |
| 4.0.34 | 473 | 12/10/2025 |
| 4.0.32 | 320 | 11/13/2025 |
| 4.0.30 | 324 | 10/15/2025 |
| 4.0.26 | 278 | 9/1/2025 |
| 4.0.25 | 197 | 7/30/2025 |
| 4.0.24 | 245 | 7/9/2025 |
| 4.0.23 | 250 | 6/16/2025 |
| 4.0.22 | 302 | 6/5/2025 |
| 4.0.21 | 229 | 6/3/2025 |
| 4.0.19 | 934 | 4/17/2025 |
| 4.0.18 | 379 | 4/2/2025 |
| 4.0.17 | 231 | 3/31/2025 |