mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 18:45:23 +00:00
* [akka-scala] template upgrade dependency version and refactor #7171 * update sbt dependencies version and add enforce plugin * delete new to the case class
This commit is contained in:
parent
4b4528317c
commit
be50955bbf
@ -49,8 +49,8 @@ object ApiInvoker {
|
||||
|
||||
def addCustomStatusCode(code: CustomStatusCode): Unit = addCustomStatusCode(code.value, code.reason, code.isSuccess)
|
||||
|
||||
def addCustomStatusCode(code: Int, reason: String = "Application defined code", isSuccess: Boolean = true) = {
|
||||
StatusCodes.getForKey(code) foreach { c =>
|
||||
def addCustomStatusCode(code: Int, reason: String = "Application defined code", isSuccess: Boolean = true): Unit = {
|
||||
StatusCodes.getForKey(code) foreach { _ =>
|
||||
StatusCodes.registerCustom(code, reason, reason, isSuccess, allowsEntity = true)
|
||||
}
|
||||
}
|
||||
@ -97,16 +97,15 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
||||
import io.swagger.client.core.ApiInvoker._
|
||||
import io.swagger.client.core.ParametersMap._
|
||||
|
||||
implicit val ec = system.dispatcher
|
||||
implicit val jsonFormats = formats
|
||||
implicit val ec: ExecutionContextExecutor = system.dispatcher
|
||||
implicit val jsonFormats: Formats = formats
|
||||
|
||||
def settings = ApiSettings(system)
|
||||
|
||||
import spray.http.MessagePredicate._
|
||||
|
||||
val CompressionFilter = MessagePredicate({ _ => settings.compressionEnabled}) &&
|
||||
Encoder.DefaultFilter &&
|
||||
minEntitySize(settings.compressionSizeThreshold)
|
||||
val CompressionFilter: MessagePredicate= MessagePredicate({ _ => settings.compressionEnabled}) &&
|
||||
Encoder.DefaultFilter && minEntitySize(settings.compressionSizeThreshold)
|
||||
|
||||
settings.customCodes.foreach(addCustomStatusCode)
|
||||
|
||||
@ -248,22 +247,22 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends Untrust
|
||||
case ResponseState.Success =>
|
||||
ApiResponse(response.status.intValue, value, response.headers.map(header => (header.name, header.value)).toMap)
|
||||
case ResponseState.Error =>
|
||||
throw new ApiError(response.status.intValue, "Error response received",
|
||||
throw ApiError(response.status.intValue, "Error response received",
|
||||
Some(value),
|
||||
headers = response.headers.map(header => (header.name, header.value)).toMap)
|
||||
}
|
||||
|
||||
case Left(MalformedContent(error, Some(cause))) ⇒
|
||||
throw new ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), cause)
|
||||
throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), cause)
|
||||
|
||||
case Left(MalformedContent(error, None)) ⇒
|
||||
throw new ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString))
|
||||
throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString))
|
||||
|
||||
case Left(ContentExpected) ⇒
|
||||
throw new ApiError(response.status.intValue, s"Unable to unmarshall empty response to [$manifest]", Some(response.entity.toString))
|
||||
throw ApiError(response.status.intValue, s"Unable to unmarshall empty response to [$manifest]", Some(response.entity.toString))
|
||||
}
|
||||
|
||||
case _ => throw new ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString))
|
||||
case _ => throw ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,50 +6,54 @@
|
||||
package {{invokerPackage}}
|
||||
|
||||
sealed trait ResponseState
|
||||
|
||||
object ResponseState {
|
||||
|
||||
case object Success extends ResponseState
|
||||
|
||||
case object Error extends ResponseState
|
||||
|
||||
}
|
||||
|
||||
case class ApiRequest[U](
|
||||
// required fields
|
||||
method: ApiMethod,
|
||||
basePath: String,
|
||||
operationPath: String,
|
||||
contentType: String,
|
||||
// required fields
|
||||
method: ApiMethod,
|
||||
basePath: String,
|
||||
operationPath: String,
|
||||
contentType: String,
|
||||
|
||||
// optional fields
|
||||
responses: Map[Int, (Manifest[_], ResponseState)] = Map.empty,
|
||||
bodyParam: Option[Any] = None,
|
||||
formParams: Map[String, Any] = Map.empty,
|
||||
pathParams: Map[String, Any] = Map.empty,
|
||||
queryParams: Map[String, Any] = Map.empty,
|
||||
headerParams: Map[String, Any] = Map.empty,
|
||||
credentials: Seq[Credentials] = List.empty) {
|
||||
// optional fields
|
||||
responses: Map[Int, (Manifest[_], ResponseState)] = Map.empty,
|
||||
bodyParam: Option[Any] = None,
|
||||
formParams: Map[String, Any] = Map.empty,
|
||||
pathParams: Map[String, Any] = Map.empty,
|
||||
queryParams: Map[String, Any] = Map.empty,
|
||||
headerParams: Map[String, Any] = Map.empty,
|
||||
credentials: Seq[Credentials] = List.empty) {
|
||||
|
||||
def withCredentials(cred: Credentials) = copy[U](credentials = credentials :+ cred)
|
||||
def withCredentials(cred: Credentials): ApiRequest[U] = copy[U](credentials = credentials :+ cred)
|
||||
|
||||
def withApiKey(key: ApiKeyValue, keyName: String, location: ApiKeyLocation) = withCredentials(ApiKeyCredentials(key, keyName, location))
|
||||
def withApiKey(key: ApiKeyValue, keyName: String, location: ApiKeyLocation): ApiRequest[U] = withCredentials(ApiKeyCredentials(key, keyName, location))
|
||||
|
||||
def withSuccessResponse[T](code: Int)(implicit m: Manifest[T]) = copy[U](responses = responses + (code -> (m, ResponseState.Success)))
|
||||
def withSuccessResponse[T](code: Int)(implicit m: Manifest[T]): ApiRequest[U] = copy[U](responses = responses + (code -> (m, ResponseState.Success)))
|
||||
|
||||
def withErrorResponse[T](code: Int)(implicit m: Manifest[T]) = copy[U](responses = responses + (code -> (m, ResponseState.Error)))
|
||||
def withErrorResponse[T](code: Int)(implicit m: Manifest[T]): ApiRequest[U] = copy[U](responses = responses + (code -> (m, ResponseState.Error)))
|
||||
|
||||
def withDefaultSuccessResponse[T](implicit m: Manifest[T]) = withSuccessResponse[T](0)
|
||||
def withDefaultSuccessResponse[T](implicit m: Manifest[T]): ApiRequest[U] = withSuccessResponse[T](0)
|
||||
|
||||
def withDefaultErrorResponse[T](implicit m: Manifest[T]) = withErrorResponse[T](0)
|
||||
def withDefaultErrorResponse[T](implicit m: Manifest[T]): ApiRequest[U] = withErrorResponse[T](0)
|
||||
|
||||
def responseForCode(statusCode: Int): Option[(Manifest[_], ResponseState)] = responses.get(statusCode) orElse responses.get(0)
|
||||
|
||||
def withoutBody() = copy[U](bodyParam = None)
|
||||
def withoutBody(): ApiRequest[U] = copy[U](bodyParam = None)
|
||||
|
||||
def withBody(body: Any) = copy[U](bodyParam = Some(body))
|
||||
def withBody(body: Any): ApiRequest[U] = copy[U](bodyParam = Some(body))
|
||||
|
||||
def withFormParam(name: String, value: Any) = copy[U](formParams = formParams + (name -> value))
|
||||
def withFormParam(name: String, value: Any): ApiRequest[U] = copy[U](formParams = formParams + (name -> value))
|
||||
|
||||
def withPathParam(name: String, value: Any) = copy[U](pathParams = pathParams + (name -> value))
|
||||
def withPathParam(name: String, value: Any): ApiRequest[U] = copy[U](pathParams = pathParams + (name -> value))
|
||||
|
||||
def withQueryParam(name: String, value: Any) = copy[U](queryParams = queryParams + (name -> value))
|
||||
def withQueryParam(name: String, value: Any): ApiRequest[U] = copy[U](queryParams = queryParams + (name -> value))
|
||||
|
||||
def withHeaderParam(name: String, value: Any) = copy[U](headerParams = headerParams + (name -> value))
|
||||
def withHeaderParam(name: String, value: Any): ApiRequest[U] = copy[U](headerParams = headerParams + (name -> value))
|
||||
}
|
||||
|
@ -20,18 +20,17 @@ class ApiSettings(config: Config) extends Extension {
|
||||
|
||||
private def cfg = config.getConfig("io.swagger.client.apiRequest")
|
||||
|
||||
val alwaysTrustCertificates = cfg.getBoolean("trust-certificates")
|
||||
val defaultHeaders = cfg.getConfig("default-headers").entrySet.toList.map(c => RawHeader(c.getKey, c.getValue.render))
|
||||
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 connectionTimeout = FiniteDuration(cfg.getDuration("connection-timeout", TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)
|
||||
val compressionEnabled = cfg.getBoolean("compression.enabled")
|
||||
val compressionSizeThreshold = cfg.getBytes("compression.size-threshold").toInt
|
||||
val customCodes = cfg.getConfigList("custom-codes").toList.map { c => CustomStatusCode(
|
||||
c.getInt("code"),
|
||||
c.getString("reason"),
|
||||
c.getBoolean("success"))
|
||||
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 =>
|
||||
CustomStatusCode(
|
||||
c.getInt("code"),
|
||||
c.getString("reason"),
|
||||
c.getBoolean("success"))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
object ApiSettings extends ExtensionKey[ApiSettings]
|
||||
|
@ -1,26 +1,21 @@
|
||||
version := "{{artifactVersion}}"
|
||||
|
||||
name := "{{artifactId}}"
|
||||
|
||||
organization := "{{groupId}}"
|
||||
|
||||
scalaVersion := "2.11.8"
|
||||
version := "{{artifactVersion}}"
|
||||
name := "{{artifactId}}"
|
||||
organization := "{{groupId}}"
|
||||
scalaVersion := "2.11.12"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"io.swagger" % "swagger-core" % "1.5.15",
|
||||
"com.typesafe" % "config" % "1.2.1",
|
||||
"com.typesafe.akka" % "akka-actor_2.10" % "2.3.9",
|
||||
"com.typesafe" % "config" % "1.3.2",
|
||||
"com.typesafe.akka" %% "akka-actor" % "2.5.8",
|
||||
"io.spray" % "spray-client" % "1.3.1",
|
||||
"joda-time" % "joda-time" % "2.2",
|
||||
"org.joda" % "joda-convert" % "1.2",
|
||||
"org.json4s" % "json4s-jackson_2.10" % "3.2.11",
|
||||
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
|
||||
"junit" % "junit" % "4.8.1" % "test"
|
||||
"joda-time" % "joda-time" % "2.9.9",
|
||||
"org.joda" % "joda-convert" % "1.9.2",
|
||||
"org.json4s" %% "json4s-jackson" % "3.5.3",
|
||||
"org.scalatest" %% "scalatest" % "3.0.4" % "test",
|
||||
"junit" % "junit" % "4.12" % "test"
|
||||
)
|
||||
|
||||
resolvers ++= Seq(
|
||||
Resolver.mavenLocal
|
||||
)
|
||||
resolvers ++= Seq(Resolver.mavenLocal)
|
||||
|
||||
scalacOptions := Seq(
|
||||
"-unchecked",
|
||||
@ -29,4 +24,3 @@ scalacOptions := Seq(
|
||||
)
|
||||
|
||||
publishArtifact in (Compile, packageDoc) := false
|
||||
|
||||
|
@ -11,27 +11,24 @@ import scala.reflect.ClassTag
|
||||
|
||||
object EnumsSerializers {
|
||||
|
||||
def all = Seq[Serializer[_]](){{#models}}{{#model}}{{#hasEnums}}{{#vars}}{{#isEnum}} :+
|
||||
def all: Seq[Serializer[_]] = Seq[Serializer[_]](){{#models}}{{#model}}{{#hasEnums}}{{#vars}}{{#isEnum}} :+
|
||||
new EnumNameSerializer({{classname}}Enums.{{datatypeWithEnum}}){{/isEnum}}{{/vars}}{{/hasEnums}}{{/model}}{{/models}}
|
||||
|
||||
|
||||
|
||||
private class EnumNameSerializer[E <: Enumeration: ClassTag](enum: E)
|
||||
extends Serializer[E#Value] {
|
||||
import JsonDSL._
|
||||
|
||||
val EnumerationClass = classOf[E#Value]
|
||||
val EnumerationClass: Class[E#Value] = classOf[E#Value]
|
||||
|
||||
def deserialize(implicit format: Formats):
|
||||
PartialFunction[(TypeInfo, JValue), E#Value] = {
|
||||
case (t @ TypeInfo(EnumerationClass, _), json) if isValid(json) => {
|
||||
case (t @ TypeInfo(EnumerationClass, _), json) if isValid(json) =>
|
||||
json match {
|
||||
case JString(value) =>
|
||||
enum.withName(value)
|
||||
case value =>
|
||||
throw new MappingException(s"Can't convert $value to $EnumerationClass")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private[this] def isValid(json: JValue) = json match {
|
||||
|
@ -1,246 +1,258 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>maven-mongodb-plugin-repo</id>
|
||||
<name>maven mongodb plugin repository</name>
|
||||
<url>http://maven-mongodb-plugin.googlecode.com/svn/maven/repo</url>
|
||||
<layout>default</layout>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<name>{{artifactId}}</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-maven</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>2.2.0</version>
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<version>{{artifactVersion}}</version>
|
||||
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/test/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>
|
||||
1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>scala-compile-first</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>scala-test-compile</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<args>
|
||||
<arg>-feature</arg>
|
||||
</args>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xms128m</jvmArg>
|
||||
<jvmArg>-Xmx1500m</jvmArg>
|
||||
</jvmArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.scala-tools</groupId>
|
||||
<artifactId>maven-scala-plugin</artifactId>
|
||||
<configuration>
|
||||
<scalaVersion>${scala-version}</scalaVersion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>${scala-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-core</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.10</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${joda-time-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.joda</groupId>
|
||||
<artifactId>joda-convert</artifactId>
|
||||
<version>${joda-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.typesafe</groupId>
|
||||
<artifactId>config</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.typesafe.akka</groupId>
|
||||
<artifactId>akka-actor_2.10</artifactId>
|
||||
<version>${akka-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spray</groupId>
|
||||
<artifactId>spray-client</artifactId>
|
||||
<version>${spray-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json4s</groupId>
|
||||
<artifactId>json4s-jackson_2.10</artifactId>
|
||||
<version>${json4s-jackson-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<scala-version>2.10.4</scala-version>
|
||||
<json4s-jackson-version>3.2.11</json4s-jackson-version>
|
||||
<json4s-ext-version>3.2.11</json4s-ext-version>
|
||||
<spray-version>1.3.1</spray-version>
|
||||
<akka-version>2.3.9</akka-version>
|
||||
<joda-version>1.2</joda-version>
|
||||
<joda-time-version>2.2</joda-time-version>
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<maven-plugin.version>1.0.0</maven-plugin.version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<jdk.version>1.8</jdk.version>
|
||||
<scala-version>2.11.12</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.8</akka-version>
|
||||
<joda-convert-version>1.9.2</joda-convert-version>
|
||||
<joda-time-version>2.9.9</joda-time-version>
|
||||
<swagger-core-version>1.5.15</swagger-core-version>
|
||||
<maven-plugin.version>1.0.0</maven-plugin.version>
|
||||
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
|
||||
<scala-test-version>2.2.0</scala-test-version>
|
||||
</properties>
|
||||
<junit-version>4.12</junit-version>
|
||||
<scala-test-version>3.0.4</scala-test-version>
|
||||
|
||||
<scala-maven-plugin-version>3.3.1</scala-maven-plugin-version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>${scala-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-core</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${joda-time-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.joda</groupId>
|
||||
<artifactId>joda-convert</artifactId>
|
||||
<version>${joda-convert-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.typesafe</groupId>
|
||||
<artifactId>config</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.typesafe.akka</groupId>
|
||||
<artifactId>akka-actor_2.11</artifactId>
|
||||
<version>${akka-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spray</groupId>
|
||||
<artifactId>spray-client</artifactId>
|
||||
<version>${spray-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json4s</groupId>
|
||||
<artifactId>json4s-jackson_2.11</artifactId>
|
||||
<version>${json4s-jackson-version}</version>
|
||||
</dependency>
|
||||
<!--test dependencies-->
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.11</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>maven-mongodb-plugin-repo</id>
|
||||
<name>maven mongodb plugin repository</name>
|
||||
<url>http://maven-mongodb-plugin.googlecode.com/svn/maven/repo</url>
|
||||
<layout>default</layout>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-maven</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>2.2.0</version>
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.20.1</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/main/java
|
||||
</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/test/java
|
||||
</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>scala-compile-first</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>scala-test-compile</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<args>
|
||||
<arg>-feature</arg>
|
||||
</args>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xms128m</jvmArg>
|
||||
<jvmArg>-Xmx1500m</jvmArg>
|
||||
</jvmArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.scala-tools</groupId>
|
||||
<artifactId>maven-scala-plugin</artifactId>
|
||||
<configuration>
|
||||
<scalaVersion>${scala-version}</scalaVersion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
||||
|
@ -7,20 +7,34 @@ package {{invokerPackage}}
|
||||
|
||||
import java.io.File
|
||||
import java.net.URLEncoder
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
sealed trait ApiReturnWithHeaders {
|
||||
def headers: Map[String, String]
|
||||
|
||||
def header(name: String): Option[String] = headers.get(name)
|
||||
def getStringHeader(name: String) = header(name)
|
||||
|
||||
def getStringHeader(name: String): Option[String] = header(name)
|
||||
|
||||
// workaround: return date time header in string instead of datetime object
|
||||
def getDateTimeHeader(name: String) = header(name)
|
||||
def getIntHeader(name: String) = castedHeader(name, java.lang.Integer.parseInt)
|
||||
def getLongHeader(name: String) = castedHeader(name, java.lang.Long.parseLong)
|
||||
def getFloatHeader(name: String) = castedHeader(name, java.lang.Float.parseFloat)
|
||||
def getDoubleHeader(name: String) = castedHeader(name, java.lang.Double.parseDouble)
|
||||
def getBooleanHeader(name: String) = castedHeader(name, java.lang.Boolean.parseBoolean)
|
||||
private def castedHeader[U](name: String, conversion: String => U): Option[U] = { Try { header(name).map( conversion ) }.get }
|
||||
def getDateTimeHeader(name: String): Option[String] = header(name)
|
||||
|
||||
def getIntHeader(name: String): Option[Int] = castedHeader(name, java.lang.Integer.parseInt)
|
||||
|
||||
def getLongHeader(name: String): Option[Long] = castedHeader(name, java.lang.Long.parseLong)
|
||||
|
||||
def getFloatHeader(name: String): Option[Float] = castedHeader(name, java.lang.Float.parseFloat)
|
||||
|
||||
def getDoubleHeader(name: String): Option[Double] = castedHeader(name, java.lang.Double.parseDouble)
|
||||
|
||||
def getBooleanHeader(name: String): Option[Boolean] = castedHeader(name, java.lang.Boolean.parseBoolean)
|
||||
|
||||
private def castedHeader[U](name: String, conversion: String => U): Option[U] = {
|
||||
Try {
|
||||
header(name).map(conversion)
|
||||
}.get
|
||||
}
|
||||
}
|
||||
|
||||
sealed case class ApiResponse[T](code: Int, content: T, headers: Map[String, String] = Map.empty)
|
||||
@ -28,7 +42,7 @@ sealed case class ApiResponse[T](code: Int, content: T, headers: Map[String, Str
|
||||
|
||||
sealed case class ApiError[T](code: Int, message: String, responseContent: Option[T], cause: Throwable = null, headers: Map[String, String] = Map.empty)
|
||||
extends Throwable(s"($code) $message.${responseContent.map(s => s" Content : $s").getOrElse("")}", cause)
|
||||
with ApiReturnWithHeaders
|
||||
with ApiReturnWithHeaders
|
||||
|
||||
sealed case class ApiMethod(value: String)
|
||||
|
||||
@ -74,15 +88,17 @@ object ApiKeyLocations {
|
||||
case object QUERY extends ApiKeyLocation
|
||||
|
||||
case object HEADER extends ApiKeyLocation
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Case class used to unapply numeric values only in pattern matching
|
||||
*
|
||||
* @param value the string representation of the numeric value
|
||||
*/
|
||||
sealed case class NumericValue(value: String) {
|
||||
override def toString = value
|
||||
override def toString: String = value
|
||||
}
|
||||
|
||||
object NumericValue {
|
||||
@ -144,9 +160,9 @@ object ParametersMap {
|
||||
*/
|
||||
implicit class ParametersMapImprovements(val m: Map[String, Any]) {
|
||||
|
||||
def asFormattedParamsList = m.toList.flatMap(formattedParams)
|
||||
def asFormattedParamsList: List[(String, Any)] = m.toList.flatMap(formattedParams)
|
||||
|
||||
def asFormattedParams = m.flatMap(formattedParams)
|
||||
def asFormattedParams: Map[String, Any] = m.flatMap(formattedParams)
|
||||
|
||||
private def urlEncode(v: Any) = URLEncoder.encode(String.valueOf(v), "utf-8").replaceAll("\\+", "%20")
|
||||
|
||||
@ -159,15 +175,13 @@ object ParametersMap {
|
||||
case format: MergedArrayFormat => Seq((name, arr.values.mkString(format.separator)))
|
||||
}
|
||||
case None => Seq.empty
|
||||
case Some(opt) =>
|
||||
formattedParams(name, opt)
|
||||
case s: Seq[Any] =>
|
||||
formattedParams(name, ArrayValues(s))
|
||||
case Some(opt) => formattedParams(name, opt)
|
||||
case s: Seq[Any] => formattedParams(name, ArrayValues(s))
|
||||
case v: String => Seq((name, urlEncode(v)))
|
||||
case NumericValue(v) => Seq((name, urlEncode(v)))
|
||||
case f: File => Seq((name, f))
|
||||
case m: ApiModel => Seq((name, m))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user