updated versions

This commit is contained in:
fehguy
2015-06-09 00:25:09 -07:00
parent 33c2b1b623
commit 3d2f09a693
180 changed files with 22318 additions and 26364 deletions

View File

@@ -25,179 +25,179 @@ 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: String): String = {
URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20")
}
def escape(value: String): String = {
URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20")
}
def escape(value: Long): String = value.toString
def escape(value: Double): String = value.toString
def escape(value: Float): 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 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 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 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 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 => {
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig
import org.sonatype.spice.jersey.client.ahc.AhcHttpClient
import com.ning.http.client.Realm
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
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)

View File

@@ -15,420 +15,420 @@ 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")
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]
/**
* 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)
// 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 {
}
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
}
}
/**
* 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)
// 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 {
}
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
}
}
/**
* 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)
// 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
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 {
case s: String =>
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
}
}
/**
* 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)
var postBody: AnyRef = body
// 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
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 {
case s: String =>
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
}
}
/**
* 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]
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 {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[Pet]).asInstanceOf[Pet])
case _ => None
}
} 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))
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()
}
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
}
}
/**
* 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]
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 {
case s: String =>
case _ => None
}
} 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))
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()
}
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
}
}
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 {
case s: String =>
case _ => None
}
} 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")
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]
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 {
case s: String =>
case _ => None
}
} 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")
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]
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 {
}
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]])
case _ => None
}
} 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")
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]
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 {
}
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]])
case _ => None
}
} 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))
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 {
}
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])
case _ => None
}
} 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))
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()
}
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
}
}
/**
* 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]
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 {
case s: String =>
case _ => None
}
} 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))
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()
}
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
}
}
}

View File

@@ -14,206 +14,206 @@ 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")
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]
/**
* 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)
// 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 {
}
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]])
case _ => None
}
} 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")
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 {
}
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])
case _ => None
}
} 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))
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 {
}
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])
case _ => None
}
} 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))
var postBody: AnyRef = null
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 {
}
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
}
}
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 {
case s: String =>
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
}
}
/**
* 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)
// 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 {
}
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])
case _ => None
}
} 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))
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 {
}
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])
case _ => None
}
} 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))
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 {
}
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
}
}
}

View File

@@ -14,399 +14,399 @@ 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")
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]
/**
* 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)
// 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 {
}
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
}
}
/**
* 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)
// 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 {
}
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
}
}
/**
* 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)
// 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 {
}
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
}
}
/**
* 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)
var postBody: AnyRef = body
// 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
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 {
case s: 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
}
}
/**
* 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)
// 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 {
}
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
}
}
/**
* 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]
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 {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[User]).asInstanceOf[User])
case _ => None
}
} 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))
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 {
}
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
}
}
/**
* 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]
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 {
case s: String =>
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
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 {
case s: String =>
case _ => None
}
} 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")
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 {
}
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
}
}
/**
* 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)
// 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 {
}
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
}
}
/**
* 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)
// 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
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 {
case s: 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
}
}
/**
* 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)
// 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 {
}
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
}
}
/**
* 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]
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 {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[User]).asInstanceOf[User])
case _ => None
}
} 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))
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 {
}
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
}
}
/**
* 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]
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 {
case s: String =>
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
}

View File

@@ -2,10 +2,8 @@ package io.swagger.client.model
case class Category (
id: Long,
name: String)
case class Category (
id: Long,
name: String)

View File

@@ -3,15 +3,13 @@ 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)

View File

@@ -4,15 +4,13 @@ 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)

View File

@@ -2,10 +2,8 @@ package io.swagger.client.model
case class Tag (
id: Long,
name: String)
case class Tag (
id: Long,
name: String)

View File

@@ -2,17 +2,15 @@ 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)