MicroElements.Swashbuckle.NodaTime 1.0.0-beta.3

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of MicroElements.Swashbuckle.NodaTime.
There is a newer version of this package available.
See the version list below for details.
dotnet add package MicroElements.Swashbuckle.NodaTime --version 1.0.0-beta.3
NuGet\Install-Package MicroElements.Swashbuckle.NodaTime -Version 1.0.0-beta.3
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="MicroElements.Swashbuckle.NodaTime" Version="1.0.0-beta.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MicroElements.Swashbuckle.NodaTime --version 1.0.0-beta.3
#r "nuget: MicroElements.Swashbuckle.NodaTime, 1.0.0-beta.3"
#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.
// Install MicroElements.Swashbuckle.NodaTime as a Cake Addin
#addin nuget:?package=MicroElements.Swashbuckle.NodaTime&version=1.0.0-beta.3&prerelease

// Install MicroElements.Swashbuckle.NodaTime as a Cake Tool
#tool nuget:?package=MicroElements.Swashbuckle.NodaTime&version=1.0.0-beta.3&prerelease

MicroElements.Swashbuckle.NodaTime

Allows configure Asp.Net Core and swagger to use NodaTime types.

Latest Builds, Packages

License NuGet NuGet MyGet

Travis AppVeyor Coverage Status

Gitter

Installation

Package Reference:

dotnet add package microelements.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 AddJsonFormatters or AddJsonOptions
  • Configure AddSwaggerGen with ConfigureForNodaTime

Why MicroElements.Swashbuckle.NodaTime is better than others

  • Implemented in c#, no FSharp.Core lib in dependencies
  • JsonSerializerSettings ContractResolver uses for NamingStrategy, so you can use DefaultNamingStrategy, CamelCaseNamingStrategy or SnakeCaseNamingStrategy
  • Added new DateInterval (waiting for new release of NodaTime.Serialization.JsonNet)

Sample

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        void InitJsonSettings(JsonSerializerSettings serializerSettings)
        {
            // Use DefaultContractResolver or CamelCasePropertyNamesContractResolver;
            serializerSettings.ContractResolver = new DefaultContractResolver();

            // Configure JsonSerializer to properly serialize NodaTime types.
            serializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
        }

        // CASE1: AddMvcCore with AddJsonFormatters
        services
            .AddMvcCore()
            .AddApiExplorer()
            .AddJsonFormatters(InitJsonSettings)
            ;

        // CASE2: AddMvc with AddJsonOptions
        //services
        //    .AddMvc()
        //    .AddJsonOptions(options => InitJsonSettings(options.SerializerSettings))
        //    ;

        // Adds swagger
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });

            // Configures swagger to use NodaTime.
            // c.ConfigureForNodaTime();

            // Configures swagger to use NodaTime. Use the same InitJsonSettings action that in AddJsonFormatters
            c.ConfigureForNodaTime(InitJsonSettings);

            // Configures swagger to use NodaTime with serializerSettings.
            // c.ConfigureForNodaTime(serializerSettings);
        });
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseMvc().UseSwagger();

        // Adds swagger UI
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
        });
    }
}

How it works

  1. MicroElements.Swashbuckle.NodaTime creates Schemas for all NodaTime types
  2. MicroElements.Swashbuckle.NodaTime configures JsonSerializer for examples
  3. Maps types to ISO 8601

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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MicroElements.Swashbuckle.NodaTime:

Package Downloads
EasyDesk.CleanArchitecture.Web

Utilities for the ASP.NET Core web layer of the clean architecture as seen by EasyDesk.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.1 563,660 1/21/2021
4.0.0 8,611 11/21/2020
3.0.0 48,566 8/29/2020
3.0.0-rc.4 91,413 2/22/2020
3.0.0-rc.3 371 2/5/2020
3.0.0-rc.2 413 2/2/2020
3.0.0-rc.1 7,704 11/14/2019
2.0.0 11,080 3/20/2019
1.2.0 1,849 3/20/2019
1.1.0 1,949 1/10/2019
1.0.2 2,012 9/27/2018
1.0.1 2,029 9/10/2018
1.0.0 2,139 8/12/2018
1.0.0-beta.3 532 8/9/2018
1.0.0-beta.2 523 8/6/2018
1.0.0-beta.1 507 8/3/2018

# 1.0.0
- Initial version

Full release notes can be found at: https://github.com/micro-elements/MicroElements.Swashbuckle.NodaTime/blob/master/CHANGELOG.md