diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a8f082..3acf5ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,11 +76,11 @@ jobs: - name: Make target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: mkdir -p uuid/target scuid/target circe/target core/target project/target + run: mkdir -p tapir/target uuid/target scuid/target circe/target core/target project/target - name: Compress target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: tar cf targets.tar uuid/target scuid/target circe/target core/target project/target + run: tar cf targets.tar tapir/target uuid/target scuid/target circe/target core/target project/target - name: Upload target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') diff --git a/build.sbt b/build.sbt index 300ed1a..33f26e6 100644 --- a/build.sbt +++ b/build.sbt @@ -71,4 +71,16 @@ 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) diff --git a/tapir/src/main/scala/me/wojnowski/humanoid/tapir/TapirCodecs.scala b/tapir/src/main/scala/me/wojnowski/humanoid/tapir/TapirCodecs.scala new file mode 100644 index 0000000..d66a6df --- /dev/null +++ b/tapir/src/main/scala/me/wojnowski/humanoid/tapir/TapirCodecs.scala @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Jakub Wojnowski + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.wojnowski.humanoid.tapir + +import me.wojnowski.humanoid.HumanId +import me.wojnowski.humanoid.HumanIdOps +import me.wojnowski.humanoid.IdConverter +import sttp.tapir.Codec +import sttp.tapir.Codec.PlainCodec +import sttp.tapir.Schema + +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) +} diff --git a/tapir/src/main/scala/me/wojnowski/humanoid/tapir/package.scala b/tapir/src/main/scala/me/wojnowski/humanoid/tapir/package.scala new file mode 100644 index 0000000..c7cfd5d --- /dev/null +++ b/tapir/src/main/scala/me/wojnowski/humanoid/tapir/package.scala @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Jakub Wojnowski + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.wojnowski.humanoid + +package object tapir extends TapirCodecs