diff --git a/modules/swagger-codegen/src/main/resources/finch/build.sbt b/modules/swagger-codegen/src/main/resources/finch/build.sbt index 95f655766be..4ea9c6ae196 100644 --- a/modules/swagger-codegen/src/main/resources/finch/build.sbt +++ b/modules/swagger-codegen/src/main/resources/finch/build.sbt @@ -6,7 +6,7 @@ name := "finch-sample" version := "0.1.0-SNAPSHOT" -scalaVersion := "2.11.11" +scalaVersion := "2.11.12" resolvers += Resolver.sonatypeRepo("snapshots") diff --git a/modules/swagger-codegen/src/main/resources/scala/api.mustache b/modules/swagger-codegen/src/main/resources/scala/api.mustache index ea4f035b6b5..e7fedfd4d4b 100644 --- a/modules/swagger-codegen/src/main/resources/scala/api.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/api.mustache @@ -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 @@ -54,7 +54,7 @@ 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) @@ -62,6 +62,7 @@ class {{classname}}( /** * {{summary}} * {{notes}} + * {{#allParams}} * @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ @@ -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}}) } @@ -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] diff --git a/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache index ccb74ec2f4d..23dcba85623 100644 --- a/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache @@ -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()) @@ -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 @@ -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) @@ -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() } } diff --git a/modules/swagger-codegen/src/main/resources/scala/build.sbt.mustache b/modules/swagger-codegen/src/main/resources/scala/build.sbt.mustache index 24ee01b6fd5..6ecd89c0ea7 100644 --- a/modules/swagger-codegen/src/main/resources/scala/build.sbt.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/build.sbt.mustache @@ -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" ) diff --git a/modules/swagger-codegen/src/main/resources/scala/client.mustache b/modules/swagger-codegen/src/main/resources/scala/client.mustache index 8098b73c6bb..e4196a6b9f5 100644 --- a/modules/swagger-codegen/src/main/resources/scala/client.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/client.mustache @@ -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 diff --git a/modules/swagger-codegen/src/main/resources/scala/model.mustache b/modules/swagger-codegen/src/main/resources/scala/model.mustache index f44fc1e5a78..fd618c2c2ca 100644 --- a/modules/swagger-codegen/src/main/resources/scala/model.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/model.mustache @@ -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}} diff --git a/modules/swagger-codegen/src/main/resources/scala/pom.mustache b/modules/swagger-codegen/src/main/resources/scala/pom.mustache index 202b4c82446..4971619a673 100644 --- a/modules/swagger-codegen/src/main/resources/scala/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/pom.mustache @@ -236,18 +236,18 @@ - 2.11.11 - 1.2 - 2.2 - 1.19 + 2.11.12 + 1.9.2 + 2.9.9 + 1.19.4 1.5.16 1.0.5 1.0.0 - 2.8.9 + 2.9.2 - 4.8.1 + 4.12 3.1.5 - 2.2.4 + 3.0.4 0.3.5 UTF-8 diff --git a/samples/client/petstore-security-test/scala/pom.xml b/samples/client/petstore-security-test/scala/pom.xml index eceb1e6fdc4..66cd2a4003a 100644 --- a/samples/client/petstore-security-test/scala/pom.xml +++ b/samples/client/petstore-security-test/scala/pom.xml @@ -216,7 +216,7 @@ - 2.11.11 + 2.11.12 1.2 2.2 1.19 diff --git a/samples/client/petstore/scala/pom.xml b/samples/client/petstore/scala/pom.xml index eceb1e6fdc4..66cd2a4003a 100644 --- a/samples/client/petstore/scala/pom.xml +++ b/samples/client/petstore/scala/pom.xml @@ -216,7 +216,7 @@ - 2.11.11 + 2.11.12 1.2 2.2 1.19 diff --git a/samples/server/petstore/finch/build.sbt b/samples/server/petstore/finch/build.sbt index 95f655766be..4ea9c6ae196 100644 --- a/samples/server/petstore/finch/build.sbt +++ b/samples/server/petstore/finch/build.sbt @@ -6,7 +6,7 @@ name := "finch-sample" version := "0.1.0-SNAPSHOT" -scalaVersion := "2.11.11" +scalaVersion := "2.11.12" resolvers += Resolver.sonatypeRepo("snapshots")