MicroElements.Swashbuckle.NodaTime 1.0.0-beta.3

Configure Asp.Net Core and swagger to use NodaTime types.

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.
Install-Package MicroElements.Swashbuckle.NodaTime -Version 1.0.0-beta.3
dotnet add package MicroElements.Swashbuckle.NodaTime --version 1.0.0-beta.3
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MicroElements.Swashbuckle.NodaTime, 1.0.0-beta.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

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.

Release Notes

# 1.0.0
- Initial version

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
4.0.1 16,297 1/21/2021
4.0.0 4,144 11/21/2020
3.0.0 7,883 8/29/2020
3.0.0-rc.4 31,513 2/22/2020
3.0.0-rc.3 258 2/5/2020
3.0.0-rc.2 308 2/2/2020
3.0.0-rc.1 4,202 11/14/2019
2.0.0 3,114 3/20/2019
1.2.0 300 3/20/2019
1.1.0 403 1/10/2019
1.0.2 462 9/27/2018
1.0.1 891 9/10/2018
1.0.0 489 8/12/2018
1.0.0-beta.3 333 8/9/2018
1.0.0-beta.2 346 8/6/2018
1.0.0-beta.1 330 8/3/2018
Show less