update async scala client to use type classes for serializing and deserializing

This commit is contained in:
Ivan Porto Carrero 2013-08-24 19:36:43 -07:00
parent e2730ae34e
commit 2610ac7fc3
5 changed files with 20 additions and 17 deletions

View File

@ -5,7 +5,7 @@ organization := "com.wordnik"
name := "swagger-codegen"
version := "2.0.8"
version := "2.0.9-SNAPSHOT"
scalaVersion := "2.9.1"
@ -16,11 +16,11 @@ scalacOptions ++= Seq("-optimize", "-unchecked", "-deprecation", "-Xcheckinit",
crossScalaVersions := Seq("2.9.0", "2.9.0-1", "2.9.1", "2.9.1-1", "2.9.2", "2.9.3", "2.10.0")
libraryDependencies ++= Seq(
"org.json4s" %% "json4s-jackson" % "3.2.4",
"org.json4s" %% "json4s-jackson" % "3.2.5",
"io.backchat.inflector" %% "scala-inflector" % "1.3.5",
"commons-io" % "commons-io" % "2.3",
"ch.qos.logback" % "logback-classic" % "1.0.10" % "provided",
"org.rogach" %% "scallop" % "0.8.1",
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
"org.rogach" %% "scallop" % "0.9.4",
"junit" % "junit" % "4.11" % "test",
"org.scalatest" %% "scalatest" % "1.9.1" % "test"
)
@ -55,6 +55,14 @@ publishTo <<= (version) { version: String =>
Some("Sonatype Nexus Releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
}
publishTo <<= (version) { version: String =>
val artifactory = "https://ci.aws.wordnik.com/artifactory/m2-"
if (version.trim.endsWith("SNAPSHOT"))
Some("snapshots" at artifactory + "snapshots")
else
Some("releases" at artifactory + "releases")
}
//publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))

View File

@ -17,13 +17,12 @@ class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiC
{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{{defaultValue}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}}, {{/hasMore}}
{{/optional}}
{{^optional}}
{{paramName}}: {{dataType}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}}, {{/hasMore}}
{{/optional}}{{/allParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = {
{{paramName}}: {{dataType}}{{#defaultValue}} = {{defaultValue}}{{/defaultValue}}{{#hasMore}}, {{/hasMore}}
{{/optional}}{{/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 =
("{{path}}"
replaceAll ("\\{format\\}", ser.name)
{{#pathParams}}replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString)
(addFmt("{{path}}"){{#pathParams}}
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString)
{{/pathParams}})
// query params
@ -42,9 +41,9 @@ class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiC
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString
{{/headerParams}}
val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}ser.serialize({{bodyParam}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}})
val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}writer.write({{bodyParam}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}})
resFuture flatMap { resp =>
process({{^returnType}}(){{/returnType}}{{#returnType}}ser.deserialize[{{returnType}}](resp.body) {{/returnType}})
process(reader.read(resp))
}
}

View File

@ -9,7 +9,6 @@ import java.io.Closeable
class {{clientName}}(config: SwaggerConfig) extends Closeable {
val locator = config.locator
val name = config.name
val dataFormat = config.dataFormat
private[this] val client = transportClient

View File

@ -2,9 +2,6 @@ package {{package}}
import org.joda.time.DateTime
{{#imports}}import {{import}}
{{/imports}}
{{#models}}
{{#model}}

View File

@ -2,7 +2,7 @@ organization := "{{package}}"
name := "{{projectName}}-client"
libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.2.1"
libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.3.0-WN4"
libraryDependencies += "joda-time" % "joda-time" % "2.2"