Skip to content
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
2 changes: 1 addition & 1 deletion modules/swagger-codegen/src/main/resources/finch/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name := "finch-sample"

version := "0.1.0-SNAPSHOT"

scalaVersion := "2.11.11"
scalaVersion := "2.11.12"

resolvers += Resolver.sonatypeRepo("snapshots")

Expand Down
20 changes: 11 additions & 9 deletions modules/swagger-codegen/src/main/resources/scala/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class {{classname}}(
implicit val formats = new org.json4s.DefaultFormats {
override def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000")
}
implicit val stringReader = ClientResponseReaders.StringReader
implicit val unitReader = ClientResponseReaders.UnitReader
implicit val jvalueReader = ClientResponseReaders.JValueReader
implicit val jsonReader = JsonFormatsReader
implicit val stringWriter = RequestWriters.StringWriter
implicit val jsonWriter = JsonFormatsWriter
implicit val stringReader: ClientResponseReader[String] = ClientResponseReaders.StringReader
implicit val unitReader: ClientResponseReader[Unit] = ClientResponseReaders.UnitReader
implicit val jvalueReader: ClientResponseReader[JValue] = ClientResponseReaders.JValueReader
implicit val jsonReader: ClientResponseReader[Nothing] = JsonFormatsReader
implicit val stringWriter: RequestWriter[String] = RequestWriters.StringWriter
implicit val jsonWriter: RequestWriter[Nothing] = JsonFormatsWriter

var basePath: String = defBasePath
var apiInvoker: ApiInvoker = defApiInvoker
Expand All @@ -54,14 +54,15 @@ class {{classname}}(
apiInvoker.defaultHeaders += key -> value
}

val config = SwaggerConfig.forUrl(new URI(defBasePath))
val config: SwaggerConfig = SwaggerConfig.forUrl(new URI(defBasePath))
val client = new RestClient(config)
val helper = new {{classname}}AsyncHelper(client, config)

{{#operation}}
/**
* {{summary}}
* {{notes}}
*
{{#allParams}} * @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/
Expand All @@ -76,9 +77,10 @@ class {{classname}}(
/**
* {{summary}} asynchronously
* {{notes}}
*
{{#allParams}} * @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}} * @return Future({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}})
*/
*/
def {{operationId}}Async({{#allParams}}{{paramName}}: {{#required}}{{dataType}}{{#defaultValue}} /* = {{{defaultValue}}}*/{{/defaultValue}}{{/required}}{{^required}}Option[{{dataType}}]{{#defaultValue}} = None /* = {{{defaultValue}}}*/{{/defaultValue}}{{^defaultValue}} = None{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}} = {
helper.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
}
Expand All @@ -94,7 +96,7 @@ class {{classname}}AsyncHelper(client: TransportClient, config: SwaggerConfig) e
{{/hasMore}}{{/required}}{{/allParams}})(implicit reader: ClientResponseReader[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]{{#bodyParams}}, writer: RequestWriter[{{dataType}}]{{/bodyParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = {
// create path and map variables
val path = (addFmt("{{path}}"){{#pathParams}}
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString){{/pathParams}})
replaceAll("\\{" + "{{baseName}}" + "\\}", {{paramName}}.toString){{/pathParams}})

// query params
val queryParams = new mutable.HashMap[String, String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.fasterxml.jackson.annotation._
import com.fasterxml.jackson.databind.annotation.JsonSerialize

object ScalaJsonUtil {
def getJsonMapper = {
def getJsonMapper: ObjectMapper = {
val mapper = new ObjectMapper()
mapper.registerModule(new DefaultScalaModule())
mapper.registerModule(new JodaModule())
Expand Down Expand Up @@ -119,9 +119,8 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper,
val builder = client.resource(host + path + querystring).accept(contentType)
headerParams.map(p => builder.header(p._1, p._2))
defaultHeaders.foreach(p => {
headerParams.contains(p._1) match {
case true => // override default with supplied header
case false => if (p._2 != null) builder.header(p._1, p._2)
if (!headerParams.contains(p._1) && p._2 != null) {
builder.header(p._1, p._2)
}
})
var formData: MultivaluedMapImpl = null
Expand All @@ -131,7 +130,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper,
}

val response: ClientResponse = method match {
case "GET" => builder.get(classOf[ClientResponse]).asInstanceOf[ClientResponse]
case "GET" => builder.get(classOf[ClientResponse])
case "POST" =>
if (formData != null && formData.size() > 0) {
builder.post(classOf[ClientResponse], formData)
Expand Down Expand Up @@ -170,46 +169,48 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper,
response.getStatusInfo.getStatusCode match {
case 204 => ""
case code: Int if Range(200, 299).contains(code) =>
response.hasEntity match {
case true => response.getEntity(classOf[String])
case false => ""
if (response.hasEntity) {
response.getEntity(classOf[String])
} else {
""
}
case _ =>
val entity = response.hasEntity match {
case true => response.getEntity(classOf[String])
case false => "no data"
val entity = if (response.hasEntity) {
response.getEntity(classOf[String])
} else {
"no data"
}
throw new ApiException(response.getStatusInfo.getStatusCode, entity)
}
}

def getClient(host: String): Client = {
hostMap.contains(host) match {
case true => hostMap(host)
case false =>
val client = newClient(host)
// client.addFilter(new LoggingFilter())
hostMap += host -> client
client
}
if (hostMap.contains(host)) {
hostMap(host)
} else {
val client = newClient(host)
// client.addFilter(new LoggingFilter())
hostMap += host -> client
client
}
}

def newClient(host: String): Client = asyncHttpClient match {
case true =>
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig
import org.sonatype.spice.jersey.client.ahc.AhcHttpClient
import com.ning.http.client.Realm

val config: DefaultAhcConfig = new DefaultAhcConfig()
if (!authScheme.isEmpty) {
val authSchemeEnum = Realm.AuthScheme.valueOf(authScheme)
config
.getAsyncHttpClientConfigBuilder
.setRealm(new Realm.RealmBuilder().setScheme(authSchemeEnum)
.setUsePreemptiveAuth(authPreemptive).build)
}
AhcHttpClient.create(config)
case _ => Client.create()
def newClient(host: String): Client = if (asyncHttpClient) {
import com.ning.http.client.Realm
import org.sonatype.spice.jersey.client.ahc.AhcHttpClient
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig

val config: DefaultAhcConfig = new DefaultAhcConfig()
if (!authScheme.isEmpty) {
val authSchemeEnum = Realm.AuthScheme.valueOf(authScheme)
config
.getAsyncHttpClientConfigBuilder
.setRealm(new Realm.RealmBuilder().setScheme(authSchemeEnum)
.setUsePreemptiveAuth(authPreemptive).build)
}
AhcHttpClient.create(config)
} else {
Client.create()
}
}

Expand Down
28 changes: 13 additions & 15 deletions modules/swagger-codegen/src/main/resources/scala/build.sbt.mustache
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
version := "{{artifactVersion}}"

name := "{{artifactId}}"

organization := "{{groupId}}"

scalaVersion := "2.11.8"
version := "{{artifactVersion}}"
name := "{{artifactId}}"
organization := "{{groupId}}"
scalaVersion := "2.11.12"

libraryDependencies ++= Seq(
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.4.2",
"com.sun.jersey" % "jersey-core" % "1.19",
"com.sun.jersey" % "jersey-client" % "1.19",
"com.sun.jersey.contribs" % "jersey-multipart" % "1.19",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.9.2",
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.9.2",
"com.sun.jersey" % "jersey-core" % "1.19.4",
"com.sun.jersey" % "jersey-client" % "1.19.4",
"com.sun.jersey.contribs" % "jersey-multipart" % "1.19.4",
"org.jfarcand" % "jersey-ahc-client" % "1.0.5",
"io.swagger" % "swagger-core" % "1.5.8",
"joda-time" % "joda-time" % "2.2",
"org.joda" % "joda-convert" % "1.2",
"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.scalatest" %% "scalatest" % "3.0.4" % "test",
"junit" % "junit" % "4.12" % "test",
"com.wordnik.swagger" %% "swagger-async-httpclient" % "0.3.5"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.wordnik.swagger.client._
import java.io.Closeable

class {{clientName}}(config: SwaggerConfig) extends Closeable {
val locator = config.locator
val name = config.name
lazy val locator: ServiceLocator = config.locator
lazy val name: String = config.name

private[this] val client = transportClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {{import}}
case class {{classname}} (
{{#vars}}
{{#description}}
/* {{{description}}} */
// {{{description}}}
{{/description}}
{{{name}}}: {{^required}}Option[{{/required}}{{datatype}}{{^required}}] = None{{/required}}{{#hasMore}},{{/hasMore}}
{{/vars}}
Expand Down
14 changes: 7 additions & 7 deletions modules/swagger-codegen/src/main/resources/scala/pom.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,18 @@
</dependency>
</dependencies>
<properties>
<scala-version>2.11.11</scala-version>
<joda-version>1.2</joda-version>
<joda-time-version>2.2</joda-time-version>
<jersey-version>1.19</jersey-version>
<scala-version>2.11.12</scala-version>
<joda-version>1.9.2</joda-version>
<joda-time-version>2.9.9</joda-time-version>
<jersey-version>1.19.4</jersey-version>
<swagger-core-version>1.5.16</swagger-core-version>
<jersey-async-version>1.0.5</jersey-async-version>
<maven-plugin.version>1.0.0</maven-plugin.version>
<jackson-version>2.8.9</jackson-version>
<jackson-version>2.9.2</jackson-version>

<junit-version>4.8.1</junit-version>
<junit-version>4.12</junit-version>
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
<scala-test-version>2.2.4</scala-test-version>
<scala-test-version>3.0.4</scala-test-version>
<swagger-async-httpclient-version>0.3.5</swagger-async-httpclient-version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore-security-test/scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
</dependency>
</dependencies>
<properties>
<scala-version>2.11.11</scala-version>
<scala-version>2.11.12</scala-version>
<joda-version>1.2</joda-version>
<joda-time-version>2.2</joda-time-version>
<jersey-version>1.19</jersey-version>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
</dependency>
</dependencies>
<properties>
<scala-version>2.11.11</scala-version>
<scala-version>2.11.12</scala-version>
<joda-version>1.2</joda-version>
<joda-time-version>2.2</joda-time-version>
<jersey-version>1.19</jersey-version>
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/finch/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name := "finch-sample"

version := "0.1.0-SNAPSHOT"

scalaVersion := "2.11.11"
scalaVersion := "2.11.12"

resolvers += Resolver.sonatypeRepo("snapshots")

Expand Down