-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for DateOnly and TimeOnly
Motivation ---------- For "date", "partial-date", "time", and "partial-time" string formats, DateOnly and TimeOnly are a better fit when available in .NET 6 or later. Modifications ------------- - Add a dependency on Microsoft.Extensions.Options - Create a new internal option to control date/time handling, and initialize based on command-line properties and target frameworks - Use the new option to choose schema types - Treat "time" format the same as "partial-time" Breaking Change --------------- When building targeting only .NET 6 or later, the default type used for "date", "partial-date", and "partial-time" is now DateOnly or TimeOnly instead of DateTime or TimeSpan. This may cause backward compatibility issues in generated SDKs. Use the command line switch `-p LegacyDateTimeHandling=true` to restore the previous behavior. This is not necessary if targeting .NET Standard 2.0.
- Loading branch information
1 parent
8b7fc50
commit 759f263
Showing
10 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/Yardarm/Generation/Schema/StringSchemaOptionsConfigurator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using Microsoft.Extensions.Options; | ||
using NuGet.Frameworks; | ||
using Yardarm.Internal; | ||
using Yardarm.Packaging; | ||
|
||
namespace Yardarm.Generation.Schema; | ||
|
||
internal class StringSchemaOptionsConfigurator( | ||
YardarmGenerationSettings settings) | ||
: IConfigureOptions<GenerationOptions> | ||
{ | ||
public void Configure(GenerationOptions options) | ||
{ | ||
// Use legacy handling for DateOnly and TimeOnly if explicitly requested | ||
if (settings.Properties.TryGetValue("LegacyDateTimeHandling", out string? legacyDateTimeHandling) && | ||
string.Equals(legacyDateTimeHandling, "true", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
options.LegacyDateTimeHandling = true; | ||
return; | ||
} | ||
|
||
// Also, use legacy handling if any target framework is less than .NET 6. This is because .NET Standard or | ||
// earlier .NET Core versions do not support DateOnly and TimeOnly. Because public APIs should be forward | ||
// compatible from older targets, we need to use legacy handling for all targets if any target is unsupported | ||
// to ensure consistent API surface. | ||
foreach (string moniker in settings.TargetFrameworkMonikers) | ||
{ | ||
var framework = NuGetFramework.Parse(moniker); | ||
if (framework.Framework != NuGetFrameworkConstants.NetCoreApp || framework.Version.Major < 6) | ||
{ | ||
options.LegacyDateTimeHandling = true; | ||
return; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Yardarm.Internal; | ||
|
||
internal class GenerationOptions | ||
{ | ||
public bool LegacyDateTimeHandling { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters