[Scala] enhancement to indention and null check (#3775)

* fix scala api null check and indention

* minor format fix
This commit is contained in:
wing328
2016-09-13 09:56:06 +08:00
committed by GitHub
parent 153397e799
commit 907db0dd5b
4 changed files with 129 additions and 176 deletions

View File

@@ -33,14 +33,11 @@ class {{classname}}(val defBasePath: String = "{{basePath}}",
*/
def {{operationId}}({{#allParams}}{{paramName}}: {{#required}}{{dataType}}{{#defaultValue}} /* = {{{defaultValue}}}*/{{/defaultValue}}{{/required}}{{^required}}Option[{{dataType}}]{{#defaultValue}} /* = {{{defaultValue}}}*/{{/defaultValue}}{{^defaultValue}} = None{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}: Option[{{returnType}}]{{/returnType}} = {
// create path and map variables
val path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{baseName}}" + "\\}",apiInvoker.escape({{paramName}}))
val path = "{{path}}".replaceAll("\\{format\\}", "json"){{#pathParams}}.replaceAll("\\{" + "{{baseName}}" + "\\}",apiInvoker.escape({{paramName}})){{/pathParams}}
{{/pathParams}}
val contentTypes = List({{#consumes}}"{{{mediaType}}}", {{/consumes}}"application/json")
val contentTypes = List({{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}"application/json"{{/consumes}})
val contentType = contentTypes(0)
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String]
@@ -51,11 +48,15 @@ class {{classname}}(val defBasePath: String = "{{basePath}}",
if ({{paramName}} == null) throw new Exception("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
{{/isPrimitiveType}}
{{#isString}}
if ({{paramName}} == null) throw new Exception("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
{{/isString}}
{{/required}}
{{/allParams}}
{{#queryParams}}
{{#required}}
if(String.valueOf({{paramName}}) != "null") queryParams += "{{baseName}}" -> {{paramName}}.toString
queryParams += "{{baseName}}" -> {{paramName}}.toString
{{/required}}
{{^required}}
{{paramName}}.map(paramVal => queryParams += "{{baseName}}" -> paramVal.toString)
@@ -73,16 +74,18 @@ class {{classname}}(val defBasePath: String = "{{basePath}}",
var postBody: AnyRef = {{#bodyParam}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}.map(paramVal => paramVal){{/required}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}
if(contentType.startsWith("multipart/form-data")) {
val mp = new FormDataMultiPart()
{{#formParams}}{{#notFile}}
if (contentType.startsWith("multipart/form-data")) {
val mp = new FormDataMultiPart
{{#formParams}}
{{#notFile}}
{{#required}}
mp.field("{{baseName}}", {{paramName}}.toString(), MediaType.MULTIPART_FORM_DATA_TYPE)
mp.field("{{baseName}}", {{paramName}}.toString, MediaType.MULTIPART_FORM_DATA_TYPE)
{{/required}}
{{^required}}
{{paramName}}.map(paramVal => mp.field("{{baseName}}", paramVal.toString, MediaType.MULTIPART_FORM_DATA_TYPE))
{{/required}}
{{/notFile}}{{#isFile}}
{{/notFile}}
{{#isFile}}
{{#required}}
mp.field("{{baseName}}", file.getName)
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE))
@@ -91,14 +94,14 @@ class {{classname}}(val defBasePath: String = "{{basePath}}",
file.map(fileVal => mp.field("{{baseName}}", fileVal.getName))
{{paramName}}.map(paramVal => mp.bodyPart(new FileDataBodyPart("{{baseName}}", paramVal, MediaType.MULTIPART_FORM_DATA_TYPE)))
{{/required}}
{{/isFile}}{{/formParams}}
{{/isFile}}
{{/formParams}}
postBody = mp
}
else {
} else {
{{#formParams}}
{{#notFile}}
{{#required}}
formParams += "{{baseName}}" -> {{paramName}}.toString()
formParams += "{{baseName}}" -> {{paramName}}.toString
{{/required}}
{{^required}}
{{paramName}}.map(paramVal => formParams += "{{baseName}}" -> paramVal.toString)