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 a77d042 commit 2b040c6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
14 changes: 13 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
37 changes: 37 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,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)
}
24 changes: 24 additions & 0 deletions tapir/src/main/scala/me/wojnowski/humanoid/tapir/package.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2b040c6

Please sign in to comment.