├── images
├── NodaTime0.png
├── NodaTime1.png
└── NodaTime2.png
├── samples
└── WebApiSample
│ ├── appsettings.json
│ ├── appsettings.Development.json
│ ├── Controllers
│ ├── DefaultController.cs
│ ├── NodaTimeModel.cs
│ └── NodaTimeValuesController.cs
│ ├── Program.cs
│ ├── WebApiSample.csproj
│ └── Startup.cs
├── version.props
├── test
├── Directory.Build.props
└── MicroElements.Swashbuckle.NodaTime.Tests
│ ├── MicroElements.Swashbuckle.NodaTime.Tests.csproj
│ └── SchemasTests.cs
├── appveyor.yml
├── .config
└── dotnet-tools.json
├── .travis.yml
├── MicroElements.Swashbuckle.NodaTime.sln.DotSettings
├── src
├── Directory.Build.props
├── stylecop.ruleset
├── stylecop.props
├── stylecop.json
└── MicroElements.Swashbuckle.NodaTime
│ ├── MicroElements.Swashbuckle.NodaTime.csproj
│ ├── NamingPolicyParameterFilter.cs
│ ├── GlobalSuppressions.cs
│ ├── NodaTimeSchemaSettings.cs
│ ├── Schemas.cs
│ ├── SchemasFactory.cs
│ ├── SchemaExamples.cs
│ ├── NodaTimeSchemaSettingsFactory.cs
│ └── SwaggerGenOptionsExtensions.cs
├── .vscode
└── launch.json
├── LICENSE
├── common.props
├── CHANGELOG.md
├── MicroElements.Swashbuckle.NodaTime.sln
├── .gitignore
├── .editorconfig
└── README.md
/images/NodaTime0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/micro-elements/MicroElements.Swashbuckle.NodaTime/HEAD/images/NodaTime0.png
--------------------------------------------------------------------------------
/images/NodaTime1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/micro-elements/MicroElements.Swashbuckle.NodaTime/HEAD/images/NodaTime1.png
--------------------------------------------------------------------------------
/images/NodaTime2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/micro-elements/MicroElements.Swashbuckle.NodaTime/HEAD/images/NodaTime2.png
--------------------------------------------------------------------------------
/samples/WebApiSample/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Warning"
5 | }
6 | },
7 | "AllowedHosts": "*"
8 | }
9 |
--------------------------------------------------------------------------------
/version.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.1
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/test/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | image: Visual Studio 2017
2 | build_script:
3 | - ps: .\build.ps1 -Target AppVeyor
4 | test: off
5 | skip_commits:
6 | files:
7 | - '**/*.md'
8 | artifacts:
9 | - path: artifacts/packages/*.nupkg
--------------------------------------------------------------------------------
/samples/WebApiSample/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/.config/dotnet-tools.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "isRoot": true,
4 | "tools": {
5 | "cake.tool": {
6 | "version": "0.38.0",
7 | "commands": [
8 | "dotnet-cake"
9 | ]
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | dist: xenial
2 | language: csharp
3 | mono: none
4 | dotnet: 3.1
5 | os:
6 | - linux
7 | before_script:
8 | - chmod a+x ./build.sh
9 | script:
10 | - ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=false
11 |
--------------------------------------------------------------------------------
/samples/WebApiSample/Controllers/DefaultController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc;
2 |
3 | namespace WebApiSample.Controllers
4 | {
5 | [ApiExplorerSettings(IgnoreApi = true), Route("")]
6 | public class DefaultController : Controller
7 | {
8 | [HttpGet]
9 | public IActionResult Get() => Redirect("swagger");
10 | }
11 | }
--------------------------------------------------------------------------------
/MicroElements.Swashbuckle.NodaTime.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
--------------------------------------------------------------------------------
/samples/WebApiSample/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore;
2 | using Microsoft.AspNetCore.Hosting;
3 |
4 | namespace WebApiSample
5 | {
6 | public class Program
7 | {
8 | public static void Main(string[] args)
9 | {
10 | WebHost
11 | .CreateDefaultBuilder(args)
12 | .UseStartup()
13 | .Build()
14 | .Run();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | embedded
7 | true
8 | true
9 | true
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/stylecop.ruleset:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/stylecop.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | $(MSBuildThisFileDirectory)stylecop.ruleset
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/stylecop.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
3 | "settings": {
4 | "documentationRules": {
5 | "companyName": "MicroElements",
6 | "copyrightText": "Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} license. See {licenseFile} file in the project root for full license information.",
7 | "variables": {
8 | "licenseName": "MIT",
9 | "licenseFile": "LICENSE"
10 | },
11 | "xmlHeader": false
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/MicroElements.Swashbuckle.NodaTime/MicroElements.Swashbuckle.NodaTime.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | netstandard2.0
6 | enable
7 | latest
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/samples/WebApiSample/WebApiSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/samples/WebApiSample/Controllers/NodaTimeModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using NodaTime;
3 |
4 | namespace WebApiSample.Controllers
5 | {
6 | public class NodaTimeModel
7 | {
8 | public DateTime DateTime { get; set; }
9 |
10 | public DateTimeZone DateTimeZone { get; set; }
11 | public Instant Instant { get; set; }
12 | public Interval Interval { get; set; }
13 | public DateInterval DateInterval { get; set; }
14 | public Period Period { get; set; }
15 | public ZonedDateTime ZonedDateTime { get; set; }
16 | public OffsetDateTime OffsetDateTime { get; set; }
17 | public LocalDate LocalDate { get; set; }
18 | public LocalTime LocalTime { get; set; }
19 | public LocalDateTime LocalDateTime { get; set; }
20 | public Offset Offset { get; set; }
21 | public Duration Duration { get; set; }
22 | public OffsetDate OffsetDate { get; set; }
23 | public OffsetTime OffsetTime { get; set; }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/test/MicroElements.Swashbuckle.NodaTime.Tests/MicroElements.Swashbuckle.NodaTime.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | all
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "name": "Cake: Debug Script (CoreCLR)",
6 | "type": "coreclr",
7 | "request": "launch",
8 | "program": "${workspaceRoot}/tools/Cake.CoreCLR/0.29.0/Cake.dll",
9 | "args": [
10 | //"${workspaceRoot}/build.cake",
11 | //uncomment and edit for component script debug
12 | "${workspaceRoot}/tools/microelements.devops/1.6.0/scripts/main.cake",
13 | "--devOpsRoot=${workspaceRoot}/tools/microelements.devops/1.6.0",
14 | "--debug",
15 | "--verbosity=diagnostic",
16 | "--rootDir=${workspaceRoot}",
17 | "--Target=Default",
18 | "--TestSourceLink=false",
19 | "--Header=\"-+++++++-,MicroElements,DevOps,-+++++++-\""
20 | ],
21 | "cwd": "${workspaceRoot}",
22 | "stopAtEntry": true,
23 | "externalConsole": false
24 | }
25 | ],
26 | "compounds": []
27 | }
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 MicroElements
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/common.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | micro-elements
5 |
6 | Configure Asp.Net Core and swagger to use NodaTime types.
7 |
8 | # Benefits of MicroElements.Swashbuckle.NodaTime
9 | - Supports Swashbuckle 5, net core 3 and brand new System.Text.Json
10 | - Implemented in c#, no FSharp.Core lib in dependencies
11 | - NamingStrategy support. You can use DefaultNamingStrategy, CamelCaseNamingStrategy or SnakeCaseNamingStrategy
12 | - Supports DateInterval
13 | - Can be generated with user provided examples or without examples
14 |
15 |
16 | swagger swashbuckle NodaTime aspnetcore
17 | https://raw.githubusercontent.com/micro-elements/MicroElements/master/image/logo_rounded.png
18 | https://github.com/micro-elements/MicroElements.Swashbuckle.NodaTime
19 | https://raw.githubusercontent.com/micro-elements/MicroElements.Swashbuckle.NodaTime/master/LICENSE
20 | git
21 | https://github.com/micro-elements/MicroElements.Swashbuckle.NodaTime
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/MicroElements.Swashbuckle.NodaTime/NamingPolicyParameterFilter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) MicroElements. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | using Microsoft.OpenApi.Models;
5 | using Swashbuckle.AspNetCore.SwaggerGen;
6 |
7 | namespace MicroElements.Swashbuckle.NodaTime
8 | {
9 | ///
10 | /// Resolves property name by .
11 | ///
12 | internal class NamingPolicyParameterFilter : IParameterFilter
13 | {
14 | private readonly NodaTimeSchemaSettings _nodaTimeSchemaSettings;
15 |
16 | ///
17 | /// Initializes a new instance of the class.
18 | ///
19 | /// Settings that controls serialization aspects.
20 | public NamingPolicyParameterFilter(NodaTimeSchemaSettings nodaTimeSchemaSettings)
21 | {
22 | _nodaTimeSchemaSettings = nodaTimeSchemaSettings;
23 | }
24 |
25 | ///
26 | public void Apply(OpenApiParameter parameter, ParameterFilterContext context)
27 | {
28 | parameter.Name = _nodaTimeSchemaSettings.ResolvePropertyName(parameter.Name);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/samples/WebApiSample/Controllers/NodaTimeValuesController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.AspNetCore.Mvc;
3 | using NodaTime;
4 |
5 | namespace WebApiSample.Controllers
6 | {
7 | [Route("api/[controller]")]
8 | [ApiController]
9 | public class NodaTimeValuesController : ControllerBase
10 | {
11 | [HttpGet("[action]")]
12 | public ActionResult GetModel()
13 | {
14 | var dateTimeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
15 | Instant instant = Instant.FromDateTimeUtc(DateTime.UtcNow);
16 | ZonedDateTime zonedDateTime = instant.InZone(dateTimeZone);
17 | NodaTimeModel nodaTimeModel = new NodaTimeModel
18 | {
19 | DateTimeZone = DateTimeZone.Utc,
20 | Instant = instant,
21 | DateTime = DateTime.UtcNow,
22 | Interval = new Interval(instant, instant.Plus(Duration.FromHours(1))),
23 | DateInterval = new DateInterval(zonedDateTime.Date, zonedDateTime.Date.PlusDays(1)),
24 | Period = Period.FromHours(1),
25 | ZonedDateTime = zonedDateTime,
26 | OffsetDateTime = instant.WithOffset(Offset.FromHours(1)),
27 | LocalDate = zonedDateTime.Date,
28 | LocalTime = zonedDateTime.TimeOfDay,
29 | LocalDateTime = zonedDateTime.LocalDateTime,
30 | Offset = zonedDateTime.Offset,
31 | Duration = Duration.FromHours(1),
32 | OffsetDate = new OffsetDate(zonedDateTime.Date, zonedDateTime.Offset),
33 | OffsetTime = new OffsetTime(zonedDateTime.TimeOfDay, zonedDateTime.Offset),
34 | };
35 | return nodaTimeModel;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/MicroElements.Swashbuckle.NodaTime/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) MicroElements. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:Using directives should be placed correctly", Justification = "Reviewed.")]
5 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:Field names should not begin with underscore", Justification = "Reviewed.")]
6 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Reviewed.")]
7 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1116:Split parameters should start on line after declaration", Justification = "Reviewed.")]
8 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1413:Use trailing comma in multi-line initializers", Justification = "Reviewed.")]
9 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1008:Opening parenthesis should be spaced correctly", Justification = "Reviewed.")]
10 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1015:Closing generic brackets should be spaced correctly", Justification = "Reviewed.")]
11 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1025:Code should not contain multiple whitespace in a row", Justification = "Reviewed.")]
12 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1503:Braces should not be omitted", Justification = "Reviewed.")]
13 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:Elements should appear in the correct order", Justification = "Reviewed.")]
14 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 4.0.0
2 | - NodaTime updated to 3.0.0
3 | - NodaTime.Serialization.JsonNet updated to 3.0.0
4 | - NodaTime.Serialization.SystemTextJson updated to 1.0.0
5 | - Swashbuckle.AspNetCore updated to version 5.5.1
6 | - Added SchemaExamples to NodaTimeSchemaSettings and configuration methods ConfigureForNodaTime and ConfigureForNodaTimeWithSystemTextJson to support custom example values
7 | - Nullable annotations added
8 |
9 | # 3.0.0
10 | - Supports Swashbuckle 5, net core 3 and System.Text.Json
11 | - Swashbuckle.AspNetCore updated to version 5.0.0
12 | - NodaTime and NodaTime.Serialization.JsonNet updated to latest versions
13 | - ConfigureForNodaTime became more customizable
14 | - Compatibility with System.Text.Json:
15 | - New dependency: NodaTime.Serialization.SystemTextJson
16 | - Added new ConfigureForNodaTimeWithSystemTextJson
17 | - PR #13 by jeremyhayes: remove unspecified format aliases (full-date, partial-time)
18 | - PR #8 by Romanx: Add flag for generating examples in output
19 | - PR #11 by dgarciarubio: Add support for OffsetDate and OffsetTime types
20 |
21 | # 3.0.0-rc.4
22 | - PR #8 by Romanx: Add flag for generating examples in output
23 | - PR #11 by dgarciarubio: Add support for OffsetDate and OffsetTime types
24 |
25 | # 3.0.0-rc.3
26 | - Supports Swashbuckle 5, net core 3 and System.Text.Json
27 | - Swashbuckle.AspNetCore updated to version 5.0.0
28 |
29 | # 3.0.0-rc.2
30 | - Supports net core 3 and brand new System.Text.Json
31 | - NodaTime and NodaTime.Serialization.JsonNet updated to latest versions
32 | - Swashbuckle.AspNetCore updated to version 5.0.0-rc5
33 | - ConfigureForNodaTime became more customizable
34 | - Compatibility with System.Text.Json:
35 | - New dependency: NodaTime.Serialization.SystemTextJson
36 | - Added new ConfigureForNodaTimeWithSystemTextJson
37 | - Sample moved to net core 3
38 | - Sample supports NewtonsoftJson, System.Text.Json and System.Text.Json with NamingPolicy from NewtonsoftJson
39 |
40 | # 3.0.0-rc.1
41 | - Swashbuckle.AspNetCore updated to version 5.0.0-rc4
42 |
43 | # 2.0.0
44 | - Swashbuckle.AspNetCore fixed to versions [4.0.1, 5.0.0)
45 |
46 | # 1.2.0
47 | - Swashbuckle.AspNetCore fixed to versions [2.4.0, 4.0.1)
48 |
49 | # 1.1.0
50 | - Dependencies updated
51 |
52 | # 1.0.2
53 | - Bugfix: Uses factory instead of shared Schema instance. See: PR#3
54 |
55 | # 1.0.1
56 | - Updated package description
57 |
58 | # 1.0.0
59 | - Implemented in c#, no FSharp.Core lib in dependencies
60 | - JsonSerializerSettings ContractResolver uses for NamingStrategy, so you can use DefaultNamingStrategy, CamelCaseNamingStrategy or SnakeCaseNamingStrategy
61 | - Added new DateInterval (use NodaTime.Serialization.JsonNet >= 2.1.0)
62 |
63 | Full release notes can be found at: https://github.com/micro-elements/MicroElements.Swashbuckle.NodaTime/blob/master/CHANGELOG.md
64 |
--------------------------------------------------------------------------------
/src/MicroElements.Swashbuckle.NodaTime/NodaTimeSchemaSettings.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) MicroElements. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | using System;
5 | using NodaTime;
6 |
7 | namespace MicroElements.Swashbuckle.NodaTime
8 | {
9 | ///
10 | /// Settings that controls serialization aspects.
11 | ///
12 | public class NodaTimeSchemaSettings
13 | {
14 | ///
15 | /// Gets a function that resolves property name by proper naming strategy.
16 | ///
17 | public Func ResolvePropertyName { get; }
18 |
19 | ///
20 | /// Gets a function that formats object as json text.
21 | ///
22 | public Func