Fix MinLength incorrectly added to DateTime and Date types#1900
Merged
lahma merged 2 commits intoRicoSuter:masterfrom Mar 7, 2026
Merged
Fix MinLength incorrectly added to DateTime and Date types#1900lahma merged 2 commits intoRicoSuter:masterfrom
lahma merged 2 commits intoRicoSuter:masterfrom
Conversation
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]>
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.
Summary
DateTime,DateTimeOffset,DateOnly, orTimeOnlyproperty has[Required], the schema incorrectly gotMinLength=1because these types are represented as strings with a format in JSON SchemaMinLengthshould only apply to actual string properties, not date/time types that happen to use string representationIsDateTimeFormatcheck to excludedate-time,date,time,duration, andtime-spanformats from theMinLength=1logicAllowEmptyStrings=trueis no longer neededTest plan
[Required]on DateTime/DateTimeOffset/DateOnly/TimeOnly does NOT set MinLength, while[Required]on string still sets MinLength=1Fixes #1583
🤖 Generated with Claude Code