Skip to content

[Feature]: Support for Java 8 date formats #5172

@Allsimon

Description

@Allsimon

Feature Description

Java 8 introduced the Date/Time API that has largely replaced Joda-Time.
Relatively recently, OpenAPI has created a Formats Registry that contains format that map nicely to the Java 8 objects.

Use Case

Date/Time is a really complex system

The current version (2.2.49) only support 2 types:

    static class TestObjectDates {
        public ZonedDateTime zonedDateTime = ZonedDateTime.parse("2007-12-03T10:15:30+01:00[Europe/Paris]"); // ❌ 'date-time', no format exists in the registry for this type yet
        public OffsetDateTime offsetDateTime = OffsetDateTime.parse("2007-12-03T10:15:30+01:00"); // 🐛 complex object, should be 'date-time'
        public Instant instant = Instant.parse("2007-12-03T10:15:30+01:00"); // ✅
        public LocalDateTime localDateTime = LocalDateTime.parse("2007-12-03T10:15:30"); // 🐛 'date-time', should be 'date-time-local'
        public LocalDate localDate = LocalDate.parse("2007-12-03"); // ✅
        public OffsetTime offsetTime = OffsetTime.parse("10:15:30+01:00"); // 🐛 complex object, should be 'time'
        public LocalTime localTime = LocalTime.parse("10:15:30"); // 🐛 complex object, should be 'time-local'
        public Duration duration = Duration.parse("PT10H15M30S"); // 🐛 complex object, should be 'duration'
    }

Suggested Solution

Built-in support in swagger-core, I opened #5113 to support 'date-time-local'. I don't mind fixing every other types if this issue is accepted

Checklist

  • I have searched the existing issues to ensure this is not a duplicate.
  • This feature would be useful to more than just my use case.
  • I have provided enough detail for the maintainers to understand the scope of the request.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions