Add Schema and Codec for java.time.Period#5129
Merged
adamw merged 3 commits intosoftwaremill:masterfrom Mar 19, 2026
Merged
Conversation
There was a problem hiding this comment.
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]usingPeriod.parse/.toString. - Added
Schema[Period]as a string schema (with an explicit format). - Extended datetime codec tests to include
Periodround-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") |
Member
|
Thanks! :) |
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.
.format("duration")as for JsonSchema spec.https://json-schema.org/understanding-json-schema/reference/type#dates-and-times