Fix DateOnly: check target runtime version instead of design-time host#323
Merged
sergey-tihon merged 2 commits intorepo-assist/fix-format-date-dateonly-2026-03-12-76e70b2ca366aa05from Mar 13, 2026
Conversation
…et runtime check Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [WIP] Address feedback on DateOnly implementation for .NET 6+ targets
Fix DateOnly: check target runtime version instead of design-time host
Mar 13, 2026
cf3d13e
into
repo-assist/fix-format-date-dateonly-2026-03-12-76e70b2ca366aa05
9 checks passed
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the type-provider codegen so format: date uses DateOnly only when the consumer project’s target runtime supports it, avoiding incorrect DateOnly members when the design-time host runtime is newer than the target.
Changes:
- Add
useDateOnly: booltoDefinitionCompiler(v2 & v3) and gateformat: datetype selection on it. - Compute
useDateOnlyfromcfg.SystemRuntimeAssemblyVersion.Major >= 6in both providers. - Update schema parser tests to pass a
useDateOnlyflag.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/SwaggerProvider.Tests/Schema.Parser.Tests.fs | Passes a runtime-based useDateOnly flag into DefinitionCompiler during schema compilation tests. |
| src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs | Gates OpenAPI v3 format: date mapping on useDateOnly (DateOnly vs DateTimeOffset). |
| src/SwaggerProvider.DesignTime/v2/DefinitionCompiler.fs | Gates Swagger v2 Date mapping on useDateOnly (DateOnly vs DateTime). |
| src/SwaggerProvider.DesignTime/Provider.SwaggerClient.fs | Derives useDateOnly from cfg.SystemRuntimeAssemblyVersion and passes it into the compiler. |
| src/SwaggerProvider.DesignTime/Provider.OpenApiClient.fs | Derives useDateOnly from cfg.SystemRuntimeAssemblyVersion and passes it into the compiler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| let schema = SwaggerParser.parseSchema schemaStr | ||
|
|
||
| let defCompiler = DefinitionCompiler(schema, false) | ||
| let defCompiler = DefinitionCompiler(schema, false, Environment.Version.Major >= 6) |
| |> String.concat ";\n- ")*) | ||
| try | ||
| let defCompiler = DefinitionCompiler(schema, false) | ||
| let defCompiler = DefinitionCompiler(schema, false, Environment.Version.Major >= 6) |
Comment on lines
+500
to
+508
| // Use DateOnly only when the target runtime supports it (.NET 6+). | ||
| // We check useDateOnly (derived from cfg.SystemRuntimeAssemblyVersion) rather than | ||
| // probing the design-time host process, which may differ from the consumer's runtime. | ||
| if useDateOnly then | ||
| System.Type.GetType("System.DateOnly") | ||
| |> Option.ofObj | ||
| |> Option.defaultValue typeof<DateTimeOffset> | ||
| else | ||
| typeof<DateTimeOffset> |
Comment on lines
+356
to
+364
| // Use DateOnly only when the target runtime supports it (.NET 6+). | ||
| // We check useDateOnly (derived from cfg.SystemRuntimeAssemblyVersion) rather than | ||
| // probing the design-time host process, which may differ from the consumer's runtime. | ||
| if useDateOnly then | ||
| System.Type.GetType("System.DateOnly") | ||
| |> Option.ofObj | ||
| |> Option.defaultValue typeof<DateTime> | ||
| else | ||
| typeof<DateTime> |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
System.Type.GetType("System.DateOnly")probes the design-time host process (IDE/compiler), not the consuming project's runtime. A .NET 6+ IDE compiling a .NET Standard or .NET 5 project would incorrectly generateDateOnly-typed members that don't exist in the target runtime.Changes
DefinitionCompiler(v2 & v3): AddeduseDateOnly: boolparameter;format: datefalls back toDateTime/DateTimeOffsetunconditionally whenfalseProvider.OpenApiClient.fs/Provider.SwaggerClient.fs: DeriveuseDateOnlyfromcfg.SystemRuntimeAssemblyVersion.Major >= 6— the standard type provider mechanism for detecting the target runtime versionEnvironment.Version.Major >= 6toDefinitionCompilerdirectly📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.