Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for http4s 0.22.x client generation - httpclients_http4s_0_22.scala.template #601

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions cli/src/main/resources/httpclients_http4s_0_22.scala.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package scalaxb

import cats.effect._
import org.http4s._
import org.http4s.client._
import org.typelevel.ci._

trait Http4sClientsF[F[_]] extends HttpClientsF[F] { self =>
implicit protected def F: Concurrent[F]
protected def http4sClient: Client[F]

protected lazy val httpClient: Http4sClientF[F] = new Http4sClientF[F] {
implicit protected def F: Concurrent[F] = self.F
protected def http4sClient: Client[F] = self.http4sClient
}

trait Http4sClientF[G[_]] extends HttpClientF[G] {
implicit protected def F: Concurrent[G]
protected def http4sClient: Client[G]

protected def entityEncoder: EntityEncoder[G, String] =
EntityEncoder[G, String]
protected def entityDecoder: EntityDecoder[G, String] =
EntityDecoder[G, String]

override def request(
in: String,
address: java.net.URI,
headers: Map[String, String]
): G[String] =
request(
in = in,
uri = Uri.unsafeFromString(address.toString),
headers = Headers(headers.map { case (name, value) =>
Header.Raw(CIString(name), value)
}.toList)
)

protected def request(in: String, uri: Uri, headers: Headers): G[String] = {
http4sClient
.expect[String](
Request[G](method = Method.POST, uri = uri)
.withEntity(in)(entityEncoder)
.putHeaders(headers)
)(entityDecoder)
}
}
}
1 change: 1 addition & 0 deletions cli/src/main/scala/scalaxb/compiler/wsdl11/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Driver extends Module { driver =>
} else Nil) ++
(if (config.generateHttp4sClient && config.httpClientStyle == HttpClientStyle.Tagless) config.http4sVersion match {
case VersionPattern(0,21, _) => List(generateFromResource[To](Some("scalaxb"), "httpclients_http4s.scala", "/httpclients_http4s_0_21.scala.template"))
case VersionPattern(0,22, _) => List(generateFromResource[To](Some("scalaxb"), "httpclients_http4s.scala", "/httpclients_http4s_0_22.scala.template"))
case VersionPattern(0,23, _) => List(generateFromResource[To](Some("scalaxb"), "httpclients_http4s.scala", "/httpclients_http4s_0_23.scala.template"))
case _ => sys.error(s"Unsupported http4s version ${config.http4sVersion}"); Nil
}
Expand Down