Skip to content

Fix MinLength incorrectly added to DateTime and Date types#1900

Merged
lahma merged 2 commits intoRicoSuter:masterfrom
lahma:fix/1583-minlength-datetime
Mar 7, 2026
Merged

Fix MinLength incorrectly added to DateTime and Date types#1900
lahma merged 2 commits intoRicoSuter:masterfrom
lahma:fix/1583-minlength-datetime

Conversation

@lahma
Copy link
Copy Markdown
Collaborator

@lahma lahma commented Mar 7, 2026

Summary

  • When a DateTime, DateTimeOffset, DateOnly, or TimeOnly property has [Required], the schema incorrectly got MinLength=1 because these types are represented as strings with a format in JSON Schema
  • This is wrong — MinLength should only apply to actual string properties, not date/time types that happen to use string representation
  • Added IsDateTimeFormat check to exclude date-time, date, time, duration, and time-span formats from the MinLength=1 logic
  • The workaround of adding AllowEmptyStrings=true is no longer needed

Test plan

  • 1 new test verifying [Required] on DateTime/DateTimeOffset/DateOnly/TimeOnly does NOT set MinLength, while [Required] on string still sets MinLength=1
  • All 449 tests pass with no regressions

Fixes #1583

🤖 Generated with Claude Code

lahma and others added 2 commits March 7, 2026 15:09
When a DateTime, DateTimeOffset, DateOnly, or TimeOnly property has
[Required], it was getting MinLength=1 because these types are
represented as strings with a format in JSON Schema. This is incorrect -
MinLength should only apply to actual string properties, not date/time
types that use string representation.

Added IsDateTimeFormat check to exclude date-time, date, time, duration,
and time-span formats from the MinLength=1 logic.

Fixes RicoSuter#1583

Co-Authored-By: Claude Opus 4.6 <[email protected]>
DateOnly and TimeOnly are .NET 6+ only types, not available in
.NET Framework 4.7.2. Wrap them with #if NET6_0_OR_GREATER.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@lahma lahma merged commit 88d9e77 into RicoSuter:master Mar 7, 2026
2 checks passed
@lahma lahma deleted the fix/1583-minlength-datetime branch March 7, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MinLength gets added to DateTime and Date types

1 participant