Skip to content

Add Schema and Codec for java.time.Period#5129

Merged
adamw merged 3 commits intosoftwaremill:masterfrom
ivan-klass:java-time-period
Mar 19, 2026
Merged

Add Schema and Codec for java.time.Period#5129
adamw merged 3 commits intosoftwaremill:masterfrom
ivan-klass:java-time-period

Conversation

@ivan-klass
Copy link
Contributor

@ivan-klass ivan-klass commented Mar 18, 2026

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class support for java.time.Period in Tapir’s text/plain codecs and schema derivation, plus a property-based regression test to ensure Period round-trips via .toString / parse.

Changes:

  • Added Codec[String, Period, TextPlain] using Period.parse / .toString.
  • Added Schema[Period] as a string schema (with an explicit format).
  • Extended datetime codec tests to include Period round-trip checks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
core/src/main/scala/sttp/tapir/Codec.scala Introduces an implicit plain-text codec for java.time.Period.
core/src/main/scala/sttp/tapir/Schema.scala Introduces an implicit schema for java.time.Period as a string with a format annotation.
core/src/test/scalajvm/sttp/tapir/CodecTestDateTime.scala Adds ScalaCheck Arbitrary[Period] and a round-trip property test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

implicit lazy val schemaForJavaDuration: Schema[Duration] = Schema(SString())
implicit lazy val schemaForLocalTime: Schema[LocalTime] = Schema(SString())
implicit lazy val schemaForOffsetTime: Schema[OffsetTime] = Schema(SString())
implicit lazy val schemaForPeriod: Schema[Period] = Schema(SString()).format("duration")
@adamw adamw merged commit 369598a into softwaremill:master Mar 19, 2026
16 checks passed
@adamw
Copy link
Member

adamw commented Mar 19, 2026

Thanks! :)

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.

3 participants