Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxkoshevoi/dateonlytimeonly.aspnet
Adds support for receiving and returning DateOnly/TimeOnly as ISO 8601 string to ASP.NET Core API
https://github.com/maxkoshevoi/dateonlytimeonly.aspnet
Last synced: 24 days ago
JSON representation
Adds support for receiving and returning DateOnly/TimeOnly as ISO 8601 string to ASP.NET Core API
- Host: GitHub
- URL: https://github.com/maxkoshevoi/dateonlytimeonly.aspnet
- Owner: maxkoshevoi
- License: mit
- Created: 2021-09-15T20:29:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-01T07:30:14.000Z (over 1 year ago)
- Last Synced: 2024-11-09T03:55:01.268Z (about 1 month ago)
- Language: C#
- Homepage:
- Size: 31.3 KB
- Stars: 119
- Watchers: 4
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DateOnlyTimeOnly.AspNet
Adds support for receiving and returning DateOnly/TimeOnly as ISO 8601 string to ASP.NET Core API
## Installation
Get it from NuGet
- Base package: [![NuGet](https://img.shields.io/nuget/vpre/DateOnlyTimeOnly.AspNet.svg?label=NuGet)](https://www.nuget.org/packages/DateOnlyTimeOnly.AspNet/)
- Swashbuckle support: [![NuGet](https://img.shields.io/nuget/vpre/DateOnlyTimeOnly.AspNet.Swashbuckle.svg?label=NuGet)](https://www.nuget.org/packages/DateOnlyTimeOnly.AspNet.Swashbuckle/)## Usage
Call `AddDateOnlyTimeOnlyStringConverters` on `services`:
```cs
builder.Services.AddDateOnlyTimeOnlyStringConverters();
```After that:
- **For .NET 6**: all `DateOnly` and `TimeOnly` action arguments will be received and returned as ISO 8601 string;
- **For .NET 7**: adds support to use `TimeOnly` as Dictionary key (the rest is available out of the box).## Swagger support
### NSwag
No additional action is needed.
### Swashbuckle
#### v6.5.0 and after:
No additional action is needed.
#### Before v6.5.0:
Install `DateOnlyTimeOnly.AspNet.Swashbuckle` package, and add `UseDateOnlyTimeOnlyStringConverters` to your swagger configuration:
```cs
builder.Services.AddSwaggerGen(c => c.UseDateOnlyTimeOnlyStringConverters());
```