Closed abteilung6 closed 1 year ago
I just moved to enumeratum and it works.
FYI, if you are using latest tapir, as per https://tapir.softwaremill.com/en/latest/endpoint/enumerations.html when using an enumeration inside a query param, this works:
import sttp.tapir._
object Provider extends Enumeration {
type ProviderValue = Value
val Credentials: Provider.Value = Value("credentials")
val Ldap: Provider.Value = Value("ldap")
}
val signInEndpoint: PublicEndpoint[Provider.ProviderValue, Unit, Unit, Any] =
endpoint.post.in(query[Provider.ProviderValue]("provider"))
Alternative with enumeratum package
package org.abteilung6.ocean
package repositories.dto
import enumeratum._
import sttp.tapir.codec.enumeratum.TapirCodecEnumeratum
sealed abstract class AuthenticatorType(override val entryName: String) extends EnumEntry
object AuthenticatorType extends Enum[AuthenticatorType] with TapirCodecEnumeratum with CirceEnum[AuthenticatorType] {
val values: IndexedSeq[AuthenticatorType] = findValues
case object Directory extends AuthenticatorType("directory")
case object Credentials extends AuthenticatorType("credentials")
}
Endpoint could look like
val signInEndpoint: PublicEndpoint[(AuthenticatorType, SignInRequest), ResponseError, AuthResponse, Any] =
endpoint.post
.tag(tag)
.description("Sign in with an authenticator")
.in(this.withSubEndpoint("signin"))
.in(query[AuthenticatorType]("authenticator"))
.in(jsonBody[SignInRequest])
.errorOut(jsonBody[ResponseError])
.out(jsonBody[AuthResponse])
def signInLogic(
authenticatorType: AuthenticatorType,
signInRequest: SignInRequest
): Future[Either[ResponseError, AuthResponse]] = ???
But needs some other dependencies when working with slick.
Having an enum called Provider which is quite the same like in the docs
I want to have an endpoint
But get following error: No implicit arguments of type: Codec[List[String], Provider.Value, CodecFormat.TextPlain]