Yarrasoft.Swashbuckle.NodaTime
10.0.1
dotnet add package Yarrasoft.Swashbuckle.NodaTime --version 10.0.1
NuGet\Install-Package Yarrasoft.Swashbuckle.NodaTime -Version 10.0.1
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="Yarrasoft.Swashbuckle.NodaTime" Version="10.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Yarrasoft.Swashbuckle.NodaTime" Version="10.0.1" />
<PackageReference Include="Yarrasoft.Swashbuckle.NodaTime" />
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 Yarrasoft.Swashbuckle.NodaTime --version 10.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Yarrasoft.Swashbuckle.NodaTime, 10.0.1"
#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 Yarrasoft.Swashbuckle.NodaTime@10.0.1
#: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=Yarrasoft.Swashbuckle.NodaTime&version=10.0.1
#tool nuget:?package=Yarrasoft.Swashbuckle.NodaTime&version=10.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Yarrasoft.Swashbuckle.NodaTime
Allows configure Asp.Net Core and swagger to use NodaTime types.
Temporary package for .NET 10 support
Forked from MicroElements.Swashbuckle.NodaTime
Contains fixes merged from xikxekxok
Installation
Package Reference:
dotnet add package yarrasoft.swashbuckle.nodatime
Getting started
- Add package reference to MicroElements.Swashbuckle.NodaTime
- Configure asp net core to use swagger
- Configure JsonSerializer to properly serialize NodaTime types. see
AddJsonFormattersorAddJsonOptions - Configure
AddSwaggerGenwithConfigureForNodaTime
Benefits of MicroElements.Swashbuckle.NodaTime
- Supports Swashbuckle 5, net core 3 and brand new System.Text.Json
- Implemented in c#, no FSharp.Core lib in dependencies
- JsonSerializerSettings ContractResolver uses for NamingStrategy, so you can use DefaultNamingStrategy, CamelCaseNamingStrategy or SnakeCaseNamingStrategy
- Supports new DateInterval (use NodaTime.Serialization.JsonNet >= 2.1.0)
Sample
Full sample see in samples: https://github.com/micro-elements/MicroElements.Swashbuckle.NodaTime/tree/master/samples/WebApiSample
public class Startup
{
enum JsonProvider
{
NewtonsoftJson,
SystemTextJson
}
// JsonProvider
private static JsonProvider useJsonProvider = JsonProvider.SystemTextJson;
// USING NewtonsoftJson settings as PropertyNamingPolicy for System.Text.Json
private static bool useNewtonsoftJsonAsNamingPolicy = true;
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
void ConfigureNewtonsoftJsonSerializerSettings(JsonSerializerSettings serializerSettings)
{
// Use DefaultContractResolver or CamelCasePropertyNamesContractResolver;
// serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
serializerSettings.ContractResolver = new DefaultContractResolver()
{
//NamingStrategy = new DefaultNamingStrategy()
//NamingStrategy = new CamelCaseNamingStrategy()
//NamingStrategy = new SnakeCaseNamingStrategy()
NamingStrategy = new CamelCaseNamingStrategy()
};
// Configures JsonSerializer to properly serialize NodaTime types.
serializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
}
void ConfigureSystemTextJsonSerializerSettings(JsonSerializerOptions serializerOptions)
{
if (useNewtonsoftJsonAsNamingPolicy)
{
// USING NewtonsoftJson settings as PropertyNamingPolicy for System.Text.Json
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
ConfigureNewtonsoftJsonSerializerSettings(jsonSerializerSettings);
serializerOptions.PropertyNamingPolicy = new NewtonsoftJsonNamingPolicy(jsonSerializerSettings);
}
// Configures JsonSerializer to properly serialize NodaTime types.
serializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
serializerOptions.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
}
if (useJsonProvider == JsonProvider.NewtonsoftJson)
{
services
.AddMvcCore()
.AddApiExplorer()
.AddNewtonsoftJson(options => ConfigureNewtonsoftJsonSerializerSettings(options.SerializerSettings, shouldGenerateExamples: true));
}
if (useJsonProvider == JsonProvider.SystemTextJson)
{
services
.AddMvcCore()
.AddApiExplorer()
.AddJsonOptions(options => ConfigureSystemTextJsonSerializerSettings(options.JsonSerializerOptions, shouldGenerateExamples: true))
;
}
//services.AddTransient<IConfigureOptions<JsonOptions>, ConfigureNewtonsoftJsonJsonNamingPolicy>();
// Adds swagger
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
if (useJsonProvider == JsonProvider.NewtonsoftJson)
{
// Configures swagger to use NodaTime with serializerSettings.
c.ConfigureForNodaTime(configureSerializerSettings: ConfigureNewtonsoftJsonSerializerSettings);
}
if (useJsonProvider == JsonProvider.SystemTextJson)
{
JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions();
ConfigureSystemTextJsonSerializerSettings(jsonSerializerOptions);
c.ConfigureForNodaTimeWithSystemTextJson(jsonSerializerOptions);
}
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseSwagger();
app.UseRouting();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
// Adds swagger UI
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
}
}
public class NewtonsoftJsonNamingPolicy : JsonNamingPolicy
{
private readonly JsonSerializerSettings _jsonSerializerSettings;
/// <inheritdoc />
public NewtonsoftJsonNamingPolicy(JsonSerializerSettings jsonSerializerSettings)
{
_jsonSerializerSettings = jsonSerializerSettings;
}
/// <inheritdoc />
public override string ConvertName(string name)
{
var contractResolver = _jsonSerializerSettings.ContractResolver;
return (contractResolver as DefaultContractResolver)?.GetResolvedPropertyName(name) ?? name;
}
}
How it works
- MicroElements.Swashbuckle.NodaTime creates Schemas for all NodaTime types
- MicroElements.Swashbuckle.NodaTime configures JsonSerializer for examples
- Maps types to ISO 8601
Screenshots
Without MicroElements.Swashbuckle.NodaTime

With MicroElements.Swashbuckle.NodaTime

With MicroElements.Swashbuckle.NodaTime (camelCase)

Build
Windows: Run build.ps1
Linux: Run build.sh
License
This project is licensed under the MIT license. See the LICENSE file for more info.
| 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 was computed. 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 was computed. 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.
-
net8.0
- NodaTime (>= 3.0.0)
- NodaTime.Serialization.JsonNet (>= 3.0.0)
- NodaTime.Serialization.SystemTextJson (>= 1.1.0)
- Swashbuckle.AspNetCore (>= 10.0.0)
- Swashbuckle.AspNetCore.SwaggerGen (>= 10.0.0)
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 |
|---|---|---|
| 10.0.1 | 7,699 | 1/7/2026 |
| 10.0.0-alpha | 140 | 1/7/2026 |