forked from loafle/openapi-generator-original
have an empty body param for setting a different value for write requests
This commit is contained in:
parent
dfdd8cac94
commit
023013b6fe
@ -25,19 +25,17 @@ class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiC
|
||||
|
||||
{{#requiredParamCount}}
|
||||
// verify required params are set
|
||||
(Set({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size match {
|
||||
case {{requiredParamCount}} => // all required values set
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
val paramCount = (Set({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size
|
||||
if (paramCount != {{requiredParamCount}}) sys.error("missing required params")
|
||||
{{/requiredParamCount}}
|
||||
|
||||
{{#queryParams}}if(String.valueOf({{paramName}}) != "null") queryParams += "{{baseName}}" -> {{paramName}}.toString
|
||||
{{#queryParams}}if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString
|
||||
{{/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 =>
|
||||
process({{^returnType}}(){{/returnType}}{{#returnType}}ser.deserialize[{{returnType}}](resp.body) {{/returnType}})
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ name := "{{projectName}}-client"
|
||||
|
||||
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 += "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"
|
||||
|
@ -329,6 +329,7 @@ class Codegen(config: CodegenConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
val writeMethods = Set("POST", "PUT", "PATCH")
|
||||
val properties =
|
||||
HashMap[String, AnyRef](
|
||||
"path" -> path,
|
||||
@ -337,6 +338,7 @@ class Codegen(config: CodegenConfig) {
|
||||
"notes" -> operation.notes,
|
||||
"deprecated" -> operation.`deprecated`,
|
||||
"bodyParam" -> bodyParam,
|
||||
"emptyBodyParam" -> (if (writeMethods contains operation.httpMethod.toUpperCase) "{}" else ""),
|
||||
"allParams" -> sp,
|
||||
"bodyParams" -> bodyParams.toList,
|
||||
"pathParams" -> pathParams.toList,
|
||||
|
Loading…
x
Reference in New Issue
Block a user