Skip to content

Easily configure Swashbuckle to generate correct documentation for NodaTime types.

License

Notifications You must be signed in to change notification settings

jakubka/swashbuckle-nodatime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swashbuckle.NodaTime

Easily configure Swashbuckle to generate correct documentation for NodaTime types.

NodaTime is an alternative date and time API for .NET which is often used to replace built in types for handling date and time. It can be easily configured to work nicely with Web Api using NodaTime.Serialization.JsonNet package.

Swashbuckle is a library to seamlesly add swagger generation and UI to Web Api projects.

The problem is that by default swagger generated by Swashbuckle doesn't show NodaTime types nicely as can be seen on the following picture:

Swashbuckle.NodaTime configures Swashbuckle to show NodaTime types as they will be really deserialized:

Installation

Install from NuGet: https://www.nuget.org/packages/Swashbuckle.NodaTime.

Run the following command in the Package Manager Console:

Install-Package Swashbuckle.NodaTime

Usage

Call ConfigureForNodaTime method on swagger configuration when setting up swagger using EnableSwagger method.

httpConfiguration
    .EnableSwagger(c =>
    {
        ...

        c.ConfigureForNodaTime(jsonSerializerSettings);
    });

jsonSerializerSettings should be the Json.NET settings object which is used by Web API to serialize and deserialize JSON. Typical usage looks like this:

var httpConfiguration = new HttpConfiguration();

var jsonSerializerSettings = httpConfiguration.Formatters.JsonFormatter.SerializerSettings;

// ConfigureForNodaTime is from NodaTime.Serialization.JsonNet package
// it needs to be called before configuring swagger
jsonSerializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);

ConfigureSwagger(httpConfiguration, jsonSerializerSettings);

Check folder example for working Web Api project with everything configured.

About

Easily configure Swashbuckle to generate correct documentation for NodaTime types.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published