Git Product home page Git Product logo

swashbuckle-nodatime's Introduction

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.

swashbuckle-nodatime's People

Contributors

jakubka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

swashbuckle-nodatime's Issues

Support .NET Core

I want to use this library but the dependency on .NET Framework full means I cannot run this on Linux or OSX.

Swashbuckle dependency

Does swashbuckle-nodatime really need to be dependent on Swashbuckle package? Swashbuckle.Core wouldn't be enough?

swashbuckle-nodatime is not compatible with the latest version of NodaTime

Due to some API changes in the latest version(s) (versions 2+), swashbuckle-nodatime no longer works. I took a shallow look at some of the changes and updating shouldn't bee too difficult. I'd be happy to make the changes but would like to seek guidance on versioning.

Since the fixes pertain to specific versions of NodaTime (ie: current version of swashbuckle-nodatime is implemented correctly for versions >= 1.3.1 but < 2, I'd imagine you'd want to keep this repo locked. Should we perhaps consider forking and making a new repo to be used for NodaTime version 2+?

Again, happy to make the changes - just let me know what you have in mind for versioning to match the correct version of NodaTime.

Support for nullable types

Using Web API 2 and Swasbuckle, if I use straight type, eg. LocalTime, then the swagger config is generated correctly.

But nullable types (LocalTime?), are not recognized by this plugin, and are generated like NodaTime types without this plugin installed (the appear as empty objects).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.