Skip to content

Commit 56eb8f7

Browse files
authored
update akka-http and pekko-http server generator and example (#21166)
1 parent 3bac186 commit 56eb8f7

File tree

11 files changed

+40
-22
lines changed

11 files changed

+40
-22
lines changed

docs/generators/scala-akka-http-server.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1818

1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
21-
|akkaHttpVersion|The version of akka-http| |10.1.10|
21+
|akkaHttpVersion|The version of akka-http| |10.2.9|
2222
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
2323
|apiPackage|package for generated api classes| |null|
2424
|artifactId|artifactId| |openapi-scala-akka-http-server|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaHttpServerCodegen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
5151
public static final String AKKA_HTTP_VERSION_DESC = "The version of akka-http";
5252
public static final String PEKKO_HTTP_VERSION = "pekkoHttpVersion";
5353
public static final String PEKKO_HTTP_VERSION_DESC = "The version of pekko-http";
54-
public static final String DEFAULT_AKKA_HTTP_VERSION = "10.1.10";
54+
public static final String DEFAULT_AKKA_HTTP_VERSION = "10.2.9";
5555
public static final String DEFAULT_PEKKO_HTTP_VERSION = "1.1.0";
5656

5757
public static final String GENERATE_AS_MANAGED_SOURCES = "asManagedSources";
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
version := "{{artifactVersion}}"
22
name := "{{artifactId}}"
33
organization := "{{groupId}}"
4-
scalaVersion := "2.12.20"
4+
scalaVersion := "2.13.16"
55

66
libraryDependencies ++= Seq({{#useApachePekko}}
7-
"org.apache.pekko" %% "pekko-stream" % "1.0.3",
7+
"org.apache.pekko" %% "pekko-stream" % "1.1.3",
88
"org.apache.pekko" %% "pekko-http" % "{{pekkoHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}}
9-
"com.typesafe.akka" %% "akka-stream" % "2.5.21",
9+
"com.typesafe.akka" %% "akka-stream" % "2.6.21",
1010
"com.typesafe.akka" %% "akka-http" % "{{akkaHttpVersion}}"{{/useApachePekko}}
1111
)
12+
13+
scalacOptions ++= Seq(
14+
"-deprecation",
15+
"-feature",
16+
)

modules/openapi-generator/src/main/resources/scala-akka-http-server/controller.mustache

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {{akkaImportGroupId}}.http.scaladsl.server.Route
66
{{/operations}}{{/apis}}{{/apiInfo}}
77
import {{akkaImportGroupId}}.http.scaladsl.server.Directives._
88
import {{akkaImportGroupId}}.actor.ActorSystem
9-
import {{akkaImportGroupId}}.stream.ActorMaterializer
9+
import {{akkaImportGroupId}}.stream.Materializer
1010

11-
class Controller({{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}: {{classname}}{{^-last}}, {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}})(implicit system: ActorSystem, materializer: ActorMaterializer) {
11+
class Controller({{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}: {{classname}}{{^-last}}, {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}})(implicit system: ActorSystem, materializer: Materializer) {
1212
1313
lazy val routes: Route = {{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}.route {{^-last}}~ {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}}
1414

15-
Http().bindAndHandle(routes, "0.0.0.0", 9000)
16-
}
15+
Http().newServerAt("0.0.0.0", 9000).bind(routes)
16+
}

modules/openapi-generator/src/main/resources/scala-akka-http-server/stringDirectives.mustache

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {{akkaImportGroupId}}.http.scaladsl.server.directives.BasicDirectives
66
import {{akkaImportGroupId}}.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
77

88
import scala.concurrent.Future
9+
import scala.language.implicitConversions
910
import scala.util.{Failure, Success}
1011

1112
trait StringDirectives {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
version := "1.0.0"
22
name := "openapi-scala-akka-http-server"
33
organization := "org.openapitools"
4-
scalaVersion := "2.12.20"
4+
scalaVersion := "2.13.16"
55

66
libraryDependencies ++= Seq(
7-
"com.typesafe.akka" %% "akka-stream" % "2.5.21",
8-
"com.typesafe.akka" %% "akka-http" % "10.1.10"
7+
"com.typesafe.akka" %% "akka-stream" % "2.6.21",
8+
"com.typesafe.akka" %% "akka-http" % "10.2.9"
9+
)
10+
11+
scalacOptions ++= Seq(
12+
"-deprecation",
13+
"-feature",
914
)

samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/Controller.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import org.openapitools.server.api.UserApi
88

99
import akka.http.scaladsl.server.Directives._
1010
import akka.actor.ActorSystem
11-
import akka.stream.ActorMaterializer
11+
import akka.stream.Materializer
1212

13-
class Controller(pet: PetApi, store: StoreApi, user: UserApi)(implicit system: ActorSystem, materializer: ActorMaterializer) {
13+
class Controller(pet: PetApi, store: StoreApi, user: UserApi)(implicit system: ActorSystem, materializer: Materializer) {
1414

1515
lazy val routes: Route = pet.route ~ store.route ~ user.route
1616

17-
Http().bindAndHandle(routes, "0.0.0.0", 9000)
18-
}
17+
Http().newServerAt("0.0.0.0", 9000).bind(routes)
18+
}

samples/server/petstore/scala-akka-http-server/src/main/scala/org/openapitools/server/StringDirectives.scala

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import akka.http.scaladsl.server.directives.BasicDirectives
66
import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
77

88
import scala.concurrent.Future
9+
import scala.language.implicitConversions
910
import scala.util.{Failure, Success}
1011

1112
trait StringDirectives {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
version := "1.0.0"
22
name := "openapi-scala-pekko-http-server"
33
organization := "org.openapitools"
4-
scalaVersion := "2.12.20"
4+
scalaVersion := "2.13.16"
55

66
libraryDependencies ++= Seq(
7-
"org.apache.pekko" %% "pekko-stream" % "1.0.3",
7+
"org.apache.pekko" %% "pekko-stream" % "1.1.3",
88
"org.apache.pekko" %% "pekko-http" % "1.1.0"
99
)
10+
11+
scalacOptions ++= Seq(
12+
"-deprecation",
13+
"-feature",
14+
)

samples/server/petstore/scala-pekko-http-server/src/main/scala/org/openapitools/server/Controller.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import org.openapitools.server.api.UserApi
88

99
import org.apache.pekko.http.scaladsl.server.Directives._
1010
import org.apache.pekko.actor.ActorSystem
11-
import org.apache.pekko.stream.ActorMaterializer
11+
import org.apache.pekko.stream.Materializer
1212

13-
class Controller(pet: PetApi, store: StoreApi, user: UserApi)(implicit system: ActorSystem, materializer: ActorMaterializer) {
13+
class Controller(pet: PetApi, store: StoreApi, user: UserApi)(implicit system: ActorSystem, materializer: Materializer) {
1414

1515
lazy val routes: Route = pet.route ~ store.route ~ user.route
1616

17-
Http().bindAndHandle(routes, "0.0.0.0", 9000)
18-
}
17+
Http().newServerAt("0.0.0.0", 9000).bind(routes)
18+
}

samples/server/petstore/scala-pekko-http-server/src/main/scala/org/openapitools/server/StringDirectives.scala

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.apache.pekko.http.scaladsl.server.directives.BasicDirectives
66
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
77

88
import scala.concurrent.Future
9+
import scala.language.implicitConversions
910
import scala.util.{Failure, Success}
1011

1112
trait StringDirectives {

0 commit comments

Comments
 (0)