feat: support Java 8 date/time formats per OpenAPI Formats Registry (#5172)#5184
Open
kuntal1461 wants to merge 1 commit into
Open
feat: support Java 8 date/time formats per OpenAPI Formats Registry (#5172)#5184kuntal1461 wants to merge 1 commit into
kuntal1461 wants to merge 1 commit into
Conversation
…gistry (swagger-api#5172) - Add DateTimeLocalSchema, TimeSchema, TimeLocalSchema, DurationSchema model classes - Map java.time.OffsetTime → format "time" by default (was incorrect complex object) - Map java.time.Duration → format "duration" by default (was incorrect complex object) - Add PrimitiveType.enableJava8Formats() opt-in to map: java.time.LocalDateTime → "date-time-local" java.time.LocalTime → "time-local" - Deprecate enablePartialTime() in favour of enableJava8Formats() - Add Java8DateFormatsTest and TestObjectJava8Dates covering default and opt-in behaviour LocalDateTime and LocalTime are opt-in only to preserve backward compatibility. The default will change in the next major version. Authored-By: Kuntal Maity <kuntal.1461@gmail.com>
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.
Description
Fixes #5172
Java 8 introduced
java.time.*types that have become the standard for date/time handling, largely replacingjava.util.Dateand Joda-Time. The OpenAPI Formats Registry now defines standard format strings that map to these types. This PR bringsswagger-coreinto alignment with that registry.What was wrong
java.time.OffsetTime"time"java.time.Duration"duration"java.time.LocalDateTime"date-time"(wrong format name)"date-time-local"java.time.LocalTime"partial-time"via opt-in"time-local"OffsetTimeandDurationhad no mapping at all — they fell through to Jackson's object expansion, producing unusable schemas with internal JDK fields.LocalDateTimewas mapped to"date-time"which is the RFC 3339 offset date-time format — incorrect for a type that carries no timezone.Why not just fix everything as the default?
LocalDateTime → "date-time"is the current default and has been since the early versions of this library. Many existing users depend on this mapping in generated specs, client SDKs, and validation logic. Silently changing it would break them on upgrade with no warning.OffsetTimeandDurationare fixed as the new default because their previous output (a complex object schema) was never usable — no user could have a working integration built on that output.What this PR does
Fixed by default (no user action required):
java.time.OffsetTime→string / "time"java.time.Duration→string / "duration"Opt-in via
PrimitiveType.enableJava8Formats():java.time.LocalDateTime→string / "date-time-local"java.time.LocalTime→string / "time-local"This follows the same opt-in pattern already established by
enablePartialTime()in this codebase.enablePartialTime()is deprecated in favour ofenableJava8Formats(), which supersedes it with the correct registry format name ("time-local"instead of"partial-time"). The old method is kept as-is so existing callers are not broken.Migration path
New schema model classes (swagger-models)
DateTimeLocalSchema"date-time-local"TimeSchema"time"TimeLocalSchema"time-local"DurationSchema"duration"Each follows the same structure as the existing
DateTimeSchemaandDateSchema.Type of Change
OffsetTimeandDurationwere broken by default)enablePartialTime()deprecation Javadoc)Checklist
Java8DateFormatsTestcovers both default and opt-in behaviour)