update akka-http and pekko-http server generator and example (#21166)

This commit is contained in:
kenji yoshida 2025-04-30 02:46:49 +09:00 committed by GitHub
parent 3bac186b2f
commit 56eb8f7bc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 40 additions and 22 deletions

View File

@ -18,7 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| Option | Description | Values | Default | | Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- | | ------ | ----------- | ------ | ------- |
|akkaHttpVersion|The version of akka-http| |10.1.10| |akkaHttpVersion|The version of akka-http| |10.2.9|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| |allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|apiPackage|package for generated api classes| |null| |apiPackage|package for generated api classes| |null|
|artifactId|artifactId| |openapi-scala-akka-http-server| |artifactId|artifactId| |openapi-scala-akka-http-server|

View File

@ -51,7 +51,7 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements
public static final String AKKA_HTTP_VERSION_DESC = "The version of akka-http"; public static final String AKKA_HTTP_VERSION_DESC = "The version of akka-http";
public static final String PEKKO_HTTP_VERSION = "pekkoHttpVersion"; public static final String PEKKO_HTTP_VERSION = "pekkoHttpVersion";
public static final String PEKKO_HTTP_VERSION_DESC = "The version of pekko-http"; public static final String PEKKO_HTTP_VERSION_DESC = "The version of pekko-http";
public static final String DEFAULT_AKKA_HTTP_VERSION = "10.1.10"; public static final String DEFAULT_AKKA_HTTP_VERSION = "10.2.9";
public static final String DEFAULT_PEKKO_HTTP_VERSION = "1.1.0"; public static final String DEFAULT_PEKKO_HTTP_VERSION = "1.1.0";
public static final String GENERATE_AS_MANAGED_SOURCES = "asManagedSources"; public static final String GENERATE_AS_MANAGED_SOURCES = "asManagedSources";

View File

@ -1,11 +1,16 @@
version := "{{artifactVersion}}" version := "{{artifactVersion}}"
name := "{{artifactId}}" name := "{{artifactId}}"
organization := "{{groupId}}" organization := "{{groupId}}"
scalaVersion := "2.12.20" scalaVersion := "2.13.16"
libraryDependencies ++= Seq({{#useApachePekko}} libraryDependencies ++= Seq({{#useApachePekko}}
"org.apache.pekko" %% "pekko-stream" % "1.0.3", "org.apache.pekko" %% "pekko-stream" % "1.1.3",
"org.apache.pekko" %% "pekko-http" % "{{pekkoHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}} "org.apache.pekko" %% "pekko-http" % "{{pekkoHttpVersion}}"{{/useApachePekko}}{{^useApachePekko}}
"com.typesafe.akka" %% "akka-stream" % "2.5.21", "com.typesafe.akka" %% "akka-stream" % "2.6.21",
"com.typesafe.akka" %% "akka-http" % "{{akkaHttpVersion}}"{{/useApachePekko}} "com.typesafe.akka" %% "akka-http" % "{{akkaHttpVersion}}"{{/useApachePekko}}
) )
scalacOptions ++= Seq(
"-deprecation",
"-feature",
)

View File

@ -6,11 +6,11 @@ import {{akkaImportGroupId}}.http.scaladsl.server.Route
{{/operations}}{{/apis}}{{/apiInfo}} {{/operations}}{{/apis}}{{/apiInfo}}
import {{akkaImportGroupId}}.http.scaladsl.server.Directives._ import {{akkaImportGroupId}}.http.scaladsl.server.Directives._
import {{akkaImportGroupId}}.actor.ActorSystem import {{akkaImportGroupId}}.actor.ActorSystem
import {{akkaImportGroupId}}.stream.ActorMaterializer import {{akkaImportGroupId}}.stream.Materializer
class Controller({{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}: {{classname}}{{^-last}}, {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}})(implicit system: ActorSystem, materializer: ActorMaterializer) { class Controller({{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}: {{classname}}{{^-last}}, {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}})(implicit system: ActorSystem, materializer: Materializer) {
lazy val routes: Route = {{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}.route {{^-last}}~ {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}} lazy val routes: Route = {{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}.route {{^-last}}~ {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}}
Http().bindAndHandle(routes, "0.0.0.0", 9000) Http().newServerAt("0.0.0.0", 9000).bind(routes)
} }

View File

@ -6,6 +6,7 @@ import {{akkaImportGroupId}}.http.scaladsl.server.directives.BasicDirectives
import {{akkaImportGroupId}}.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import {{akkaImportGroupId}}.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
import scala.concurrent.Future import scala.concurrent.Future
import scala.language.implicitConversions
import scala.util.{Failure, Success} import scala.util.{Failure, Success}
trait StringDirectives { trait StringDirectives {

View File

@ -1,9 +1,14 @@
version := "1.0.0" version := "1.0.0"
name := "openapi-scala-akka-http-server" name := "openapi-scala-akka-http-server"
organization := "org.openapitools" organization := "org.openapitools"
scalaVersion := "2.12.20" scalaVersion := "2.13.16"
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-stream" % "2.5.21", "com.typesafe.akka" %% "akka-stream" % "2.6.21",
"com.typesafe.akka" %% "akka-http" % "10.1.10" "com.typesafe.akka" %% "akka-http" % "10.2.9"
)
scalacOptions ++= Seq(
"-deprecation",
"-feature",
) )

View File

@ -8,11 +8,11 @@ import org.openapitools.server.api.UserApi
import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Directives._
import akka.actor.ActorSystem import akka.actor.ActorSystem
import akka.stream.ActorMaterializer import akka.stream.Materializer
class Controller(pet: PetApi, store: StoreApi, user: UserApi)(implicit system: ActorSystem, materializer: ActorMaterializer) { class Controller(pet: PetApi, store: StoreApi, user: UserApi)(implicit system: ActorSystem, materializer: Materializer) {
lazy val routes: Route = pet.route ~ store.route ~ user.route lazy val routes: Route = pet.route ~ store.route ~ user.route
Http().bindAndHandle(routes, "0.0.0.0", 9000) Http().newServerAt("0.0.0.0", 9000).bind(routes)
} }

View File

@ -6,6 +6,7 @@ import akka.http.scaladsl.server.directives.BasicDirectives
import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
import scala.concurrent.Future import scala.concurrent.Future
import scala.language.implicitConversions
import scala.util.{Failure, Success} import scala.util.{Failure, Success}
trait StringDirectives { trait StringDirectives {

View File

@ -1,9 +1,14 @@
version := "1.0.0" version := "1.0.0"
name := "openapi-scala-pekko-http-server" name := "openapi-scala-pekko-http-server"
organization := "org.openapitools" organization := "org.openapitools"
scalaVersion := "2.12.20" scalaVersion := "2.13.16"
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"org.apache.pekko" %% "pekko-stream" % "1.0.3", "org.apache.pekko" %% "pekko-stream" % "1.1.3",
"org.apache.pekko" %% "pekko-http" % "1.1.0" "org.apache.pekko" %% "pekko-http" % "1.1.0"
) )
scalacOptions ++= Seq(
"-deprecation",
"-feature",
)

View File

@ -8,11 +8,11 @@ import org.openapitools.server.api.UserApi
import org.apache.pekko.http.scaladsl.server.Directives._ import org.apache.pekko.http.scaladsl.server.Directives._
import org.apache.pekko.actor.ActorSystem import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.ActorMaterializer import org.apache.pekko.stream.Materializer
class Controller(pet: PetApi, store: StoreApi, user: UserApi)(implicit system: ActorSystem, materializer: ActorMaterializer) { class Controller(pet: PetApi, store: StoreApi, user: UserApi)(implicit system: ActorSystem, materializer: Materializer) {
lazy val routes: Route = pet.route ~ store.route ~ user.route lazy val routes: Route = pet.route ~ store.route ~ user.route
Http().bindAndHandle(routes, "0.0.0.0", 9000) Http().newServerAt("0.0.0.0", 9000).bind(routes)
} }

View File

@ -6,6 +6,7 @@ import org.apache.pekko.http.scaladsl.server.directives.BasicDirectives
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException
import scala.concurrent.Future import scala.concurrent.Future
import scala.language.implicitConversions
import scala.util.{Failure, Success} import scala.util.{Failure, Success}
trait StringDirectives { trait StringDirectives {