Created
September 25, 2020 13:37
-
-
Save danslapman/2d8e9b09b6c32f91a9d23f6ef3465dcb to your computer and use it in GitHub Desktop.
asdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@derive(encoder(identity, Some("statusCode"))) | |
sealed trait Result[T] | |
object Result { | |
implicit val swaggerConfig: SwaggerTypeable.Config = | |
SwaggerTypeable.defaultConfig.withDiscriminator("statusCode") | |
.copy(mangleTypeParams = false) | |
implicit def typeable[T: Tag](implicit tType: SwaggerTypeable[T]): SwaggerTypeable[Result[T]] = { | |
val updateRefName: Endo[SwaggerType] = | |
(SwaggerType.refPrism >> SwaggerRef.name) | |
.update(_, name => s"${name}Of${Tag[T].closestClass.getSimpleName}") | |
Swagger.derive[Result[T]].updateTyp( | |
updateRefName andThen | |
((SwaggerType.refPrism >> SwaggerRef.typ) | |
.update(_, _.map { | |
case SwaggerOneOf(alts, discriminator) => | |
SwaggerOneOf(alts.map(second[Option[String], Eval[SwaggerType]] | |
.update(_, _.map(updateRefName))), discriminator) | |
case other => | |
other | |
})) | |
) | |
} | |
} | |
@derive(encoder) | |
case class Success[T](payload: T) extends Result[T] | |
@derive(encoder) | |
case class Error[T](error: Fault) extends Result[T] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment