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

Various updates in Akka Scala generator #2472

Merged
merged 3 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -11,6 +11,11 @@ import {{mainPackage}}.core.ApiKeyLocations._
{{#operations}}
object {{classname}} {

def apply(baseUrl: String = "{{{basePath}}}") = new {{classname}}(baseUrl)
}

class {{classname}}(baseUrl: String) {

{{#operation}}
{{#javadocRenderer}}
{{>javadoc}}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@ package {{{mainPackage}}}.core

import java.util.concurrent.TimeUnit

import akka.actor.{ExtendedActorSystem, Extension, ExtensionKey}
import akka.actor.{ ExtendedActorSystem, Extension, ExtensionKey }
import akka.http.scaladsl.model.StatusCodes.CustomStatusCode
import akka.http.scaladsl.model.headers.RawHeader
import com.typesafe.config.Config
import {{mainPackage}}.core.ApiInvoker.CustomStatusCode
import spray.http.HttpHeaders.RawHeader

import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.concurrent.duration.FiniteDuration

class ApiSettings(config: Config) extends Extension {
def this(system: ExtendedActorSystem) = this(system.settings.config)

private def cfg = config.getConfig("{{mainPackage}}.apiRequest")
private def cfg = config.getConfig("{{{mainPackage}}}.apiRequest")

val alwaysTrustCertificates: Boolean = cfg.getBoolean("trust-certificates")
val defaultHeaders: List[RawHeader] = cfg.getConfig("default-headers").entrySet.toList.map(c => RawHeader(c.getKey, c.getValue.render))
val defaultHeaders: List[RawHeader] = cfg.getConfig("default-headers").entrySet.asScala.toList.map(c => RawHeader(c.getKey, c.getValue.render))
val connectionTimeout = FiniteDuration(cfg.getDuration("connection-timeout", TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)
val compressionEnabled: Boolean = cfg.getBoolean("compression.enabled")
val compressionSizeThreshold: Int = cfg.getBytes("compression.size-threshold").toInt
val customCodes: List[CustomStatusCode] = cfg.getConfigList("custom-codes").toList.map { c =>
val customCodes: List[CustomStatusCode] = cfg.getConfigList("custom-codes").asScala.toList.map { c =>
CustomStatusCode(
c.getInt("code"),
c.getInt("code"))(
c.getString("reason"),
c.getBoolean("success"))
if (c.hasPath("defaultMessage")) c.getString("defaultMessage") else c.getString("reason"),
c.getBoolean("success"),
if (c.hasPath("allowsEntity")) c.getBoolean("allowsEntity") else true
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
version := "{{artifactVersion}}"
name := "{{artifactId}}"
organization := "{{groupId}}"
scalaVersion := "2.11.12"
scalaVersion := "2.12.8"

libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.3.2",
"com.typesafe.akka" %% "akka-actor" % "2.5.17",
"io.spray" % "spray-client" % "1.3.1",
"joda-time" % "joda-time" % "2.9.9",
"org.json4s" %% "json4s-jackson" % "3.5.4",
"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",
"joda-time" % "joda-time" % "2.10.1",
"org.json4s" %% "json4s-jackson" % "3.6.5",
"org.json4s" %% "json4s-ext" % "3.6.5",
"de.heikoseeberger" %% "akka-http-json4s" % "1.25.2",
// test dependencies
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"junit" % "junit" % "4.12" % "test"
Expand All @@ -22,4 +25,4 @@ scalacOptions := Seq(
"-feature"
)

publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageDoc) := false
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>
<scala.version>2.11.12</scala.version>
<json4s.jackson.version>3.5.4</json4s.jackson.version>
<scala.version>2.12.8</scala.version>
<json4s.jackson.version>3.5.3</json4s.jackson.version>
<json4s.ext.version>3.2.11</json4s.ext.version>
<spray.version>1.3.1</spray.version>
<akka.version>2.5.17</akka.version>
<joda.time.version>2.9.9</joda.time.version>

<akka.version>2.5.21</akka.version>
<akka.http.version>10.1.7</akka.http.version>
<joda.time.version>2.10.1</joda.time.version>
<typesafeconfig.version>1.3.3</typesafeconfig.version>
<akka.http.json4s.version>1.25.2</akka.http.json4s.version>
<junit.version>4.12</junit.version>
<scala.test.version>3.0.5</scala.test.version>

Expand All @@ -43,28 +44,43 @@
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.2</version>
<version>${typesafeconfig.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<artifactId>akka-stream_2.12</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-client</artifactId>
<version>${spray.version}</version>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http_2.12</artifactId>
<version>${akka.http.version}</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.12</artifactId>
<version>${json4s.jackson.version}</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.11</artifactId>
<artifactId>json4s-ext_2.12</artifactId>
<version>${json4s.jackson.version}</version>
</dependency>
<dependency>
<groupId>de.heikoseeberger</groupId>
<artifactId>akka-http-json4s_2.12</artifactId>
<version>${akka.http.json4s.version}</version>
</dependency>

<!--test dependencies-->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.11</artifactId>
<artifactId>scalatest_2.12</artifactId>
<version>${scala.test.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -240,4 +256,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.2-SNAPSHOT
4.0.0-SNAPSHOT
17 changes: 10 additions & 7 deletions samples/client/petstore/scala-akka/build.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
version := "1.0.0"
name := "scala-akka-petstore-client"
organization := "org.openapitools"
scalaVersion := "2.11.12"
scalaVersion := "2.12.8"

libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.3.2",
"com.typesafe.akka" %% "akka-actor" % "2.5.17",
"io.spray" % "spray-client" % "1.3.1",
"joda-time" % "joda-time" % "2.9.9",
"org.json4s" %% "json4s-jackson" % "3.5.4",
"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",
"joda-time" % "joda-time" % "2.10.1",
"org.json4s" %% "json4s-jackson" % "3.6.5",
"org.json4s" %% "json4s-ext" % "3.6.5",
"de.heikoseeberger" %% "akka-http-json4s" % "1.25.2",
// test dependencies
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"junit" % "junit" % "4.12" % "test"
Expand All @@ -22,4 +25,4 @@ scalacOptions := Seq(
"-feature"
)

publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageDoc) := false
44 changes: 30 additions & 14 deletions samples/client/petstore/scala-akka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>
<scala.version>2.11.12</scala.version>
<json4s.jackson.version>3.5.4</json4s.jackson.version>
<scala.version>2.12.8</scala.version>
<json4s.jackson.version>3.5.3</json4s.jackson.version>
<json4s.ext.version>3.2.11</json4s.ext.version>
<spray.version>1.3.1</spray.version>
<akka.version>2.5.17</akka.version>
<joda.time.version>2.9.9</joda.time.version>

<akka.version>2.5.21</akka.version>
<akka.http.version>10.1.7</akka.http.version>
<joda.time.version>2.10.1</joda.time.version>
<typesafeconfig.version>1.3.3</typesafeconfig.version>
<akka.http.json4s.version>1.25.2</akka.http.json4s.version>
<junit.version>4.12</junit.version>
<scala.test.version>3.0.5</scala.test.version>

Expand All @@ -43,28 +44,43 @@
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.2</version>
<version>${typesafeconfig.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<artifactId>akka-stream_2.12</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-client</artifactId>
<version>${spray.version}</version>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http_2.12</artifactId>
<version>${akka.http.version}</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.12</artifactId>
<version>${json4s.jackson.version}</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.11</artifactId>
<artifactId>json4s-ext_2.12</artifactId>
<version>${json4s.jackson.version}</version>
</dependency>
<dependency>
<groupId>de.heikoseeberger</groupId>
<artifactId>akka-http-json4s_2.12</artifactId>
<version>${akka.http.json4s.version}</version>
</dependency>

<!--test dependencies-->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.11</artifactId>
<artifactId>scalatest_2.12</artifactId>
<version>${scala.test.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -240,4 +256,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.2.8
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ import org.openapitools.client.core.ApiKeyLocations._

object PetApi {

def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new PetApi(baseUrl)
}

class PetApi(baseUrl: String) {

/**
* Expected answers:
* code 405 : (Invalid input)
*
* @param pet Pet object that needs to be added to the store
* @param body Pet object that needs to be added to the store
*/
def addPet(pet: Pet): ApiRequest[Unit] =
def addPet(body: Pet): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/pet", "application/json")
.withBody(pet)
.withBody(body)
.withErrorResponse[Unit](405)
/**
* Expected answers:
Expand Down Expand Up @@ -96,11 +101,11 @@ object PetApi {
* code 404 : (Pet not found)
* code 405 : (Validation exception)
*
* @param pet Pet object that needs to be added to the store
* @param body Pet object that needs to be added to the store
*/
def updatePet(pet: Pet): ApiRequest[Unit] =
def updatePet(body: Pet): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.PUT, "http://petstore.swagger.io/v2", "/pet", "application/json")
.withBody(pet)
.withBody(body)
.withErrorResponse[Unit](400)
.withErrorResponse[Unit](404)
.withErrorResponse[Unit](405)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import org.openapitools.client.core.ApiKeyLocations._

object StoreApi {

def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new StoreApi(baseUrl)
}

class StoreApi(baseUrl: String) {

/**
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
*
Expand Down Expand Up @@ -66,11 +71,11 @@ object StoreApi {
* code 200 : Order (successful operation)
* code 400 : (Invalid Order)
*
* @param order order placed for purchasing the pet
* @param body order placed for purchasing the pet
*/
def placeOrder(order: Order): ApiRequest[Unit] =
def placeOrder(body: Order): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/store/order", "application/json")
.withBody(order)
.withBody(body)
.withSuccessResponse[Order](200)
.withErrorResponse[Unit](400)

Expand Down
Loading