Migration from Wiro
Tapiro is meant to deprecate wiro.
Tapiro is based on the same concepts of wiro, the migration is pretty straightforward.
Here is a checklist of what you need to do:
- Install the plugin (as described in the guide)
- Configure your
build.sbt
(as described in the guide) - Add
Auth
type parameter to controllerstrait AccountController[F]
->trait AccountController[F[_], Auth]
- Modify controllers so that wiro
Auth
is replaced withAuth
and move as last argumentdef read(token: wiro.Auth, arg: Int)
->def read(arg: Int, token: Auth)
- Add
**/*Endpoints.scala linguist-generated
to repository's.gitattributes
to automatically collapse tapiro generated code in GitHub diffs - Add required codecs This is a valid codec for wiro.Auth:
import sttp.tapir._
import sttp.tapir.Codec._
case class Auth(token: String) //should be imported as wiro.Auth instead //should be imported as wiro.Auth instead
implicit val authCodec: PlainCodec[Auth] = Codec.string
.mapDecode(decodeAuth)(encodeAuth)
// authCodec: PlainCodec[Auth] = sttp.tapir.Codec$$anon$1@2c88cbda
def decodeAuth(s: String): DecodeResult[Auth] = {
val TokenPattern = "Token token=(.+)".r
s match {
case TokenPattern(token) => DecodeResult.Value(Auth(token))
case _ => DecodeResult.Error(s, new Exception("token not found"))
}
}
def encodeAuth(auth: Auth): String = auth.token
- Run
sbt tapiro