have an empty body param for setting a different value for write requests

This commit is contained in:
Ivan Porto Carrero 2013-05-12 17:17:42 -07:00
parent dfdd8cac94
commit 023013b6fe
3 changed files with 8 additions and 8 deletions

View File

@ -25,19 +25,17 @@ class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiC
{{#requiredParamCount}} {{#requiredParamCount}}
// verify required params are set // verify required params are set
(Set({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size match { val paramCount = (Set({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size
case {{requiredParamCount}} => // all required values set if (paramCount != {{requiredParamCount}}) sys.error("missing required params")
case _ => throw new Exception("missing required params")
}
{{/requiredParamCount}} {{/requiredParamCount}}
{{#queryParams}}if(String.valueOf({{paramName}}) != "null") queryParams += "{{baseName}}" -> {{paramName}}.toString {{#queryParams}}if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString
{{/queryParams}} {{/queryParams}}
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString {{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString
{{/headerParams}} {{/headerParams}}
val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}ser.serialize({{bodyParam}}){{/bodyParam}}{{^bodyParam}}""{{/bodyParam}}) val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}ser.serialize({{bodyParam}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}})
resFuture flatMap { resp => resFuture flatMap { resp =>
process({{^returnType}}(){{/returnType}}{{#returnType}}ser.deserialize[{{returnType}}](resp.body) {{/returnType}}) process({{^returnType}}(){{/returnType}}{{#returnType}}ser.deserialize[{{returnType}}](resp.body) {{/returnType}})
} }

View File

@ -4,10 +4,10 @@ name := "{{projectName}}-client"
scalaVersion := "2.10.0" scalaVersion := "2.10.0"
libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.1.4" libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.1.6"
libraryDependencies += "joda-time" % "joda-time" % "2.2" libraryDependencies += "joda-time" % "joda-time" % "2.2"
libraryDependencies += "org.joda" % "joda-convert" % "1.3.1" libraryDependencies += "org.joda" % "joda-convert" % "1.3.1"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.0.12" % "provided" libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.0.13" % "provided"

View File

@ -329,6 +329,7 @@ class Codegen(config: CodegenConfig) {
} }
} }
val writeMethods = Set("POST", "PUT", "PATCH")
val properties = val properties =
HashMap[String, AnyRef]( HashMap[String, AnyRef](
"path" -> path, "path" -> path,
@ -337,6 +338,7 @@ class Codegen(config: CodegenConfig) {
"notes" -> operation.notes, "notes" -> operation.notes,
"deprecated" -> operation.`deprecated`, "deprecated" -> operation.`deprecated`,
"bodyParam" -> bodyParam, "bodyParam" -> bodyParam,
"emptyBodyParam" -> (if (writeMethods contains operation.httpMethod.toUpperCase) "{}" else ""),
"allParams" -> sp, "allParams" -> sp,
"bodyParams" -> bodyParams.toList, "bodyParams" -> bodyParams.toList,
"pathParams" -> pathParams.toList, "pathParams" -> pathParams.toList,