diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java index 138e9bf9c1d..a5e293c9879 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java @@ -166,8 +166,8 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt")); + supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); supportingFiles.add(new SupportingFile("reference.mustache", resourcesFolder, "reference.conf")); final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator); supportingFiles.add(new SupportingFile("apiRequest.mustache", invokerFolder, "ApiRequest.scala")); @@ -175,6 +175,7 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code supportingFiles.add(new SupportingFile("requests.mustache", invokerFolder, "requests.scala")); supportingFiles.add(new SupportingFile("apiSettings.mustache", invokerFolder, "ApiSettings.scala")); final String apiFolder = (sourceFolder + File.separator + apiPackage).replace(".", File.separator); + supportingFiles.add(new SupportingFile("project/build.properties.mustache", "project", "build.properties")); supportingFiles.add(new SupportingFile("enumsSerializers.mustache", apiFolder, "EnumsSerializers.scala")); supportingFiles.add(new SupportingFile("serializers.mustache", invokerFolder, "Serializers.scala")); } diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache index 8c81b0b2d8b..a82135170c4 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache @@ -18,6 +18,7 @@ import de.heikoseeberger.akkahttpjson4s.Json4sSupport import org.json4s._ import org.json4s.jackson.JsonMethods._ import org.json4s.jackson.Serialization +import scala.collection.compat._ import scala.collection.immutable import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor, Future } @@ -86,7 +87,7 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC private val http = Http() - val CompressionFilter: HttpMessage ⇒ Boolean = (msg: HttpMessage) => + val CompressionFilter: HttpMessage => Boolean = (msg: HttpMessage) => Seq( { _: HttpMessage => settings.compressionEnabled }, Encoder.DefaultFilter, @@ -115,7 +116,7 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC private def headers(headers: Map[String, Any]): immutable.Seq[HttpHeader] = headers.asFormattedParams .map { case (name, value) => RawHeader(name, value.toString) } - .to[immutable.Seq] + .to(immutable.Seq) private def bodyPart(name: String, value: Any): BodyPart = { @@ -147,9 +148,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC case MediaTypes.`multipart/form-data` => Multipart.FormData(Source(params.toList.map { case (name, value) => bodyPart(name, value) })) case MediaTypes.`application/x-www-form-urlencoded` => - FormData(params.mapValues(_.toString)) + FormData(params.view.mapValues(_.toString).toMap) case _: MediaType => // Default : application/x-www-form-urlencoded. - FormData(params.mapValues(_.toString)) + FormData(params.view.mapValues(_.toString).toMap) } ) } @@ -187,7 +188,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC params + (keyName -> key.value) case (params, _) => params }.asFormattedParams + .view .mapValues(_.toString) + .toMap .foldRight[Query](Uri.Query.Empty) { case ((name, value), acc) => acc.+:(name, value) } @@ -196,7 +199,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC def makeUri(r: ApiRequest[_]): Uri = { val opPath = r.operationPath.replaceAll("\\{format\\}", "json") val opPathWithParams = r.pathParams.asFormattedParams + .view .mapValues(_.toString) + .toMap .foldLeft(opPath) { case (path, (name, value)) => path.replaceAll(s"\\{$name\\}", value) } @@ -213,13 +218,13 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC http .singleRequest(request) .map { response => - val decoder: Coder with StreamDecoder = response.encoding match { - case HttpEncodings.gzip ⇒ - Gzip - case HttpEncodings.deflate ⇒ - Deflate - case HttpEncodings.identity ⇒ - NoCoding + val decoder: Decoder with Decoder = response.encoding match { + case HttpEncodings.gzip => + Coders.Gzip + case HttpEncodings.deflate => + Coders.Deflate + case HttpEncodings.identity => + Coders.NoCoding case HttpEncoding(encoding) => throw new IllegalArgumentException(s"Unsupported encoding: $encoding") } @@ -247,13 +252,13 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC request .responseForCode(response.status.intValue) match { case Some((Manifest.Unit, state: ResponseState)) => - Future(responseForState(state, Unit).asInstanceOf[ApiResponse[T]]) + Future(responseForState(state, ()).asInstanceOf[ApiResponse[T]]) case Some((manifest, state: ResponseState)) if manifest == mf => implicit val m: Unmarshaller[HttpEntity, T] = unmarshaller[T](mf, serialization, formats) Unmarshal(response.entity) .to[T] .recoverWith { - case e ⇒ throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) + case e => throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) } .map(value => responseForState(state, value)) case None | Some(_) => diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/apiSettings.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/apiSettings.mustache index d5856ccc17d..22f56080b01 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/apiSettings.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/apiSettings.mustache @@ -3,12 +3,12 @@ package {{invokerPackage}} import java.util.concurrent.TimeUnit -import akka.actor.{ ExtendedActorSystem, Extension, ExtensionKey } +import akka.actor.{ActorSystem, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider} import akka.http.scaladsl.model.StatusCodes.CustomStatusCode import akka.http.scaladsl.model.headers.RawHeader import com.typesafe.config.Config -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.concurrent.duration.FiniteDuration class ApiSettings(config: Config) extends Extension { @@ -32,4 +32,13 @@ class ApiSettings(config: Config) extends Extension { } } -object ApiSettings extends ExtensionKey[ApiSettings] +object ApiSettings extends ExtensionId[ApiSettings] with ExtensionIdProvider { + + override def lookup = ApiSettings + + override def createExtension(system: ExtendedActorSystem): ApiSettings = + new ApiSettings(system) + + // needed to get the type right when used from Java + override def get(system: ActorSystem): ApiSettings = super.get(system) +} diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/build.sbt.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/build.sbt.mustache index c26dae841c7..e4c21c19d0c 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/build.sbt.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/build.sbt.mustache @@ -1,22 +1,26 @@ version := "{{artifactVersion}}" name := "{{artifactId}}" organization := "{{groupId}}" -scalaVersion := "2.12.8" + +scalaVersion := "2.12.13" +crossScalaVersions := Seq(scalaVersion.value, "2.13.4") + libraryDependencies ++= Seq( - "com.typesafe" % "config" % "1.3.3", - "com.typesafe.akka" %% "akka-actor" % "2.5.21", - "com.typesafe.akka" %% "akka-stream" % "2.5.21", - "com.typesafe.akka" %% "akka-http" % "10.1.7", + "com.typesafe" % "config" % "1.4.1", + "com.typesafe.akka" %% "akka-actor" % "2.6.12", + "com.typesafe.akka" %% "akka-stream" % "2.6.12", + "com.typesafe.akka" %% "akka-http" % "10.2.3", {{#joda}} "joda-time" % "joda-time" % "2.10.1", {{/joda}} - "org.json4s" %% "json4s-jackson" % "3.6.5", - "org.json4s" %% "json4s-ext" % "3.6.5", - "de.heikoseeberger" %% "akka-http-json4s" % "1.25.2", + "org.json4s" %% "json4s-jackson" % "3.6.7", + "org.json4s" %% "json4s-ext" % "3.6.7", + "de.heikoseeberger" %% "akka-http-json4s" % "1.27.0", + "org.scala-lang.modules" %% "scala-collection-compat" % "2.4.1", // test dependencies - "org.scalatest" %% "scalatest" % "3.0.5" % "test", - "junit" % "junit" % "4.13.1" % "test" + "org.scalatest" %% "scalatest" % "3.2.3" % "test", + "org.scalatestplus" %% "junit-4-13" % "3.2.3.0" % "test" ) resolvers ++= Seq(Resolver.mavenLocal) diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/pom.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/pom.mustache index 78cbec12128..e82df0c17b9 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/pom.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/pom.mustache @@ -15,18 +15,19 @@ UTF-8 1.8 - 2.12.8 - 3.5.3 - 3.2.11 - 2.5.21 - 10.1.7 + 2.12.13 + 3.6.7 + 3.6.7 + 2.6.12 + 10.2.3 {{#joda}} 2.10.1 {{/joda}} - 1.3.3 - 1.25.2 - 4.13.1 - 3.0.5 + 1.4.1 + 1.27.0 + 2.4.1 + 3.2.3 + 3.2.3.0 3.3.1 @@ -80,6 +81,11 @@ akka-http-json4s_2.12 ${akka.http.json4s.version} + + org.scala-lang.modules + scala-collection-compat_2.12 + ${scala.compat.version} + @@ -89,9 +95,9 @@ test - junit - junit - ${junit.version} + org.scalatestplus + junit-4-13_2.12 + ${scala.test.plus.version} test diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/project/build.properties.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/project/build.properties.mustache new file mode 100644 index 00000000000..dc07aed85e0 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/project/build.properties.mustache @@ -0,0 +1 @@ +sbt.version=1.3.10 \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java index d78b487d286..4304e092bb1 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/scalaakka/ScalaAkkaClientCodegenTest.java @@ -472,7 +472,7 @@ public class ScalaAkkaClientCodegenTest { Generator gen = generator.opts(clientOptInput); List files = gen.generate(); - Assert.assertEquals(files.size(), 15); + Assert.assertEquals(files.size(), 16); TestUtils.ensureContainsFile(files, output, "src/main/scala/hello/world/model/SomeObj.scala"); TestUtils.ensureContainsFile(files, output, "src/main/scala/hello/world/core/ApiSettings.scala"); @@ -509,7 +509,7 @@ public class ScalaAkkaClientCodegenTest { Generator gen = generator.opts(clientOptInput); List files = gen.generate(); - Assert.assertEquals(files.size(), 15); + Assert.assertEquals(files.size(), 16); TestUtils.ensureContainsFile(files, output, "src/main/scala/hello/world/model/package/SomeObj.scala"); TestUtils.ensureContainsFile(files, output, "src/main/scala/hello/world/package/invoker/ApiSettings.scala"); diff --git a/samples/client/petstore/scala-akka/.openapi-generator/FILES b/samples/client/petstore/scala-akka/.openapi-generator/FILES index 8d22043b5a9..2cd9737cf18 100644 --- a/samples/client/petstore/scala-akka/.openapi-generator/FILES +++ b/samples/client/petstore/scala-akka/.openapi-generator/FILES @@ -1,5 +1,6 @@ README.md build.sbt +project/build.properties src/main/resources/reference.conf src/main/scala/org/openapitools/client/api/EnumsSerializers.scala src/main/scala/org/openapitools/client/api/PetApi.scala diff --git a/samples/client/petstore/scala-akka/build.sbt b/samples/client/petstore/scala-akka/build.sbt index 038757790a5..e9915b07f85 100644 --- a/samples/client/petstore/scala-akka/build.sbt +++ b/samples/client/petstore/scala-akka/build.sbt @@ -1,19 +1,23 @@ version := "1.0.0" name := "scala-akka-petstore-client" organization := "org.openapitools" -scalaVersion := "2.12.8" + +scalaVersion := "2.12.13" +crossScalaVersions := Seq(scalaVersion.value, "2.13.4") + libraryDependencies ++= Seq( - "com.typesafe" % "config" % "1.3.3", - "com.typesafe.akka" %% "akka-actor" % "2.5.21", - "com.typesafe.akka" %% "akka-stream" % "2.5.21", - "com.typesafe.akka" %% "akka-http" % "10.1.7", - "org.json4s" %% "json4s-jackson" % "3.6.5", - "org.json4s" %% "json4s-ext" % "3.6.5", - "de.heikoseeberger" %% "akka-http-json4s" % "1.25.2", + "com.typesafe" % "config" % "1.4.1", + "com.typesafe.akka" %% "akka-actor" % "2.6.12", + "com.typesafe.akka" %% "akka-stream" % "2.6.12", + "com.typesafe.akka" %% "akka-http" % "10.2.3", + "org.json4s" %% "json4s-jackson" % "3.6.7", + "org.json4s" %% "json4s-ext" % "3.6.7", + "de.heikoseeberger" %% "akka-http-json4s" % "1.27.0", + "org.scala-lang.modules" %% "scala-collection-compat" % "2.4.1", // test dependencies - "org.scalatest" %% "scalatest" % "3.0.5" % "test", - "junit" % "junit" % "4.13.1" % "test" + "org.scalatest" %% "scalatest" % "3.2.3" % "test", + "org.scalatestplus" %% "junit-4-13" % "3.2.3.0" % "test" ) resolvers ++= Seq(Resolver.mavenLocal) diff --git a/samples/client/petstore/scala-akka/pom.xml b/samples/client/petstore/scala-akka/pom.xml index 42e08693b64..0f93bcb372b 100644 --- a/samples/client/petstore/scala-akka/pom.xml +++ b/samples/client/petstore/scala-akka/pom.xml @@ -15,15 +15,16 @@ UTF-8 1.8 - 2.12.8 - 3.5.3 - 3.2.11 - 2.5.21 - 10.1.7 - 1.3.3 - 1.25.2 - 4.13 - 3.0.5 + 2.12.13 + 3.6.7 + 3.6.7 + 2.6.12 + 10.2.3 + 1.4.1 + 1.27.0 + 2.4.1 + 3.2.3 + 3.2.3.0 3.3.1 @@ -70,6 +71,11 @@ akka-http-json4s_2.12 ${akka.http.json4s.version} + + org.scala-lang.modules + scala-collection-compat_2.12 + ${scala.compat.version} + @@ -79,9 +85,9 @@ test - junit - junit - ${junit.version} + org.scalatestplus + junit-4-13_2.12 + ${scala.test.plus.version} test diff --git a/samples/client/petstore/scala-akka/project/build.properties b/samples/client/petstore/scala-akka/project/build.properties new file mode 100644 index 00000000000..dc07aed85e0 --- /dev/null +++ b/samples/client/petstore/scala-akka/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.3.10 \ No newline at end of file diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala index d3ff4cadb8e..fe391096713 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala @@ -28,6 +28,7 @@ import de.heikoseeberger.akkahttpjson4s.Json4sSupport import org.json4s._ import org.json4s.jackson.JsonMethods._ import org.json4s.jackson.Serialization +import scala.collection.compat._ import scala.collection.immutable import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor, Future } @@ -96,7 +97,7 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC private val http = Http() - val CompressionFilter: HttpMessage ⇒ Boolean = (msg: HttpMessage) => + val CompressionFilter: HttpMessage => Boolean = (msg: HttpMessage) => Seq( { _: HttpMessage => settings.compressionEnabled }, Encoder.DefaultFilter, @@ -125,7 +126,7 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC private def headers(headers: Map[String, Any]): immutable.Seq[HttpHeader] = headers.asFormattedParams .map { case (name, value) => RawHeader(name, value.toString) } - .to[immutable.Seq] + .to(immutable.Seq) private def bodyPart(name: String, value: Any): BodyPart = { @@ -157,9 +158,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC case MediaTypes.`multipart/form-data` => Multipart.FormData(Source(params.toList.map { case (name, value) => bodyPart(name, value) })) case MediaTypes.`application/x-www-form-urlencoded` => - FormData(params.mapValues(_.toString)) + FormData(params.view.mapValues(_.toString).toMap) case _: MediaType => // Default : application/x-www-form-urlencoded. - FormData(params.mapValues(_.toString)) + FormData(params.view.mapValues(_.toString).toMap) } ) } @@ -197,7 +198,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC params + (keyName -> key.value) case (params, _) => params }.asFormattedParams + .view .mapValues(_.toString) + .toMap .foldRight[Query](Uri.Query.Empty) { case ((name, value), acc) => acc.+:(name, value) } @@ -206,7 +209,9 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC def makeUri(r: ApiRequest[_]): Uri = { val opPath = r.operationPath.replaceAll("\\{format\\}", "json") val opPathWithParams = r.pathParams.asFormattedParams + .view .mapValues(_.toString) + .toMap .foldLeft(opPath) { case (path, (name, value)) => path.replaceAll(s"\\{$name\\}", value) } @@ -223,13 +228,13 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC http .singleRequest(request) .map { response => - val decoder: Coder with StreamDecoder = response.encoding match { - case HttpEncodings.gzip ⇒ - Gzip - case HttpEncodings.deflate ⇒ - Deflate - case HttpEncodings.identity ⇒ - NoCoding + val decoder: Decoder with Decoder = response.encoding match { + case HttpEncodings.gzip => + Coders.Gzip + case HttpEncodings.deflate => + Coders.Deflate + case HttpEncodings.identity => + Coders.NoCoding case HttpEncoding(encoding) => throw new IllegalArgumentException(s"Unsupported encoding: $encoding") } @@ -257,13 +262,13 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC request .responseForCode(response.status.intValue) match { case Some((Manifest.Unit, state: ResponseState)) => - Future(responseForState(state, Unit).asInstanceOf[ApiResponse[T]]) + Future(responseForState(state, ()).asInstanceOf[ApiResponse[T]]) case Some((manifest, state: ResponseState)) if manifest == mf => implicit val m: Unmarshaller[HttpEntity, T] = unmarshaller[T](mf, serialization, formats) Unmarshal(response.entity) .to[T] .recoverWith { - case e ⇒ throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) + case e => throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) } .map(value => responseForState(state, value)) case None | Some(_) => diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiSettings.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiSettings.scala index 2553aeb3c87..2c02c47c7ba 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiSettings.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiSettings.scala @@ -13,12 +13,12 @@ package org.openapitools.client.core import java.util.concurrent.TimeUnit -import akka.actor.{ ExtendedActorSystem, Extension, ExtensionKey } +import akka.actor.{ActorSystem, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider} import akka.http.scaladsl.model.StatusCodes.CustomStatusCode import akka.http.scaladsl.model.headers.RawHeader import com.typesafe.config.Config -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.concurrent.duration.FiniteDuration class ApiSettings(config: Config) extends Extension { @@ -42,4 +42,13 @@ class ApiSettings(config: Config) extends Extension { } } -object ApiSettings extends ExtensionKey[ApiSettings] +object ApiSettings extends ExtensionId[ApiSettings] with ExtensionIdProvider { + + override def lookup = ApiSettings + + override def createExtension(system: ExtendedActorSystem): ApiSettings = + new ApiSettings(system) + + // needed to get the type right when used from Java + override def get(system: ActorSystem): ApiSettings = super.get(system) +} diff --git a/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala b/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala index e6229fb05f3..48c8d4c644f 100644 --- a/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala +++ b/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala @@ -5,18 +5,19 @@ import org.openapitools.client.api._ import org.openapitools.client.core.{ApiInvoker, ApiKeyValue} import org.openapitools.client.model._ import org.scalatest.Inspectors._ -import org.scalatest._ -import org.scalatest.junit.JUnitRunner +import org.scalatest.flatspec.AsyncFlatSpec +import org.scalatest.matchers.should.Matchers +import org.scalatestplus.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) class PetApiTest extends AsyncFlatSpec with Matchers { - private implicit val system: ActorSystem = ActorSystem() + implicit private val system: ActorSystem = ActorSystem() behavior of "PetApi" - val api: PetApi = PetApi() - val invoker: ApiInvoker = ApiInvoker(EnumsSerializers.all) - private implicit val apiKey: ApiKeyValue = ApiKeyValue("special-key") + val api: PetApi = PetApi() + val invoker: ApiInvoker = ApiInvoker(EnumsSerializers.all) + implicit private val apiKey: ApiKeyValue = ApiKeyValue("special-key") it should "add and fetch a pet" in { val petId = 1000 @@ -34,7 +35,7 @@ class PetApiTest extends AsyncFlatSpec with Matchers { for { addResponse <- invoker.execute(addPetRequest) - response <- invoker.execute(getPetRequest) + response <- invoker.execute(getPetRequest) } yield { addResponse.code should be(200) @@ -54,7 +55,7 @@ class PetApiTest extends AsyncFlatSpec with Matchers { } it should "update a pet" in { - val petId = (Math.random()*1000000000).toLong + val petId = (Math.random() * 1000000000).toLong val createdPet = Pet( Some(petId), Some(Category(Some(1), Some("sold"))), @@ -64,12 +65,12 @@ class PetApiTest extends AsyncFlatSpec with Matchers { Some(PetEnums.Status.Available) ) - for { - createdPet <- invoker.execute(api.addPet(createdPet)) + for { + createdPet <- invoker.execute(api.addPet(createdPet)) pet: core.ApiResponse[Pet] <- invoker.execute(api.getPetById(createdPet.content.id.get)) updatedPet = pet.content.copy(status = Some(PetEnums.Status.Sold), name = "developer") updatedPetResponse: core.ApiResponse[Pet] <- invoker.execute(api.updatePet(updatedPet)) - updatedRequested: core.ApiResponse[Pet] <- invoker.execute(api.getPetById(createdPet.content.id.get)) + updatedRequested: core.ApiResponse[Pet] <- invoker.execute(api.getPetById(createdPet.content.id.get)) } yield { pet.content.name should be("programmer") pet.content.status should be(Some(PetEnums.Status.Available)) @@ -120,4 +121,3 @@ class PetApiTest extends AsyncFlatSpec with Matchers { } */ } -