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

Adding pekko-http support #305

Merged
merged 7 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import java.time.format.DateTimeFormatter
import java.time.{LocalDate, LocalTime}
import java.util.concurrent.TimeUnit

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.marshalling.ToResponseMarshallable
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import org.apache.pekko.http.scaladsl.marshalling.ToResponseMarshallable
import org.apache.pekko.http.scaladsl.model.StatusCodes._
import org.apache.pekko.http.scaladsl.model.{ContentTypes, HttpEntity}
import org.apache.pekko.http.scaladsl.server.Directives._
import org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTest
import org.openjdk.jmh.annotations._
import org.scalatest.{FunSpec, Matchers}
import pl.iterators.kebs.json.KebsSpray
Expand Down
54 changes: 28 additions & 26 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,25 @@ def enumeratumInExamples = {
}
val optionalEnumeratum = optional(enumeratum.cross(CrossVersion.for3Use2_13))

val akkaVersion = "2.6.20"
val akkaHttpVersion = "10.2.10"
val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion
val akkaStreamTestkit = "com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion
val akkaHttp = "com.typesafe.akka" %% "akka-http" % akkaHttpVersion
val akkaHttpTestkit = "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion
def akkaHttpInExamples = {
val akkaHttpSprayJson = "com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion
Seq(akkaStream.cross(CrossVersion.for3Use2_13),
akkaHttp.cross(CrossVersion.for3Use2_13),
akkaHttpSprayJson.cross(CrossVersion.for3Use2_13))
val pekkoVersion = "1.0.1"
val pekkoHttpVersion = "1.0.0"
val pekkoHttpJsonV = "2.0.0"
val pekkoStream = "org.apache.pekko" %% "pekko-stream" % pekkoVersion
val pekkoStreamTestkit = "org.apache.pekko" %% "pekko-stream-testkit" % pekkoVersion
val pekkoHttp = "org.apache.pekko" %% "pekko-http" % pekkoHttpVersion
val pekkoHttpTestkit = "org.apache.pekko" %% "pekko-http-testkit" % pekkoHttpVersion

def pekkoHttpInExamples = {
val pekkoHttpSprayJson = "org.apache.pekko" %% "pekko-http-spray-json" % pekkoHttpVersion
Seq(pekkoStream.cross(CrossVersion.for3Use2_13),
pekkoHttp.cross(CrossVersion.for3Use2_13),
pekkoHttpSprayJson.cross(CrossVersion.for3Use2_13))
}

val http4sVersion = "0.23.23"
val http4s = "org.http4s" %% "http4s-dsl" % http4sVersion

def akkaHttpInBenchmarks = akkaHttpInExamples :+ (akkaHttpTestkit).cross(CrossVersion.for3Use2_13)
def pekkoHttpInBenchmarks = pekkoHttpInExamples :+ (pekkoHttpTestkit).cross(CrossVersion.for3Use2_13)

lazy val commonSettings = baseSettings ++ Seq(
scalacOptions ++=
Expand Down Expand Up @@ -201,10 +203,10 @@ lazy val circeSettings = commonSettings ++ Seq(
libraryDependencies ++= (if (scalaVersion.value.startsWith("3")) Nil
else Seq(circeAutoExtras)))

lazy val akkaHttpSettings = commonSettings ++ Seq(
libraryDependencies += (akkaHttp).cross(CrossVersion.for3Use2_13),
libraryDependencies += (akkaStreamTestkit % "test").cross(CrossVersion.for3Use2_13),
libraryDependencies += (akkaHttpTestkit % "test").cross(CrossVersion.for3Use2_13),
lazy val pekkoHttpSettings = commonSettings ++ Seq(
libraryDependencies += (pekkoHttp).cross(CrossVersion.for3Use2_13),
libraryDependencies += (pekkoStreamTestkit % "test").cross(CrossVersion.for3Use2_13),
libraryDependencies += (pekkoHttpTestkit % "test").cross(CrossVersion.for3Use2_13),
libraryDependencies += optionalEnumeratum.cross(CrossVersion.for3Use2_13),
libraryDependencies ++= paradisePlugin(scalaVersion.value),
scalacOptions ++= paradiseFlag(scalaVersion.value)
Expand Down Expand Up @@ -240,15 +242,15 @@ lazy val examplesSettings = commonSettings ++ Seq(
libraryDependencies += slickPg.cross(CrossVersion.for3Use2_13),
libraryDependencies += circeParser,
libraryDependencies ++= enumeratumInExamples,
libraryDependencies ++= akkaHttpInExamples,
libraryDependencies ++= pekkoHttpInExamples,
libraryDependencies ++= paradisePlugin(scalaVersion.value),
scalacOptions ++= paradiseFlag(scalaVersion.value)
)

lazy val benchmarkSettings = commonSettings ++ Seq(
libraryDependencies += scalaTest.value,
libraryDependencies += enumeratum.cross(CrossVersion.for3Use2_13),
libraryDependencies ++= akkaHttpInBenchmarks
libraryDependencies ++= pekkoHttpInBenchmarks
)

lazy val taggedMetaSettings = metaSettings ++ Seq(
Expand Down Expand Up @@ -363,16 +365,16 @@ lazy val circeSupport = project
moduleName := "kebs-circe"
)

lazy val akkaHttpSupport = project
.in(file("akka-http"))
lazy val pekkoHttpSupport = project
.in(file("pekko-http"))
.dependsOn(core.jvm, instances % "test -> test", tagged.jvm % "test -> test", taggedMeta % "test -> test")
.settings(akkaHttpSettings: _*)
.settings(pekkoHttpSettings: _*)
.settings(publishSettings: _*)
.settings(disableScala(List("3")))
.settings(
name := "akka-http",
description := "Automatic generation of akka-http deserializers for 1-element case classes",
moduleName := "kebs-akka-http",
name := "pekko-http",
description := "Automatic generation of pekko-http deserializers for 1-element case classes",
moduleName := "kebs-pekko-http",
crossScalaVersions := supportedScalaVersions
)

Expand Down Expand Up @@ -465,7 +467,7 @@ lazy val taggedMeta = project

lazy val examples = project
.in(file("examples"))
.dependsOn(slickSupport, sprayJsonSupport, playJsonSupport, akkaHttpSupport, taggedMeta, circeSupport, instances)
.dependsOn(slickSupport, sprayJsonSupport, playJsonSupport, pekkoHttpSupport, taggedMeta, circeSupport, instances)
.settings(examplesSettings: _*)
.settings(noPublishSettings: _*)
.settings(disableScala(List("3")))
Expand Down Expand Up @@ -515,7 +517,7 @@ lazy val kebs = project
circeSupport,
jsonschemaSupport,
scalacheckSupport,
akkaHttpSupport,
pekkoHttpSupport,
http4sSupport,
taggedMeta,
instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package pl.iterators.kebs_examples
import java.net.URL
import java.util.UUID

import akka.http.scaladsl.marshalling.{ToResponseMarshallable, _}
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.model.{ContentType, ContentTypeRange, HttpEntity, MediaType}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.unmarshalling._
import akka.util.ByteString
import org.apache.pekko.http.scaladsl.marshalling.{ToResponseMarshallable, _}
import org.apache.pekko.http.scaladsl.model.MediaTypes.`application/json`
import org.apache.pekko.http.scaladsl.model.StatusCodes._
import org.apache.pekko.http.scaladsl.model.{ContentType, ContentTypeRange, HttpEntity, MediaType}
import org.apache.pekko.http.scaladsl.server.Directives._
import org.apache.pekko.http.scaladsl.server.Route
import org.apache.pekko.http.scaladsl.unmarshalling._
import org.apache.pekko.util.ByteString
import cats.data.NonEmptyList
import io.circe.jawn.parseByteBuffer
import io.circe._
Expand All @@ -27,7 +27,7 @@ object CirceExample {
}

object BeforeKebs {
object ThingProtocol extends CirceProtocol with CirceAkkaHttpSupport {
object ThingProtocol extends CirceProtocol with CircePekkoHttpSupport {
import io.circe._
import io.circe.generic.semiauto._
implicit val thingCreateRequestEncoder: Encoder[ThingCreateRequest] = deriveEncoder
Expand Down Expand Up @@ -62,7 +62,7 @@ object CirceExample {
}

object AfterKebs {
object ThingProtocol extends KebsCirce with CirceProtocol with CirceAkkaHttpSupport
object ThingProtocol extends KebsCirce with CirceProtocol with CircePekkoHttpSupport
import ThingProtocol._

class ThingRouter(thingsService: ThingsService)(implicit ec: ExecutionContext) {
Expand Down Expand Up @@ -105,7 +105,7 @@ object CirceExample {
}
}

trait CirceAkkaHttpSupport {
trait CircePekkoHttpSupport {

implicit def jsonUnmarshaller[T](implicit reader: Decoder[T]): FromEntityUnmarshaller[T] =
jsonUnmarshaller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package pl.iterators.kebs_examples
import java.net.URL
import java.util.UUID

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.marshalling.ToResponseMarshallable
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.server.Directives._
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import org.apache.pekko.http.scaladsl.marshalling.ToResponseMarshallable
import org.apache.pekko.http.scaladsl.model.StatusCodes._
import org.apache.pekko.http.scaladsl.server.Directives._
import enumeratum.{Enum, EnumEntry}
import pl.iterators.kebs.json.{KebsEnumFormats, KebsSpray}
import spray.json.{DefaultJsonProtocol, JsString, JsValue, JsonFormat, JsonReader, JsonWriter, deserializationError}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package pl.iterators.kebs_examples

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.unmarshalling.{FromStringUnmarshaller, Unmarshaller}
import akka.http.scaladsl.util.FastFuture
import org.apache.pekko.http.scaladsl.model.StatusCodes
import org.apache.pekko.http.scaladsl.server.Directives._
import org.apache.pekko.http.scaladsl.unmarshalling.{FromStringUnmarshaller, Unmarshaller}
import org.apache.pekko.http.scaladsl.util.FastFuture
import enumeratum.values._
import enumeratum.{Enum, EnumEntry}

object AkkaHttpUnmarshallers {
object PekkoHttpUnmarshallers {
sealed abstract class Column(val value: Int) extends IntEnumEntry
object Column extends IntEnum[Column] {
case object Name extends Column(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.iterators.kebs_examples

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.marshalling.ToResponseMarshallable
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.server.Directives._
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import org.apache.pekko.http.scaladsl.marshalling.ToResponseMarshallable
import org.apache.pekko.http.scaladsl.model.StatusCodes._
import org.apache.pekko.http.scaladsl.server.Directives._
import pl.iterators.kebs.instances.net.URIString
import pl.iterators.kebs.instances.util.UUIDString
import pl.iterators.kebs.json.KebsSpray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import java.io.IOException
import java.time.format.DateTimeFormatter
import java.time.{LocalDate, LocalTime}

import akka.actor.ActorSystem
import akka.event.LoggingAdapter
import akka.http.scaladsl.Http
import akka.http.scaladsl.client.RequestBuilding
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.model.Uri.Query
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.Materializer
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.event.LoggingAdapter
import org.apache.pekko.http.scaladsl.Http
import org.apache.pekko.http.scaladsl.client.RequestBuilding
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import org.apache.pekko.http.scaladsl.model.StatusCodes._
import org.apache.pekko.http.scaladsl.model.Uri.Query
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model.headers.RawHeader
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
import org.apache.pekko.stream.Materializer
import pl.iterators.kebs.json.KebsSpray
import spray.json._

import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try

object SprayJsonWithAkkaHttpExample {
object SprayJsonWithPekkoHttpExample {
trait Protocol extends DefaultJsonProtocol with SprayJsonSupport with KebsSpray {
implicit val localTimeFormat = new JsonFormat[LocalTime] {
override def write(obj: LocalTime): JsValue = JsString(formatter.format(obj))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pl.iterators.kebs.matchers

import akka.http.scaladsl.server.{PathMatcher1, PathMatchers}
import org.apache.pekko.http.scaladsl.server.{PathMatcher1, PathMatchers}
import enumeratum.{Enum, EnumEntry}
import pl.iterators.kebs.instances.InstanceConverter
import pl.iterators.kebs.macros.CaseClass1Rep
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pl.iterators.kebs.unmarshallers

import akka.http.scaladsl.unmarshalling.{FromStringUnmarshaller, Unmarshaller}
import org.apache.pekko.http.scaladsl.unmarshalling.{FromStringUnmarshaller, Unmarshaller}
import pl.iterators.kebs.instances.InstanceConverter
import pl.iterators.kebs.macros.CaseClass1Rep

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pl.iterators.kebs.unmarshallers.enums

import akka.http.scaladsl.unmarshalling.PredefinedFromStringUnmarshallers._
import akka.http.scaladsl.unmarshalling.{FromStringUnmarshaller, Unmarshaller}
import akka.http.scaladsl.util.FastFuture
import org.apache.pekko.http.scaladsl.unmarshalling.PredefinedFromStringUnmarshallers._
import org.apache.pekko.http.scaladsl.unmarshalling.{FromStringUnmarshaller, Unmarshaller}
import org.apache.pekko.http.scaladsl.util.FastFuture
import enumeratum.values._
import enumeratum.{Enum, EnumEntry}
import pl.iterators.kebs.macros.enums.{EnumOf, ValueEnumOf}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.iterators.kebs.matchers

import akka.http.scaladsl.server.Directives
import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.apache.pekko.http.scaladsl.server.Directives
import org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTest
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
Expand All @@ -13,7 +13,7 @@ import pl.iterators.kebs.instances.time.{DayOfWeekInt, ZonedDateTimeString}
import java.net.URI
import java.time.{DayOfWeek, Instant, ZonedDateTime}

class AkkaHttpMatchersTests
class PekkoHttpMatchersTests
extends AnyFunSuite
with Matchers
with Directives
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.iterators.kebs.unmarshallers

import akka.http.scaladsl.model.FormData
import akka.http.scaladsl.server.{Directives, MalformedQueryParamRejection}
import akka.http.scaladsl.testkit.ScalatestRouteTest
import akka.http.scaladsl.unmarshalling.Unmarshal
import org.apache.pekko.http.scaladsl.model.FormData
import org.apache.pekko.http.scaladsl.server.{Directives, MalformedQueryParamRejection}
import org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTest
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
Expand All @@ -14,7 +14,7 @@ import pl.iterators.kebs.unmarshallers.enums.KebsEnumUnmarshallers

import java.time.{DayOfWeek, YearMonth}

class AkkaHttpUnmarshallersTests
class PekkoHttpUnmarshallersTests
extends AnyFunSuite
with Matchers
with ScalatestRouteTest
Expand Down
Loading