Skip to content

Commit

Permalink
✨ Add Tapir module
Browse files Browse the repository at this point in the history
  • Loading branch information
jwojnowski committed Apr 13, 2024
1 parent 7aef2a8 commit de9ba92
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
15 changes: 14 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@ lazy val circe =
)
)

lazy val root = tlCrossRootProject.aggregate(core, scuid, uuid, circe)
lazy val tapir =
project
.in(file("tapir"))
.dependsOn(core)
.settings(
name := "humanoid-tapir",
libraryDependencies ++= Seq(
"com.softwaremill.sttp.tapir" %% "tapir-core" % "1.10.4",
"org.scalameta" %% "munit" % "0.7.29" % Test
)

)

lazy val root = tlCrossRootProject.aggregate(core, scuid, uuid, circe, tapir)
16 changes: 16 additions & 0 deletions tapir/src/main/scala/me/wojnowski/humanoid/tapir/TapirCodecs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.wojnowski.humanoid.tapir

import sttp.tapir.Schema
import sttp.tapir.Codec.PlainCodec
import me.wojnowski.humanoid.HumanId
import me.wojnowski.humanoid.IdConverter
import me.wojnowski.humanoid.HumanIdOps
import sttp.tapir.Codec

trait TapirCodecs {
implicit def schemaForHumanId[P <: String, Id](implicit valueOf: ValueOf[P]): Schema[HumanId[P, Id]] =
Schema.string.format(s"ID with prefix: ${valueOf.value}_")

implicit def codecForHumanId[P <: String, Id](implicit valueOf: ValueOf[P], IdConverter: IdConverter[Id]): PlainCodec[HumanId[P, Id]] =
Codec.string.mapEither(HumanIdOps[P, Id].parsePrefixOptional)(_.renderWithPrefix)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package me.wojnowski.humanoid

package object tapir extends TapirCodecs

0 comments on commit de9ba92

Please sign in to comment.