|
| 1 | +/** |
| 2 | + * Scala Client API Integration Test |
| 3 | + * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) |
| 4 | + * |
| 5 | + * OpenAPI spec version: 1 |
| 6 | + * |
| 7 | + * |
| 8 | + * NOTE: This class is auto generated by the swagger code generator program. |
| 9 | + * https://github.com/swagger-api/swagger-codegen.git |
| 10 | + * Do not edit the class manually. |
| 11 | + */ |
| 12 | + |
| 13 | +package io.swagger.client.api |
| 14 | + |
| 15 | +import java.text.SimpleDateFormat |
| 16 | + |
| 17 | +import io.swagger.client.model.ArrayByte |
| 18 | +import java.util.Date |
| 19 | +import io.swagger.client.model.Hobby |
| 20 | +import io.swagger.client.{ApiInvoker, ApiException} |
| 21 | + |
| 22 | +import com.sun.jersey.multipart.FormDataMultiPart |
| 23 | +import com.sun.jersey.multipart.file.FileDataBodyPart |
| 24 | + |
| 25 | +import javax.ws.rs.core.MediaType |
| 26 | + |
| 27 | +import java.io.File |
| 28 | +import java.util.Date |
| 29 | +import java.util.TimeZone |
| 30 | + |
| 31 | +import scala.collection.mutable.HashMap |
| 32 | + |
| 33 | +import com.wordnik.swagger.client._ |
| 34 | +import scala.concurrent.Future |
| 35 | +import collection.mutable |
| 36 | + |
| 37 | +import java.net.URI |
| 38 | + |
| 39 | +import com.wordnik.swagger.client.ClientResponseReaders.Json4sFormatsReader._ |
| 40 | +import com.wordnik.swagger.client.RequestWriters.Json4sFormatsWriter._ |
| 41 | + |
| 42 | +import scala.concurrent.ExecutionContext.Implicits.global |
| 43 | +import scala.concurrent._ |
| 44 | +import scala.concurrent.duration._ |
| 45 | +import scala.util.{Failure, Success, Try} |
| 46 | + |
| 47 | +import org.json4s._ |
| 48 | + |
| 49 | +class HobbiesApi( |
| 50 | + val defBasePath: String = "https://localhost:8080", |
| 51 | + defApiInvoker: ApiInvoker = ApiInvoker |
| 52 | +) { |
| 53 | + private lazy val dateTimeFormatter = { |
| 54 | + val formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") |
| 55 | + formatter.setTimeZone(TimeZone.getTimeZone("UTC")) |
| 56 | + formatter |
| 57 | + } |
| 58 | + private val dateFormatter = { |
| 59 | + val formatter = new SimpleDateFormat("yyyy-MM-dd") |
| 60 | + formatter.setTimeZone(TimeZone.getTimeZone("UTC")) |
| 61 | + formatter |
| 62 | + } |
| 63 | + implicit val formats = new org.json4s.DefaultFormats { |
| 64 | + override def dateFormatter = dateTimeFormatter |
| 65 | + } |
| 66 | + implicit val stringReader: ClientResponseReader[String] = ClientResponseReaders.StringReader |
| 67 | + implicit val unitReader: ClientResponseReader[Unit] = ClientResponseReaders.UnitReader |
| 68 | + implicit val jvalueReader: ClientResponseReader[JValue] = ClientResponseReaders.JValueReader |
| 69 | + implicit val jsonReader: ClientResponseReader[Nothing] = JsonFormatsReader |
| 70 | + implicit val stringWriter: RequestWriter[String] = RequestWriters.StringWriter |
| 71 | + implicit val jsonWriter: RequestWriter[Nothing] = JsonFormatsWriter |
| 72 | + |
| 73 | + var basePath: String = defBasePath |
| 74 | + var apiInvoker: ApiInvoker = defApiInvoker |
| 75 | + |
| 76 | + def addHeader(key: String, value: String): mutable.HashMap[String, String] = { |
| 77 | + apiInvoker.defaultHeaders += key -> value |
| 78 | + } |
| 79 | + |
| 80 | + val config: SwaggerConfig = SwaggerConfig.forUrl(new URI(defBasePath)) |
| 81 | + val client = new RestClient(config) |
| 82 | + val helper = new HobbiesApiAsyncHelper(client, config) |
| 83 | + |
| 84 | + /** |
| 85 | + * Get hobbies |
| 86 | + * Query hobbies with some additional optional meaningless parameters |
| 87 | + * |
| 88 | + * @param s a string (optional, default to some string) |
| 89 | + * @param i an integer (optional, default to 1) |
| 90 | + * @param l a long (optional, default to 2) |
| 91 | + * @param bool a bool (optional, default to true) |
| 92 | + * @param f a float (optional, default to 0.1) |
| 93 | + * @param d a double (optional, default to 10.005) |
| 94 | + * @param datetime a date time (optional, default to 2018-01-01T08:30:00Z-04:00) |
| 95 | + * @param date a date (optional, default to 2018-01-01) |
| 96 | + * @param b a base64 encoded string (optional, default to c3dhZ2dlciBjb2RlZ2Vu) |
| 97 | + * @param bin an octet string (optional, default to DEADBEEF) |
| 98 | + * @return Hobby |
| 99 | + */ |
| 100 | + def getHobbies(s: Option[String] = Option("some string"), i: Option[Integer] = Option(1), l: Option[Long] = Option(2), bool: Option[Boolean] = Option(true), f: Option[Float] = Option(0.1), d: Option[Double] = Option(10.005), datetime: Option[Date] = Option(dateTimeFormatter.parse("2018-01-01T08:30:00Z-04:00")), date: Option[Date] = Option(dateFormatter.parse("2018-01-01")), b: Option[ArrayByte] = Option("c3dhZ2dlciBjb2RlZ2Vu".getBytes), bin: Option[ArrayByte] = Option("DEADBEEF".getBytes)): Option[Hobby] = { |
| 101 | + val await = Try(Await.result(getHobbiesAsync(s, i, l, bool, f, d, datetime, date, b, bin), Duration.Inf)) |
| 102 | + await match { |
| 103 | + case Success(i) => Some(await.get) |
| 104 | + case Failure(t) => None |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Get hobbies asynchronously |
| 110 | + * Query hobbies with some additional optional meaningless parameters |
| 111 | + * |
| 112 | + * @param s a string (optional, default to some string) |
| 113 | + * @param i an integer (optional, default to 1) |
| 114 | + * @param l a long (optional, default to 2) |
| 115 | + * @param bool a bool (optional, default to true) |
| 116 | + * @param f a float (optional, default to 0.1) |
| 117 | + * @param d a double (optional, default to 10.005) |
| 118 | + * @param datetime a date time (optional, default to 2018-01-01T08:30:00Z-04:00) |
| 119 | + * @param date a date (optional, default to 2018-01-01) |
| 120 | + * @param b a base64 encoded string (optional, default to c3dhZ2dlciBjb2RlZ2Vu) |
| 121 | + * @param bin an octet string (optional, default to DEADBEEF) |
| 122 | + * @return Future(Hobby) |
| 123 | + */ |
| 124 | + def getHobbiesAsync(s: Option[String] = Option("some string"), i: Option[Integer] = Option(1), l: Option[Long] = Option(2), bool: Option[Boolean] = Option(true), f: Option[Float] = Option(0.1), d: Option[Double] = Option(10.005), datetime: Option[Date] = Option(dateTimeFormatter.parse("2018-01-01T08:30:00Z-04:00")), date: Option[Date] = Option(dateFormatter.parse("2018-01-01")), b: Option[ArrayByte] = Option("c3dhZ2dlciBjb2RlZ2Vu".getBytes), bin: Option[ArrayByte] = Option("DEADBEEF".getBytes)): Future[Hobby] = { |
| 125 | + helper.getHobbies(s, i, l, bool, f, d, datetime, date, b, bin) |
| 126 | + } |
| 127 | + |
| 128 | +} |
| 129 | + |
| 130 | +class HobbiesApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { |
| 131 | + |
| 132 | + def getHobbies(s: Option[String] = Option("some string"), |
| 133 | + i: Option[Integer] = Option(1), |
| 134 | + l: Option[Long] = Option(2), |
| 135 | + bool: Option[Boolean] = Option(true), |
| 136 | + f: Option[Float] = Option(0.1), |
| 137 | + d: Option[Double] = Option(10.005), |
| 138 | + datetime: Option[Date] = Option(dateTimeFormatter.parse("2018-01-01T08:30:00Z-04:00")), |
| 139 | + date: Option[Date] = Option(dateFormatter.parse("2018-01-01")), |
| 140 | + b: Option[ArrayByte] = Option("c3dhZ2dlciBjb2RlZ2Vu".getBytes), |
| 141 | + bin: Option[ArrayByte] = Option("DEADBEEF".getBytes) |
| 142 | + )(implicit reader: ClientResponseReader[Hobby]): Future[Hobby] = { |
| 143 | + // create path and map variables |
| 144 | + val path = (addFmt("/hobbies")) |
| 145 | + |
| 146 | + // query params |
| 147 | + val queryParams = new mutable.HashMap[String, String] |
| 148 | + val headerParams = new mutable.HashMap[String, String] |
| 149 | + |
| 150 | + s match { |
| 151 | + case Some(param) => queryParams += "s" -> param.toString |
| 152 | + case _ => queryParams |
| 153 | + } |
| 154 | + i match { |
| 155 | + case Some(param) => queryParams += "i" -> param.toString |
| 156 | + case _ => queryParams |
| 157 | + } |
| 158 | + l match { |
| 159 | + case Some(param) => queryParams += "l" -> param.toString |
| 160 | + case _ => queryParams |
| 161 | + } |
| 162 | + bool match { |
| 163 | + case Some(param) => queryParams += "bool" -> param.toString |
| 164 | + case _ => queryParams |
| 165 | + } |
| 166 | + f match { |
| 167 | + case Some(param) => queryParams += "f" -> param.toString |
| 168 | + case _ => queryParams |
| 169 | + } |
| 170 | + d match { |
| 171 | + case Some(param) => queryParams += "d" -> param.toString |
| 172 | + case _ => queryParams |
| 173 | + } |
| 174 | + datetime match { |
| 175 | + case Some(param) => queryParams += "datetime" -> param.toString |
| 176 | + case _ => queryParams |
| 177 | + } |
| 178 | + date match { |
| 179 | + case Some(param) => queryParams += "date" -> param.toString |
| 180 | + case _ => queryParams |
| 181 | + } |
| 182 | + b match { |
| 183 | + case Some(param) => queryParams += "b" -> param.toString |
| 184 | + case _ => queryParams |
| 185 | + } |
| 186 | + bin match { |
| 187 | + case Some(param) => queryParams += "bin" -> param.toString |
| 188 | + case _ => queryParams |
| 189 | + } |
| 190 | + |
| 191 | + val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") |
| 192 | + resFuture flatMap { resp => |
| 193 | + process(reader.read(resp)) |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | + |
| 198 | +} |
0 commit comments