TinyHelpers.AspNetCore.Swashbuckle 4.0.50

dotnet add package TinyHelpers.AspNetCore.Swashbuckle --version 4.0.50
                    
NuGet\Install-Package TinyHelpers.AspNetCore.Swashbuckle -Version 4.0.50
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TinyHelpers.AspNetCore.Swashbuckle" Version="4.0.50" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TinyHelpers.AspNetCore.Swashbuckle" Version="4.0.50" />
                    
Directory.Packages.props
<PackageReference Include="TinyHelpers.AspNetCore.Swashbuckle" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TinyHelpers.AspNetCore.Swashbuckle --version 4.0.50
                    
#r "nuget: TinyHelpers.AspNetCore.Swashbuckle, 4.0.50"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TinyHelpers.AspNetCore.Swashbuckle@4.0.50
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TinyHelpers.AspNetCore.Swashbuckle&version=4.0.50
                    
Install as a Cake Addin
#tool nuget:?package=TinyHelpers.AspNetCore.Swashbuckle&version=4.0.50
                    
Install as a Cake Tool

Tiny Helpers for Swashbuckle ASP.NET Core

Lint Code Base CodeQL NuGet NuGet License: MIT

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, endpoint metadata, or custom filters.

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 consumers need to discover supported culture values.
AddDefaultProblemDetailsResponse() Adds a default application/problem+json response to generated 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 the schema to show the wire format clearly.
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 Swagger operation parameters in the dependency injection container. When cross-cutting headers or query values must be declared once and reused during Swagger generation.
AddOperationParameters() Adds the operation filter that copies registered shared parameters into generated Swagger operations. When you want the generated contract to include the parameters registered with AddSwaggerOperationParameters().

Example

using Microsoft.OpenApi;
using TinyHelpers.AspNetCore.Swagger;

builder.Services.AddSwaggerOperationParameters(parameters =>
{
    parameters.Parameters.Add(new OpenApiParameter
    {
        Name = "X-Correlation-Id",
        In = ParameterLocation.Header,
        Required = false,
        Description = "Identifier used to correlate requests"
    });
});

builder.Services.AddSwaggerGen(options =>
{
    options.AddAcceptLanguageHeader();
    options.AddDefaultProblemDetailsResponse();
    options.AddTimeSpanTypeMapping(useCurrentTimeAsExample: true);
    options.AddOperationParameters();
});

Register shared parameters with AddSwaggerOperationParameters() during service registration, then enable AddOperationParameters() in AddSwaggerGen(...). The options object stores the shared parameter definitions, and the operation filter copies them into generated operations. This prevents duplicated endpoint metadata while preserving a complete contract for Swagger UI and generated clients.

Schema helpers

OpenApiSchemaHelper

This helper provides ready-to-use schema fragments that can be reused when building custom Swagger filters or other OpenAPI customizations. It keeps default values, formats, and enum choices consistent across generated documents.

Method What it does When to use it
CreateStringSchema(string? defaultValue = null) Creates a reusable string schema with an optional default value. When you want text-based contract metadata without rebuilding the same schema each time.
CreateSchema<TValue>(JsonSchemaType type, string? format = null) Creates a primitive schema with explicit OpenAPI type and format metadata. When a filter needs to describe a primitive OpenAPI shape consistently.
CreateSchema<TValue>(JsonSchemaType type, string? format, TValue? defaultValue = null) Creates a primitive schema and includes the default value that clients should display or assume. When you want to document both the value shape and its fallback.
CreateSchema(IEnumerable<string> values, string? defaultValue = null) Creates a string schema with an enumeration of externally defined allowed values. When the field is constrained to a fixed set of strings that is not represented by a CLR enum.
CreateSchema<TEnum>(TEnum? defaultValue = null) Creates a string schema from an enum type so every declared value is documented. When you want CLR 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.AddSwaggerOperationParameters(parameters =>
{
    parameters.Parameters.Add(new OpenApiParameter
    {
        Name = "X-Request-Id",
        In = ParameterLocation.Header,
        Required = false,
        Description = "Optional request correlation identifier"
    });
});

builder.Services.AddSwaggerGen(options =>
{
    options.AddAcceptLanguageHeader();
    options.AddDefaultProblemDetailsResponse();
    options.AddTimeSpanTypeMapping("00:15:00");
    options.AddOperationParameters();
});

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed