Skip to content

Commit ebc1d7b

Browse files
authored
[scala][akka] Update dependencies for scala 2.13 in scala-akka (#8624)
* [scala][akka] Update dependencies for scala 2.13 * Update pom.mustache to support multiple scala's version * Update pom.xml * Scala cross build 2.12 and 2.13 * Update version. Migrate to sbt * Remove space * Add pom.xml back
1 parent dbb42f9 commit ebc1d7b

14 files changed

Lines changed: 143 additions & 91 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,16 @@ public void processOpts() {
166166
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
167167

168168
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
169-
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
170169
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
170+
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
171171
supportingFiles.add(new SupportingFile("reference.mustache", resourcesFolder, "reference.conf"));
172172
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
173173
supportingFiles.add(new SupportingFile("apiRequest.mustache", invokerFolder, "ApiRequest.scala"));
174174
supportingFiles.add(new SupportingFile("apiInvoker.mustache", invokerFolder, "ApiInvoker.scala"));
175175
supportingFiles.add(new SupportingFile("requests.mustache", invokerFolder, "requests.scala"));
176176
supportingFiles.add(new SupportingFile("apiSettings.mustache", invokerFolder, "ApiSettings.scala"));
177177
final String apiFolder = (sourceFolder + File.separator + apiPackage).replace(".", File.separator);
178+
supportingFiles.add(new SupportingFile("project/build.properties.mustache", "project", "build.properties"));
178179
supportingFiles.add(new SupportingFile("enumsSerializers.mustache", apiFolder, "EnumsSerializers.scala"));
179180
supportingFiles.add(new SupportingFile("serializers.mustache", invokerFolder, "Serializers.scala"));
180181
}

modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import de.heikoseeberger.akkahttpjson4s.Json4sSupport
1818
import org.json4s._
1919
import org.json4s.jackson.JsonMethods._
2020
import org.json4s.jackson.Serialization
21+
import scala.collection.compat._
2122

2223
import scala.collection.immutable
2324
import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor, Future }
@@ -86,7 +87,7 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC
8687
8788
private val http = Http()
8889
89-
val CompressionFilter: HttpMessage Boolean = (msg: HttpMessage) =>
90+
val CompressionFilter: HttpMessage => Boolean = (msg: HttpMessage) =>
9091
Seq(
9192
{ _: HttpMessage => settings.compressionEnabled },
9293
Encoder.DefaultFilter,
@@ -115,7 +116,7 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC
115116
private def headers(headers: Map[String, Any]): immutable.Seq[HttpHeader] =
116117
headers.asFormattedParams
117118
.map { case (name, value) => RawHeader(name, value.toString) }
118-
.to[immutable.Seq]
119+
.to(immutable.Seq)
119120
120121
121122
private def bodyPart(name: String, value: Any): BodyPart = {
@@ -147,9 +148,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC
147148
case MediaTypes.`multipart/form-data` =>
148149
Multipart.FormData(Source(params.toList.map { case (name, value) => bodyPart(name, value) }))
149150
case MediaTypes.`application/x-www-form-urlencoded` =>
150-
FormData(params.mapValues(_.toString))
151+
FormData(params.view.mapValues(_.toString).toMap)
151152
case _: MediaType => // Default : application/x-www-form-urlencoded.
152-
FormData(params.mapValues(_.toString))
153+
FormData(params.view.mapValues(_.toString).toMap)
153154
}
154155
)
155156
}
@@ -187,7 +188,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC
187188
params + (keyName -> key.value)
188189
case (params, _) => params
189190
}.asFormattedParams
191+
.view
190192
.mapValues(_.toString)
193+
.toMap
191194
.foldRight[Query](Uri.Query.Empty) {
192195
case ((name, value), acc) => acc.+:(name, value)
193196
}
@@ -196,7 +199,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC
196199
def makeUri(r: ApiRequest[_]): Uri = {
197200
val opPath = r.operationPath.replaceAll("\\{format\\}", "json")
198201
val opPathWithParams = r.pathParams.asFormattedParams
202+
.view
199203
.mapValues(_.toString)
204+
.toMap
200205
.foldLeft(opPath) {
201206
case (path, (name, value)) => path.replaceAll(s"\\{$name\\}", value)
202207
}
@@ -213,13 +218,13 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC
213218
http
214219
.singleRequest(request)
215220
.map { response =>
216-
val decoder: Coder with StreamDecoder = response.encoding match {
217-
case HttpEncodings.gzip
218-
Gzip
219-
case HttpEncodings.deflate
220-
Deflate
221-
case HttpEncodings.identity
222-
NoCoding
221+
val decoder: Decoder with Decoder = response.encoding match {
222+
case HttpEncodings.gzip =>
223+
Coders.Gzip
224+
case HttpEncodings.deflate =>
225+
Coders.Deflate
226+
case HttpEncodings.identity =>
227+
Coders.NoCoding
223228
case HttpEncoding(encoding) =>
224229
throw new IllegalArgumentException(s"Unsupported encoding: $encoding")
225230
}
@@ -247,13 +252,13 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC
247252
request
248253
.responseForCode(response.status.intValue) match {
249254
case Some((Manifest.Unit, state: ResponseState)) =>
250-
Future(responseForState(state, Unit).asInstanceOf[ApiResponse[T]])
255+
Future(responseForState(state, ()).asInstanceOf[ApiResponse[T]])
251256
case Some((manifest, state: ResponseState)) if manifest == mf =>
252257
implicit val m: Unmarshaller[HttpEntity, T] = unmarshaller[T](mf, serialization, formats)
253258
Unmarshal(response.entity)
254259
.to[T]
255260
.recoverWith {
256-
case e throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e)
261+
case e => throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e)
257262
}
258263
.map(value => responseForState(state, value))
259264
case None | Some(_) =>

modules/openapi-generator/src/main/resources/scala-akka-client/apiSettings.mustache

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package {{invokerPackage}}
33

44
import java.util.concurrent.TimeUnit
55

6-
import akka.actor.{ ExtendedActorSystem, Extension, ExtensionKey }
6+
import akka.actor.{ActorSystem, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider}
77
import akka.http.scaladsl.model.StatusCodes.CustomStatusCode
88
import akka.http.scaladsl.model.headers.RawHeader
99
import com.typesafe.config.Config
1010

11-
import scala.collection.JavaConverters._
11+
import scala.jdk.CollectionConverters._
1212
import scala.concurrent.duration.FiniteDuration
1313

1414
class ApiSettings(config: Config) extends Extension {
@@ -32,4 +32,13 @@ class ApiSettings(config: Config) extends Extension {
3232
}
3333
}
3434

35-
object ApiSettings extends ExtensionKey[ApiSettings]
35+
object ApiSettings extends ExtensionId[ApiSettings] with ExtensionIdProvider {
36+
37+
override def lookup = ApiSettings
38+
39+
override def createExtension(system: ExtendedActorSystem): ApiSettings =
40+
new ApiSettings(system)
41+
42+
// needed to get the type right when used from Java
43+
override def get(system: ActorSystem): ApiSettings = super.get(system)
44+
}

modules/openapi-generator/src/main/resources/scala-akka-client/build.sbt.mustache

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
version := "{{artifactVersion}}"
22
name := "{{artifactId}}"
33
organization := "{{groupId}}"
4-
scalaVersion := "2.12.8"
4+
5+
scalaVersion := "2.12.13"
6+
crossScalaVersions := Seq(scalaVersion.value, "2.13.4")
7+
58

69
libraryDependencies ++= Seq(
7-
"com.typesafe" % "config" % "1.3.3",
8-
"com.typesafe.akka" %% "akka-actor" % "2.5.21",
9-
"com.typesafe.akka" %% "akka-stream" % "2.5.21",
10-
"com.typesafe.akka" %% "akka-http" % "10.1.7",
10+
"com.typesafe" % "config" % "1.4.1",
11+
"com.typesafe.akka" %% "akka-actor" % "2.6.12",
12+
"com.typesafe.akka" %% "akka-stream" % "2.6.12",
13+
"com.typesafe.akka" %% "akka-http" % "10.2.3",
1114
{{#joda}}
1215
"joda-time" % "joda-time" % "2.10.1",
1316
{{/joda}}
14-
"org.json4s" %% "json4s-jackson" % "3.6.5",
15-
"org.json4s" %% "json4s-ext" % "3.6.5",
16-
"de.heikoseeberger" %% "akka-http-json4s" % "1.25.2",
17+
"org.json4s" %% "json4s-jackson" % "3.6.7",
18+
"org.json4s" %% "json4s-ext" % "3.6.7",
19+
"de.heikoseeberger" %% "akka-http-json4s" % "1.27.0",
20+
"org.scala-lang.modules" %% "scala-collection-compat" % "2.4.1",
1721
// test dependencies
18-
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
19-
"junit" % "junit" % "4.13.1" % "test"
22+
"org.scalatest" %% "scalatest" % "3.2.3" % "test",
23+
"org.scalatestplus" %% "junit-4-13" % "3.2.3.0" % "test"
2024
)
2125

2226
resolvers ++= Seq(Resolver.mavenLocal)

modules/openapi-generator/src/main/resources/scala-akka-client/pom.mustache

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1616

1717
<java.version>1.8</java.version>
18-
<scala.version>2.12.8</scala.version>
19-
<json4s.jackson.version>3.5.3</json4s.jackson.version>
20-
<json4s.ext.version>3.2.11</json4s.ext.version>
21-
<akka.version>2.5.21</akka.version>
22-
<akka.http.version>10.1.7</akka.http.version>
18+
<scala.version>2.12.13</scala.version>
19+
<json4s.jackson.version>3.6.7</json4s.jackson.version>
20+
<json4s.ext.version>3.6.7</json4s.ext.version>
21+
<akka.version>2.6.12</akka.version>
22+
<akka.http.version>10.2.3</akka.http.version>
2323
{{#joda}}
2424
<joda.time.version>2.10.1</joda.time.version>
2525
{{/joda}}
26-
<typesafeconfig.version>1.3.3</typesafeconfig.version>
27-
<akka.http.json4s.version>1.25.2</akka.http.json4s.version>
28-
<junit.version>4.13.1</junit.version>
29-
<scala.test.version>3.0.5</scala.test.version>
26+
<typesafeconfig.version>1.4.1</typesafeconfig.version>
27+
<akka.http.json4s.version>1.27.0</akka.http.json4s.version>
28+
<scala.compat.version>2.4.1</scala.compat.version>
29+
<scala.test.version>3.2.3</scala.test.version>
30+
<scala.test.plus.version>3.2.3.0</scala.test.plus.version>
3031

3132
<scala.maven.plugin.version>3.3.1</scala.maven.plugin.version>
3233
</properties>
@@ -80,6 +81,11 @@
8081
<artifactId>akka-http-json4s_2.12</artifactId>
8182
<version>${akka.http.json4s.version}</version>
8283
</dependency>
84+
<dependency>
85+
<groupId>org.scala-lang.modules</groupId>
86+
<artifactId>scala-collection-compat_2.12</artifactId>
87+
<version>${scala.compat.version}</version>
88+
</dependency>
8389

8490
<!--test dependencies-->
8591
<dependency>
@@ -89,9 +95,9 @@
8995
<scope>test</scope>
9096
</dependency>
9197
<dependency>
92-
<groupId>junit</groupId>
93-
<artifactId>junit</artifactId>
94-
<version>${junit.version}</version>
98+
<groupId>org.scalatestplus</groupId>
99+
<artifactId>junit-4-13_2.12</artifactId>
100+
<version>${scala.test.plus.version}</version>
95101
<scope>test</scope>
96102
</dependency>
97103
</dependencies>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.3.10

modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public void mainPackageTest() throws Exception {
472472
Generator gen = generator.opts(clientOptInput);
473473
List<File> files = gen.generate();
474474

475-
Assert.assertEquals(files.size(), 15);
475+
Assert.assertEquals(files.size(), 16);
476476

477477
TestUtils.ensureContainsFile(files, output, "src/main/scala/hello/world/model/SomeObj.scala");
478478
TestUtils.ensureContainsFile(files, output, "src/main/scala/hello/world/core/ApiSettings.scala");
@@ -509,7 +509,7 @@ public void overridePackagesTest() throws Exception {
509509
Generator gen = generator.opts(clientOptInput);
510510

511511
List<File> files = gen.generate();
512-
Assert.assertEquals(files.size(), 15);
512+
Assert.assertEquals(files.size(), 16);
513513

514514
TestUtils.ensureContainsFile(files, output, "src/main/scala/hello/world/model/package/SomeObj.scala");
515515
TestUtils.ensureContainsFile(files, output, "src/main/scala/hello/world/package/invoker/ApiSettings.scala");

samples/client/petstore/scala-akka/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
README.md
22
build.sbt
3+
project/build.properties
34
src/main/resources/reference.conf
45
src/main/scala/org/openapitools/client/api/EnumsSerializers.scala
56
src/main/scala/org/openapitools/client/api/PetApi.scala

samples/client/petstore/scala-akka/build.sbt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
version := "1.0.0"
22
name := "scala-akka-petstore-client"
33
organization := "org.openapitools"
4-
scalaVersion := "2.12.8"
4+
5+
scalaVersion := "2.12.13"
6+
crossScalaVersions := Seq(scalaVersion.value, "2.13.4")
7+
58

69
libraryDependencies ++= Seq(
7-
"com.typesafe" % "config" % "1.3.3",
8-
"com.typesafe.akka" %% "akka-actor" % "2.5.21",
9-
"com.typesafe.akka" %% "akka-stream" % "2.5.21",
10-
"com.typesafe.akka" %% "akka-http" % "10.1.7",
11-
"org.json4s" %% "json4s-jackson" % "3.6.5",
12-
"org.json4s" %% "json4s-ext" % "3.6.5",
13-
"de.heikoseeberger" %% "akka-http-json4s" % "1.25.2",
10+
"com.typesafe" % "config" % "1.4.1",
11+
"com.typesafe.akka" %% "akka-actor" % "2.6.12",
12+
"com.typesafe.akka" %% "akka-stream" % "2.6.12",
13+
"com.typesafe.akka" %% "akka-http" % "10.2.3",
14+
"org.json4s" %% "json4s-jackson" % "3.6.7",
15+
"org.json4s" %% "json4s-ext" % "3.6.7",
16+
"de.heikoseeberger" %% "akka-http-json4s" % "1.27.0",
17+
"org.scala-lang.modules" %% "scala-collection-compat" % "2.4.1",
1418
// test dependencies
15-
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
16-
"junit" % "junit" % "4.13.1" % "test"
19+
"org.scalatest" %% "scalatest" % "3.2.3" % "test",
20+
"org.scalatestplus" %% "junit-4-13" % "3.2.3.0" % "test"
1721
)
1822

1923
resolvers ++= Seq(Resolver.mavenLocal)

samples/client/petstore/scala-akka/pom.xml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1616

1717
<java.version>1.8</java.version>
18-
<scala.version>2.12.8</scala.version>
19-
<json4s.jackson.version>3.5.3</json4s.jackson.version>
20-
<json4s.ext.version>3.2.11</json4s.ext.version>
21-
<akka.version>2.5.21</akka.version>
22-
<akka.http.version>10.1.7</akka.http.version>
23-
<typesafeconfig.version>1.3.3</typesafeconfig.version>
24-
<akka.http.json4s.version>1.25.2</akka.http.json4s.version>
25-
<junit.version>4.13</junit.version>
26-
<scala.test.version>3.0.5</scala.test.version>
18+
<scala.version>2.12.13</scala.version>
19+
<json4s.jackson.version>3.6.7</json4s.jackson.version>
20+
<json4s.ext.version>3.6.7</json4s.ext.version>
21+
<akka.version>2.6.12</akka.version>
22+
<akka.http.version>10.2.3</akka.http.version>
23+
<typesafeconfig.version>1.4.1</typesafeconfig.version>
24+
<akka.http.json4s.version>1.27.0</akka.http.json4s.version>
25+
<scala.compat.version>2.4.1</scala.compat.version>
26+
<scala.test.version>3.2.3</scala.test.version>
27+
<scala.test.plus.version>3.2.3.0</scala.test.plus.version>
2728

2829
<scala.maven.plugin.version>3.3.1</scala.maven.plugin.version>
2930
</properties>
@@ -70,6 +71,11 @@
7071
<artifactId>akka-http-json4s_2.12</artifactId>
7172
<version>${akka.http.json4s.version}</version>
7273
</dependency>
74+
<dependency>
75+
<groupId>org.scala-lang.modules</groupId>
76+
<artifactId>scala-collection-compat_2.12</artifactId>
77+
<version>${scala.compat.version}</version>
78+
</dependency>
7379

7480
<!--test dependencies-->
7581
<dependency>
@@ -79,9 +85,9 @@
7985
<scope>test</scope>
8086
</dependency>
8187
<dependency>
82-
<groupId>junit</groupId>
83-
<artifactId>junit</artifactId>
84-
<version>${junit.version}</version>
88+
<groupId>org.scalatestplus</groupId>
89+
<artifactId>junit-4-13_2.12</artifactId>
90+
<version>${scala.test.plus.version}</version>
8591
<scope>test</scope>
8692
</dependency>
8793
</dependencies>

0 commit comments

Comments
 (0)