From aaa0603e298bdf625209bf442caf7243272ee424 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Sun, 7 Jun 2015 20:47:22 -0700 Subject: [PATCH] rebuilt, added back imports --- samples/client/petstore/scala/pom.xml | 11 +- .../scala/io/swagger/client/ApiInvoker.scala | 329 +++++---- .../scala/io/swagger/client/api/PetApi.scala | 671 +++++++++--------- .../io/swagger/client/api/StoreApi.scala | 328 ++++----- .../scala/io/swagger/client/api/UserApi.scala | 632 +++++++++-------- .../io/swagger/client/model/Category.scala | 12 +- .../scala/io/swagger/client/model/Order.scala | 23 +- .../scala/io/swagger/client/model/Pet.scala | 24 +- .../scala/io/swagger/client/model/Tag.scala | 12 +- .../scala/io/swagger/client/model/User.scala | 26 +- .../scala/src/test/scala/PetApiTest.scala | 10 + .../scala/src/test/scala/StoreApiTest.scala | 10 + .../scala/src/test/scala/UserApiTest.scala | 10 + 13 files changed, 1104 insertions(+), 994 deletions(-) diff --git a/samples/client/petstore/scala/pom.xml b/samples/client/petstore/scala/pom.xml index 672987339d..75b711d3ee 100644 --- a/samples/client/petstore/scala/pom.xml +++ b/samples/client/petstore/scala/pom.xml @@ -1,4 +1,4 @@ - 4.0.0 io.swagger @@ -81,7 +81,8 @@ - src/main/java + + src/main/java @@ -93,7 +94,8 @@ - src/test/java + + src/test/java @@ -104,7 +106,8 @@ maven-compiler-plugin 2.3.2 - 1.6 + + 1.6 1.6 diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala index 3d766d5cd8..516e545b19 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala @@ -1,184 +1,203 @@ package io.swagger.client +import com.sun.jersey.api.client.Client +import com.sun.jersey.api.client.ClientResponse +import com.sun.jersey.api.client.config.ClientConfig +import com.sun.jersey.api.client.config.DefaultClientConfig +import com.sun.jersey.api.client.filter.LoggingFilter + +import com.sun.jersey.core.util.MultivaluedMapImpl +import com.sun.jersey.multipart.FormDataMultiPart +import com.sun.jersey.multipart.file.FileDataBodyPart + import java.io.File import java.net.URLEncoder +import javax.ws.rs.core.MediaType import scala.collection.JavaConverters._ import scala.collection.mutable.HashMap +import com.fasterxml.jackson.module.scala.DefaultScalaModule +import com.fasterxml.jackson.datatype.joda.JodaModule +import com.fasterxml.jackson.core.JsonGenerator.Feature +import com.fasterxml.jackson.databind._ +import com.fasterxml.jackson.annotation._ +import com.fasterxml.jackson.databind.annotation.JsonSerialize + object ScalaJsonUtil { - def getJsonMapper = { - val mapper = new ObjectMapper() - mapper.registerModule(new DefaultScalaModule()) - mapper.registerModule(new JodaModule()); - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT) - mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY) - mapper - } +def getJsonMapper = { +val mapper = new ObjectMapper() +mapper.registerModule(new DefaultScalaModule()) +mapper.registerModule(new JodaModule()); +mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); +mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT) +mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) +mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) +mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY) +mapper +} } class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, - httpHeaders: HashMap[String, String] = HashMap(), - hostMap: HashMap[String, Client] = HashMap(), - asyncHttpClient: Boolean = false, - authScheme: String = "", - authPreemptive: Boolean = false) { +httpHeaders: HashMap[String, String] = HashMap(), +hostMap: HashMap[String, Client] = HashMap(), +asyncHttpClient: Boolean = false, +authScheme: String = "", +authPreemptive: Boolean = false) { - var defaultHeaders: HashMap[String, String] = httpHeaders +var defaultHeaders: HashMap[String, String] = httpHeaders - def escape(value: Long): String = value.toString +def escape(value: String): String = { +URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20") +} - def escape(value: Double): String = value.toString +def escape(value: Long): String = value.toString +def escape(value: Double): String = value.toString +def escape(value: Float): String = value.toString - def escape(value: Float): String = value.toString +def deserialize(json: String, containerType: String, cls: Class[_]) = { +if (cls == classOf[String]) { +json match { +case s: String => { +if (s.startsWith("\"") && s.endsWith("\"") && s.length > 1) s.substring(1, s.length - 2) +else s +} +case _ => null +} +} else { +containerType.toLowerCase match { +case "array" => { +val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls) +val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]] +response.asScala.toList +} +case "list" => { +val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls) +val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]] +response.asScala.toList +} +case _ => { +json match { +case e: String if ("\"\"" == e) => null +case _ => mapper.readValue(json, cls) +} +} +} +} +} - def deserialize(json: String, containerType: String, cls: Class[_]) = { - if (cls == classOf[String]) { - json match { - case s: String => { - if (s.startsWith("\"") && s.endsWith("\"") && s.length > 1) s.substring(1, s.length - 2) - else s - } - case _ => null - } - } else { - containerType.toLowerCase match { - case "array" => { - val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls) - val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]] - response.asScala.toList - } - case "list" => { - val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls) - val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]] - response.asScala.toList - } - case _ => { - json match { - case e: String if ("\"\"" == e) => null - case _ => mapper.readValue(json, cls) - } - } - } - } - } +def serialize(obj: AnyRef): String = { +if (obj != null) { +obj match { +case e: List[_] => mapper.writeValueAsString(obj.asInstanceOf[List[_]].asJava) +case _ => mapper.writeValueAsString(obj) +} +} else null +} - def invokeApi(host: String, path: String, method: String, queryParams: Map[String, String], formParams: Map[String, String], body: AnyRef, headerParams: Map[String, String], contentType: String): String = { - val client = getClient(host) +def invokeApi(host: String, path: String, method: String, queryParams: Map[String, String], formParams: Map[String, String], body: AnyRef, headerParams: Map[String, String], contentType: String): String = { +val client = getClient(host) - val querystring = queryParams.filter(k => k._2 != null).map(k => (escape(k._1) + "=" + escape(k._2))).mkString("?", "&", "") - val builder = client.resource(host + path + querystring).accept(contentType) - headerParams.map(p => builder.header(p._1, p._2)) - defaultHeaders.map(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) - } - }) - var formData: MultivaluedMapImpl = null - if (contentType == "application/x-www-form-urlencoded") { - formData = new MultivaluedMapImpl() - formParams.map(p => formData.add(p._1, p._2)) - } +val querystring = queryParams.filter(k => k._2 != null).map(k => (escape(k._1) + "=" + escape(k._2))).mkString("?", "&", "") +val builder = client.resource(host + path + querystring).accept(contentType) +headerParams.map(p => builder.header(p._1, p._2)) +defaultHeaders.map(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) +} +}) +var formData: MultivaluedMapImpl = null +if(contentType == "application/x-www-form-urlencoded") { +formData = new MultivaluedMapImpl() +formParams.map(p => formData.add(p._1, p._2)) +} - val response: ClientResponse = method match { - case "GET" => { - builder.get(classOf[ClientResponse]).asInstanceOf[ClientResponse] - } - case "POST" => { - if (formData != null) builder.post(classOf[ClientResponse], formData) - else if (body != null && body.isInstanceOf[File]) { - val file = body.asInstanceOf[File] - val form = new FormDataMultiPart() - form.field("filename", file.getName()) - form.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE)) - builder.post(classOf[ClientResponse], form) - } - else { - if (body == null) builder.post(classOf[ClientResponse], serialize(body)) - else builder.`type`(contentType).post(classOf[ClientResponse], serialize(body)) - } - } - case "PUT" => { - if (formData != null) builder.post(classOf[ClientResponse], formData) - else if (body == null) builder.put(classOf[ClientResponse], null) - else builder.`type`(contentType).put(classOf[ClientResponse], serialize(body)) - } - case "DELETE" => { - builder.delete(classOf[ClientResponse]) - } - case _ => null - } - response.getClientResponseStatus().getStatusCode() match { - case 204 => "" - case code: Int if (Range(200, 299).contains(code)) => { - response.hasEntity() match { - case true => response.getEntity(classOf[String]) - case false => "" - } - } - case _ => { - val entity = response.hasEntity() match { - case true => response.getEntity(classOf[String]) - case false => "no data" - } - throw new ApiException( - response.getClientResponseStatus().getStatusCode(), - entity) - } - } - } +val response: ClientResponse = method match { +case "GET" => { +builder.get(classOf[ClientResponse]).asInstanceOf[ClientResponse] +} +case "POST" => { +if(formData != null) builder.post(classOf[ClientResponse], formData) +else if(body != null && body.isInstanceOf[File]) { +val file = body.asInstanceOf[File] +val form = new FormDataMultiPart() +form.field("filename", file.getName()) +form.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE)) +builder.post(classOf[ClientResponse], form) +} +else { +if(body == null) builder.post(classOf[ClientResponse], serialize(body)) +else builder.`type`(contentType).post(classOf[ClientResponse], serialize(body)) +} +} +case "PUT" => { +if(formData != null) builder.post(classOf[ClientResponse], formData) +else if(body == null) builder.put(classOf[ClientResponse], null) +else builder.`type`(contentType).put(classOf[ClientResponse], serialize(body)) +} +case "DELETE" => { +builder.delete(classOf[ClientResponse]) +} +case _ => null +} +response.getClientResponseStatus().getStatusCode() match { +case 204 => "" +case code: Int if (Range(200, 299).contains(code)) => { +response.hasEntity() match { +case true => response.getEntity(classOf[String]) +case false => "" +} +} +case _ => { +val entity = response.hasEntity() match { +case true => response.getEntity(classOf[String]) +case false => "no data" +} +throw new ApiException( +response.getClientResponseStatus().getStatusCode(), +entity) +} +} +} - def escape(value: String): String = { - URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20") - } +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 +} +} +} - def serialize(obj: AnyRef): String = { - if (obj != null) { - obj match { - case e: List[_] => mapper.writeValueAsString(obj.asInstanceOf[List[_]].asJava) - case _ => mapper.writeValueAsString(obj) - } - } else null - } +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 - 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 - } - } - } - - def newClient(host: String): Client = asyncHttpClient match { - case true => { - - 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() - } +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() +} } object ApiInvoker extends ApiInvoker(mapper = ScalaJsonUtil.getJsonMapper, - httpHeaders = HashMap(), - hostMap = HashMap(), - asyncHttpClient = false, - authScheme = "", - authPreemptive = false) +httpHeaders = HashMap(), +hostMap = HashMap(), +asyncHttpClient = false, +authScheme = "", +authPreemptive = false) class ApiException(val code: Int, msg: String) extends RuntimeException(msg) diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala index f400645e55..305a16c282 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/PetApi.scala @@ -1,423 +1,434 @@ package io.swagger.client.api +import io.swagger.client.model.Pet import java.io.File +import io.swagger.client.ApiInvoker +import io.swagger.client.ApiException + +import com.sun.jersey.multipart.FormDataMultiPart +import com.sun.jersey.multipart.file.FileDataBodyPart + +import javax.ws.rs.core.MediaType + +import java.io.File +import java.util.Date import scala.collection.mutable.HashMap -class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2", - defApiInvoker: ApiInvoker = ApiInvoker) { - var basePath = defBasePath - var apiInvoker = defApiInvoker + class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2", + defApiInvoker: ApiInvoker = ApiInvoker) { + var basePath = defBasePath + var apiInvoker = defApiInvoker - def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value + def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + * @return void + */ + def updatePet (body: Pet) = { + // create path and map variables + val path = "/pet".replaceAll("\\{format\\}","json") - /** - * Update an existing pet - * - * @param body Pet object that needs to be added to the store - * @return void - */ - def updatePet(body: Pet) = { - // create path and map variables - val path = "/pet".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json", "application/xml", "application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json", "application/xml", "application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + + var postBody: AnyRef = body + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = body - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + * @return void + */ + def addPet (body: Pet) = { + // create path and map variables + val path = "/pet".replaceAll("\\{format\\}","json") - /** - * Add a new pet to the store - * - * @param body Pet object that needs to be added to the store - * @return void - */ - def addPet(body: Pet) = { - // create path and map variables - val path = "/pet".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json", "application/xml", "application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json", "application/xml", "application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + + var postBody: AnyRef = body + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = body - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + * @return List[Pet] + */ + def findPetsByStatus (status: List[String] /* = available */) : Option[List[Pet]] = { + // create path and map variables + val path = "/pet/findByStatus".replaceAll("\\{format\\}","json") - /** - * Finds Pets by status - * Multiple status values can be provided with comma seperated strings - * @param status Status values that need to be considered for filter - * @return List[Pet] - */ - def findPetsByStatus(status: List[String] /* = available */): Option[List[Pet]] = { - // create path and map variables - val path = "/pet/findByStatus".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + if(String.valueOf(status) != "null") queryParams += "status" -> status.toString + + - if (String.valueOf(status) != "null") queryParams += "status" -> status.toString + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - Some(ApiInvoker.deserialize(s, "array", classOf[Pet]).asInstanceOf[List[Pet]]) - + Some(ApiInvoker.deserialize(s, "array", classOf[Pet]).asInstanceOf[List[Pet]]) + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + * @return List[Pet] + */ + def findPetsByTags (tags: List[String]) : Option[List[Pet]] = { + // create path and map variables + val path = "/pet/findByTags".replaceAll("\\{format\\}","json") - /** - * Finds Pets by tags - * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - * @param tags Tags to filter by - * @return List[Pet] - */ - def findPetsByTags(tags: List[String]): Option[List[Pet]] = { - // create path and map variables - val path = "/pet/findByTags".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + if(String.valueOf(tags) != "null") queryParams += "tags" -> tags.toString + + - if (String.valueOf(tags) != "null") queryParams += "tags" -> tags.toString + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - Some(ApiInvoker.deserialize(s, "array", classOf[Pet]).asInstanceOf[List[Pet]]) - + Some(ApiInvoker.deserialize(s, "array", classOf[Pet]).asInstanceOf[List[Pet]]) + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + * @return Pet + */ + def getPetById (petId: Long) : Option[Pet] = { + // create path and map variables + val path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId)) - /** - * Find pet by ID - * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - * @param petId ID of pet that needs to be fetched - * @return Pet - */ - def getPetById(petId: Long): Option[Pet] = { - // create path and map variables - val path = "/pet/{petId}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escape(petId)) + + val contentTypes = List("application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - Some(ApiInvoker.deserialize(s, "", classOf[Pet]).asInstanceOf[Pet]) - + Some(ApiInvoker.deserialize(s, "", classOf[Pet]).asInstanceOf[Pet]) + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + * @return void + */ + def updatePetWithForm (petId: String, name: String, status: String) = { + // create path and map variables + val path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId)) - /** - * Updates a pet in the store with form data - * - * @param petId ID of pet that needs to be updated - * @param name Updated name of the pet - * @param status Updated status of the pet - * @return void - */ - def updatePetWithForm(petId: String, name: String, status: String) = { - // create path and map variables - val path = "/pet/{petId}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escape(petId)) + + val contentTypes = List("application/x-www-form-urlencoded", "application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("application/x-www-form-urlencoded", "application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + mp.field("name", name.toString(), MediaType.MULTIPART_FORM_DATA_TYPE) + + mp.field("status", status.toString(), MediaType.MULTIPART_FORM_DATA_TYPE) + + postBody = mp + } + else { + formParams += "name" -> name.toString() + formParams += "status" -> status.toString() + + } - - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - mp.field("name", name.toString(), MediaType.MULTIPART_FORM_DATA_TYPE) - - mp.field("status", status.toString(), MediaType.MULTIPART_FORM_DATA_TYPE) - - postBody = mp - } - else { - formParams += "name" -> name.toString() - formParams += "status" -> status.toString() - - } - - try { - apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Deletes a pet + * + * @param apiKey + * @param petId Pet id to delete + * @return void + */ + def deletePet (apiKey: String, petId: Long) = { + // create path and map variables + val path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId)) - /** - * Deletes a pet - * - * @param apiKey - * @param petId Pet id to delete - * @return void - */ - def deletePet(apiKey: String, petId: Long) = { - // create path and map variables - val path = "/pet/{petId}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escape(petId)) + + val contentTypes = List("application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + headerParams += "api_key" -> apiKey + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - headerParams += "api_key" -> apiKey - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + * @return void + */ + def uploadFile (petId: Long, additionalMetadata: String, file: File) = { + // create path and map variables + val path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId)) - /** - * uploads an image - * - * @param petId ID of pet to update - * @param additionalMetadata Additional data to pass to server - * @param file file to upload - * @return void - */ - def uploadFile(petId: Long, additionalMetadata: String, file: File) = { - // create path and map variables - val path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escape(petId)) + + val contentTypes = List("multipart/form-data", "application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("multipart/form-data", "application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + mp.field("additionalMetadata", additionalMetadata.toString(), MediaType.MULTIPART_FORM_DATA_TYPE) + + mp.field("file", file.getName) + mp.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE)) + + postBody = mp + } + else { + formParams += "additionalMetadata" -> additionalMetadata.toString() + + + } - - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - mp.field("additionalMetadata", additionalMetadata.toString(), MediaType.MULTIPART_FORM_DATA_TYPE) - - mp.field("file", file.getName) - mp.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE)) - - postBody = mp - } - else { - formParams += "additionalMetadata" -> additionalMetadata.toString() - - - } - - try { - apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + } - } - -} diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala index f2be527bbb..084794af60 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/StoreApi.scala @@ -1,207 +1,219 @@ package io.swagger.client.api +import io.swagger.client.model.Order +import io.swagger.client.ApiInvoker +import io.swagger.client.ApiException + +import com.sun.jersey.multipart.FormDataMultiPart +import com.sun.jersey.multipart.file.FileDataBodyPart + +import javax.ws.rs.core.MediaType + +import java.io.File +import java.util.Date + import scala.collection.mutable.HashMap -class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2", - defApiInvoker: ApiInvoker = ApiInvoker) { - var basePath = defBasePath - var apiInvoker = defApiInvoker + class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2", + defApiInvoker: ApiInvoker = ApiInvoker) { + var basePath = defBasePath + var apiInvoker = defApiInvoker - def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value + def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + * @return Map[String, Integer] + */ + def getInventory () : Option[Map[String, Integer]] = { + // create path and map variables + val path = "/store/inventory".replaceAll("\\{format\\}","json") - /** - * Returns pet inventories by status - * Returns a map of status codes to quantities - * @return Map[String, Integer] - */ - def getInventory(): Option[Map[String, Integer]] = { - // create path and map variables - val path = "/store/inventory".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - Some(ApiInvoker.deserialize(s, "map", classOf[Integer]).asInstanceOf[Map[String, Integer]]) - + Some(ApiInvoker.deserialize(s, "map", classOf[Integer]).asInstanceOf[Map[String, Integer]]) + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + * @return Order + */ + def placeOrder (body: Order) : Option[Order] = { + // create path and map variables + val path = "/store/order".replaceAll("\\{format\\}","json") - /** - * Place an order for a pet - * - * @param body order placed for purchasing the pet - * @return Order - */ - def placeOrder(body: Order): Option[Order] = { - // create path and map variables - val path = "/store/order".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + + var postBody: AnyRef = body + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = body - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - Some(ApiInvoker.deserialize(s, "", classOf[Order]).asInstanceOf[Order]) - + Some(ApiInvoker.deserialize(s, "", classOf[Order]).asInstanceOf[Order]) + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + * @return Order + */ + def getOrderById (orderId: String) : Option[Order] = { + // create path and map variables + val path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}",apiInvoker.escape(orderId)) - /** - * Find purchase order by ID - * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * @param orderId ID of pet that needs to be fetched - * @return Order - */ - def getOrderById(orderId: String): Option[Order] = { - // create path and map variables - val path = "/store/order/{orderId}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escape(orderId)) + + val contentTypes = List("application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - Some(ApiInvoker.deserialize(s, "", classOf[Order]).asInstanceOf[Order]) - + Some(ApiInvoker.deserialize(s, "", classOf[Order]).asInstanceOf[Order]) + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + * @return void + */ + def deleteOrder (orderId: String) = { + // create path and map variables + val path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}",apiInvoker.escape(orderId)) - /** - * Delete purchase order by ID - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * @param orderId ID of the order that needs to be deleted - * @return void - */ - def deleteOrder(orderId: String) = { - // create path and map variables - val path = "/store/order/{orderId}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escape(orderId)) + + val contentTypes = List("application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + } - } - -} diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/UserApi.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/UserApi.scala index 984c684cbf..98375741bb 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/UserApi.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/api/UserApi.scala @@ -1,400 +1,412 @@ package io.swagger.client.api +import io.swagger.client.model.User +import io.swagger.client.ApiInvoker +import io.swagger.client.ApiException + +import com.sun.jersey.multipart.FormDataMultiPart +import com.sun.jersey.multipart.file.FileDataBodyPart + +import javax.ws.rs.core.MediaType + +import java.io.File +import java.util.Date + import scala.collection.mutable.HashMap -class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2", - defApiInvoker: ApiInvoker = ApiInvoker) { - var basePath = defBasePath - var apiInvoker = defApiInvoker + class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2", + defApiInvoker: ApiInvoker = ApiInvoker) { + var basePath = defBasePath + var apiInvoker = defApiInvoker - def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value + def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + * @return void + */ + def createUser (body: User) = { + // create path and map variables + val path = "/user".replaceAll("\\{format\\}","json") - /** - * Create user - * This can only be done by the logged in user. - * @param body Created user object - * @return void - */ - def createUser(body: User) = { - // create path and map variables - val path = "/user".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + + var postBody: AnyRef = body + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = body - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return void + */ + def createUsersWithArrayInput (body: List[User]) = { + // create path and map variables + val path = "/user/createWithArray".replaceAll("\\{format\\}","json") - /** - * Creates list of users with given input array - * - * @param body List of user object - * @return void - */ - def createUsersWithArrayInput(body: List[User]) = { - // create path and map variables - val path = "/user/createWithArray".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + + var postBody: AnyRef = body + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = body - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return void + */ + def createUsersWithListInput (body: List[User]) = { + // create path and map variables + val path = "/user/createWithList".replaceAll("\\{format\\}","json") - /** - * Creates list of users with given input array - * - * @param body List of user object - * @return void - */ - def createUsersWithListInput(body: List[User]) = { - // create path and map variables - val path = "/user/createWithList".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + + var postBody: AnyRef = body + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = body - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + * @return String + */ + def loginUser (username: String, password: String) : Option[String] = { + // create path and map variables + val path = "/user/login".replaceAll("\\{format\\}","json") - /** - * Logs user into the system - * - * @param username The user name for login - * @param password The password for login in clear text - * @return String - */ - def loginUser(username: String, password: String): Option[String] = { - // create path and map variables - val path = "/user/login".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + if(String.valueOf(username) != "null") queryParams += "username" -> username.toString + if(String.valueOf(password) != "null") queryParams += "password" -> password.toString + + - if (String.valueOf(username) != "null") queryParams += "username" -> username.toString - if (String.valueOf(password) != "null") queryParams += "password" -> password.toString + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - Some(ApiInvoker.deserialize(s, "", classOf[String]).asInstanceOf[String]) - + Some(ApiInvoker.deserialize(s, "", classOf[String]).asInstanceOf[String]) + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Logs out current logged in user session + * + * @return void + */ + def logoutUser () = { + // create path and map variables + val path = "/user/logout".replaceAll("\\{format\\}","json") - /** - * Logs out current logged in user session - * - * @return void - */ - def logoutUser() = { - // create path and map variables - val path = "/user/logout".replaceAll("\\{format\\}", "json") + val contentTypes = List("application/json") + val contentType = contentTypes(0) - val contentTypes = List("application/json") - val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return User + */ + def getUserByName (username: String) : Option[User] = { + // create path and map variables + val path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escape(username)) - /** - * Get user by user name - * - * @param username The name that needs to be fetched. Use user1 for testing. - * @return User - */ - def getUserByName(username: String): Option[User] = { - // create path and map variables - val path = "/user/{username}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escape(username)) + + val contentTypes = List("application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - Some(ApiInvoker.deserialize(s, "", classOf[User]).asInstanceOf[User]) - + Some(ApiInvoker.deserialize(s, "", classOf[User]).asInstanceOf[User]) + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + * @return void + */ + def updateUser (username: String, body: User) = { + // create path and map variables + val path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escape(username)) - /** - * Updated user - * This can only be done by the logged in user. - * @param username name that need to be deleted - * @param body Updated user object - * @return void - */ - def updateUser(username: String, body: User) = { - // create path and map variables - val path = "/user/{username}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escape(username)) + + val contentTypes = List("application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + var postBody: AnyRef = body + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - - var postBody: AnyRef = body - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex - } - } + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + * @return void + */ + def deleteUser (username: String) = { + // create path and map variables + val path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escape(username)) - /** - * Delete user - * This can only be done by the logged in user. - * @param username The name that needs to be deleted - * @return void - */ - def deleteUser(username: String) = { - // create path and map variables - val path = "/user/{username}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escape(username)) + + val contentTypes = List("application/json") + val contentType = contentTypes(0) + // query params + val queryParams = new HashMap[String, String] + val headerParams = new HashMap[String, String] + val formParams = new HashMap[String, String] - val contentTypes = List("application/json") - val contentType = contentTypes(0) + - // query params - val queryParams = new HashMap[String, String] - val headerParams = new HashMap[String, String] - val formParams = new HashMap[String, String] + + + var postBody: AnyRef = null + if(contentType.startsWith("multipart/form-data")) { + val mp = new FormDataMultiPart() + + postBody = mp + } + else { + + } - - - - var postBody: AnyRef = null - - if (contentType.startsWith("multipart/form-data")) { - val mp = new FormDataMultiPart() - - postBody = mp - } - else { - - } - - try { - apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { + try { + apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { case s: String => - + case _ => None - } - } catch { - case ex: ApiException if ex.code == 404 => None - case ex: ApiException => throw ex + } + } catch { + case ex: ApiException if ex.code == 404 => None + case ex: ApiException => throw ex + } + } + } - } - -} diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Category.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Category.scala index dcc19f58d7..0b4fdab413 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Category.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Category.scala @@ -1,7 +1,11 @@ package io.swagger.client.model -case class Category( - id: Long, - name: String) - + + + + case class Category ( + id: Long, + name: String) + + diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Order.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Order.scala index f05630501c..d2e4b77f90 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Order.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Order.scala @@ -1,12 +1,17 @@ package io.swagger.client.model +import org.joda.time.DateTime -case class Order( - id: Long, - petId: Long, - quantity: Integer, - shipDate: DateTime, - /* Order Status */ - status: String, - complete: Boolean) - + + + + case class Order ( + id: Long, + petId: Long, + quantity: Integer, + shipDate: DateTime, + /* Order Status */ + status: String, + complete: Boolean) + + diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala index 96d2a5677a..e51a5f25a4 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Pet.scala @@ -1,12 +1,18 @@ package io.swagger.client.model +import io.swagger.client.model.Category +import io.swagger.client.model.Tag -case class Pet( - id: Long, - category: Category, - name: String, - photoUrls: List[String], - tags: List[Tag], - /* pet status in the store */ - status: String) - + + + + case class Pet ( + id: Long, + category: Category, + name: String, + photoUrls: List[String], + tags: List[Tag], + /* pet status in the store */ + status: String) + + diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Tag.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Tag.scala index e495653cf2..d541ca315a 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Tag.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/Tag.scala @@ -1,7 +1,11 @@ package io.swagger.client.model -case class Tag( - id: Long, - name: String) - + + + + case class Tag ( + id: Long, + name: String) + + diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/User.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/User.scala index 8f7be17799..f7b826ec0f 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/User.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/model/User.scala @@ -1,14 +1,18 @@ package io.swagger.client.model -case class User( - id: Long, - username: String, - firstName: String, - lastName: String, - email: String, - password: String, - phone: String, - /* User Status */ - userStatus: Integer) - + + + + case class User ( + id: Long, + username: String, + firstName: String, + lastName: String, + email: String, + password: String, + phone: String, + /* User Status */ + userStatus: Integer) + + diff --git a/samples/client/petstore/scala/src/test/scala/PetApiTest.scala b/samples/client/petstore/scala/src/test/scala/PetApiTest.scala index 32af4aa4dd..dc0fca27b2 100644 --- a/samples/client/petstore/scala/src/test/scala/PetApiTest.scala +++ b/samples/client/petstore/scala/src/test/scala/PetApiTest.scala @@ -1,4 +1,14 @@ +import io.swagger.client._ +import io.swagger.client.api._ +import io.swagger.client.model._ + +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner +import org.scalatest._ +import scala.collection.mutable.{ ListBuffer, HashMap } +import scala.collection.JavaConverters._ +import scala.beans.BeanProperty @RunWith(classOf[JUnitRunner]) class PetApiTest extends FlatSpec with Matchers { diff --git a/samples/client/petstore/scala/src/test/scala/StoreApiTest.scala b/samples/client/petstore/scala/src/test/scala/StoreApiTest.scala index a22e1a0888..5a1d641c12 100644 --- a/samples/client/petstore/scala/src/test/scala/StoreApiTest.scala +++ b/samples/client/petstore/scala/src/test/scala/StoreApiTest.scala @@ -1,4 +1,14 @@ +import io.swagger.client._ +import io.swagger.client.api._ +import io.swagger.client.model._ + +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner +import org.scalatest._ +import scala.collection.mutable.{ ListBuffer, HashMap } +import scala.collection.JavaConverters._ +import scala.beans.BeanProperty @RunWith(classOf[JUnitRunner]) class StoreApiTest extends FlatSpec with Matchers { diff --git a/samples/client/petstore/scala/src/test/scala/UserApiTest.scala b/samples/client/petstore/scala/src/test/scala/UserApiTest.scala index 60f184329b..ea0fda03d9 100644 --- a/samples/client/petstore/scala/src/test/scala/UserApiTest.scala +++ b/samples/client/petstore/scala/src/test/scala/UserApiTest.scala @@ -1,4 +1,14 @@ +import io.swagger.client._ +import io.swagger.client.api._ +import io.swagger.client.model._ + +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner +import org.scalatest._ +import scala.collection.mutable.{ ListBuffer, HashMap } +import scala.collection.JavaConverters._ +import scala.beans.BeanProperty @RunWith(classOf[JUnitRunner]) class UserApiTest extends FlatSpec with Matchers {