forked from loafle/openapi-generator-original
Fix finch package name. (#4755)
This commit is contained in:
@@ -1,133 +1,133 @@
|
||||
package io.swagger.petstore
|
||||
package io.swagger
|
||||
|
||||
// TODO: properly handle custom imports
|
||||
import java.io._
|
||||
import java.util.Date
|
||||
|
||||
import io.swagger.petstore.models._
|
||||
import io.swagger.models._
|
||||
|
||||
trait DataAccessor {
|
||||
// TODO: apiInfo -> apis -> operations = ???
|
||||
// NOTE: ??? throws a not implemented exception
|
||||
// TODO: apiInfo -> apis -> operations = ???
|
||||
// NOTE: ??? throws a not implemented exception
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Pet_addPet(body: Pet): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Pet_addPet(body: Pet): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Pet_deletePet(petId: Long, apiKey: String): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Pet_deletePet(petId: Long, apiKey: String): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Seq[Pet]
|
||||
*/
|
||||
def Pet_findPetsByStatus(status: Seq[String]): Seq[Pet] = ???
|
||||
/**
|
||||
*
|
||||
* @return A Seq[Pet]
|
||||
*/
|
||||
def Pet_findPetsByStatus(status: Seq[String]): Seq[Pet] = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Seq[Pet]
|
||||
*/
|
||||
def Pet_findPetsByTags(tags: Seq[String]): Seq[Pet] = ???
|
||||
/**
|
||||
*
|
||||
* @return A Seq[Pet]
|
||||
*/
|
||||
def Pet_findPetsByTags(tags: Seq[String]): Seq[Pet] = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Pet
|
||||
*/
|
||||
def Pet_getPetById(petId: Long): Pet = ???
|
||||
/**
|
||||
*
|
||||
* @return A Pet
|
||||
*/
|
||||
def Pet_getPetById(petId: Long): Pet = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Pet_updatePet(body: Pet): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Pet_updatePet(body: Pet): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Pet_updatePetWithForm(petId: Long, name: String, status: String): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Pet_updatePetWithForm(petId: Long, name: String, status: String): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A ApiResponse
|
||||
*/
|
||||
def Pet_uploadFile(petId: Long, additionalMetadata: String, file: File): ApiResponse = ???
|
||||
/**
|
||||
*
|
||||
* @return A ApiResponse
|
||||
*/
|
||||
def Pet_uploadFile(petId: Long, additionalMetadata: String, file: File): ApiResponse = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Store_deleteOrder(orderId: String): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def Store_deleteOrder(orderId: String): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Map[String, Int]
|
||||
*/
|
||||
def Store_getInventory(): Map[String, Int] = ???
|
||||
/**
|
||||
*
|
||||
* @return A Map[String, Int]
|
||||
*/
|
||||
def Store_getInventory(): Map[String, Int] = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Order
|
||||
*/
|
||||
def Store_getOrderById(orderId: Long): Order = ???
|
||||
/**
|
||||
*
|
||||
* @return A Order
|
||||
*/
|
||||
def Store_getOrderById(orderId: Long): Order = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Order
|
||||
*/
|
||||
def Store_placeOrder(body: Order): Order = ???
|
||||
/**
|
||||
*
|
||||
* @return A Order
|
||||
*/
|
||||
def Store_placeOrder(body: Order): Order = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_createUser(body: User): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_createUser(body: User): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_createUsersWithArrayInput(body: Seq[User]): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_createUsersWithArrayInput(body: Seq[User]): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_createUsersWithListInput(body: Seq[User]): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_createUsersWithListInput(body: Seq[User]): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_deleteUser(username: String): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_deleteUser(username: String): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A User
|
||||
*/
|
||||
def User_getUserByName(username: String): User = ???
|
||||
/**
|
||||
*
|
||||
* @return A User
|
||||
*/
|
||||
def User_getUserByName(username: String): User = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A String
|
||||
*/
|
||||
def User_loginUser(username: String, password: String): String = ???
|
||||
/**
|
||||
*
|
||||
* @return A String
|
||||
*/
|
||||
def User_loginUser(username: String, password: String): String = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_logoutUser(): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_logoutUser(): Unit = ???
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_updateUser(username: String, body: User): Unit = ???
|
||||
/**
|
||||
*
|
||||
* @return A Unit
|
||||
*/
|
||||
def User_updateUser(username: String, body: User): Unit = ???
|
||||
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
package io.swagger.petstore
|
||||
package io.swagger
|
||||
|
||||
import io.finch._
|
||||
import io.finch.circe._
|
||||
import io.circe.{ Decoder, ObjectEncoder }
|
||||
import io.circe.{Decoder, ObjectEncoder}
|
||||
import io.circe.generic.auto._
|
||||
import io.circe.generic.semiauto
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import com.twitter.finagle.Http
|
||||
import com.twitter.finagle.util.LoadService
|
||||
import com.twitter.util.{ Await, Future }
|
||||
import com.twitter.util.{Await, Future}
|
||||
|
||||
|
||||
class Server {
|
||||
|
||||
// Loads implementation defined in resources/META-INF/services/io.swagger.petstore.DataAccessor
|
||||
// Loads implementation defined in resources/META-INF/services/io.swagger.DataAccessor
|
||||
val db = LoadService[DataAccessor]() match {
|
||||
case accessor :: _ => accessor
|
||||
case _ => new DataAccessor {}
|
||||
case _ => new DataAccessor { }
|
||||
}
|
||||
|
||||
val service = endpoint.makeService(db)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package io.swagger.petstore
|
||||
package io.swagger
|
||||
|
||||
import com.twitter.finagle.Service
|
||||
import com.twitter.finagle.http.{ Request, Response }
|
||||
import com.twitter.finagle.http.{Request, Response}
|
||||
import com.twitter.finagle.http.exp.Multipart.FileUpload
|
||||
import com.twitter.util.Future
|
||||
import io.finch._, items._
|
||||
import io.circe.{ Encoder, Json }
|
||||
import io.circe.{Encoder, Json}
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
|
||||
import io.swagger.petstore.apis._
|
||||
import io.swagger.apis._
|
||||
|
||||
/**
|
||||
* Provides the paths and endpoints for all the API's public service methods.
|
||||
@@ -17,32 +17,32 @@ import io.swagger.petstore.apis._
|
||||
object endpoint {
|
||||
|
||||
def errorToJson(e: Exception): Json = e match {
|
||||
case Error.NotPresent(_) =>
|
||||
Json.obj("error" -> Json.fromString("something_not_present"))
|
||||
case Error.NotParsed(_, _, _) =>
|
||||
Json.obj("error" -> Json.fromString("something_not_parsed"))
|
||||
case Error.NotValid(_, _) =>
|
||||
Json.obj("error" -> Json.fromString("something_not_valid"))
|
||||
case error: PetstoreError =>
|
||||
Json.obj("error" -> Json.fromString(error.message))
|
||||
case Error.NotPresent(_) =>
|
||||
Json.obj("error" -> Json.fromString("something_not_present"))
|
||||
case Error.NotParsed(_, _, _) =>
|
||||
Json.obj("error" -> Json.fromString("something_not_parsed"))
|
||||
case Error.NotValid(_, _) =>
|
||||
Json.obj("error" -> Json.fromString("something_not_valid"))
|
||||
case error: PetstoreError =>
|
||||
Json.obj("error" -> Json.fromString(error.message))
|
||||
}
|
||||
|
||||
implicit val ee: Encoder[Exception] = Encoder.instance {
|
||||
case e: Error => errorToJson(e)
|
||||
case Errors(nel) => Json.arr(nel.toList.map(errorToJson): _*)
|
||||
case e: Error => errorToJson(e)
|
||||
case Errors(nel) => Json.arr(nel.toList.map(errorToJson): _*)
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles together all the endpoints relating to public service methods.
|
||||
*
|
||||
* @return A service that contains all provided endpoints of the API.
|
||||
*/
|
||||
* Compiles together all the endpoints relating to public service methods.
|
||||
*
|
||||
* @return A service that contains all provided endpoints of the API.
|
||||
*/
|
||||
def makeService(da: DataAccessor): Service[Request, Response] = (
|
||||
PetApi.endpoints(da) :+:
|
||||
StoreApi.endpoints(da) :+:
|
||||
UserApi.endpoints(da)
|
||||
PetApi.endpoints(da) :+:
|
||||
StoreApi.endpoints(da) :+:
|
||||
UserApi.endpoints(da)
|
||||
).handle({
|
||||
case e: PetstoreError => NotFound(e)
|
||||
}).toService
|
||||
}).toService
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.swagger.petstore
|
||||
package io.swagger
|
||||
|
||||
/**
|
||||
* The parent error from which most PetstoreAPI errors extend. Thrown whenever something in the api goes wrong.
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package io.swagger.apis
|
||||
|
||||
import java.io._
|
||||
import java.util.Date
|
||||
import io.swagger._
|
||||
import io.swagger.models._
|
||||
import io.swagger.models.ApiResponse
|
||||
import java.io.File
|
||||
import io.swagger.models.Pet
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import com.twitter.concurrent.AsyncStream
|
||||
import com.twitter.finagle.Service
|
||||
import com.twitter.finagle.Http
|
||||
import com.twitter.finagle.http.{Request, Response}
|
||||
import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload}
|
||||
import com.twitter.util.Future
|
||||
import com.twitter.io.Buf
|
||||
import io.finch._, items._
|
||||
import java.io.File
|
||||
|
||||
object PetApi {
|
||||
/**
|
||||
* Compiles all service endpoints.
|
||||
* @return Bundled compilation of all service endpoints.
|
||||
*/
|
||||
def endpoints(da: DataAccessor) =
|
||||
addPet(da) :+:
|
||||
deletePet(da) :+:
|
||||
findPetsByStatus(da) :+:
|
||||
findPetsByTags(da) :+:
|
||||
getPetById(da) :+:
|
||||
updatePet(da) :+:
|
||||
updatePetWithForm(da) :+:
|
||||
uploadFile(da)
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def addPet(da: DataAccessor): Endpoint[Unit] =
|
||||
post("pet" :: jsonBody[Pet]) { (body: Pet) =>
|
||||
da.Pet_addPet(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def deletePet(da: DataAccessor): Endpoint[Unit] =
|
||||
delete("pet" :: long :: string) { (petId: Long, apiKey: String) =>
|
||||
da.Pet_deletePet(petId, apiKey)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Seq[Pet]
|
||||
*/
|
||||
private def findPetsByStatus(da: DataAccessor): Endpoint[Seq[Pet]] =
|
||||
get("pet" :: "findByStatus" :: params("status")) { (status: Seq[String]) =>
|
||||
Ok(da.Pet_findPetsByStatus(status))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Seq[Pet]
|
||||
*/
|
||||
private def findPetsByTags(da: DataAccessor): Endpoint[Seq[Pet]] =
|
||||
get("pet" :: "findByTags" :: params("tags")) { (tags: Seq[String]) =>
|
||||
Ok(da.Pet_findPetsByTags(tags))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Pet
|
||||
*/
|
||||
private def getPetById(da: DataAccessor): Endpoint[Pet] =
|
||||
get("pet" :: long ) { (petId: Long) =>
|
||||
Ok(da.Pet_getPetById(petId))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def updatePet(da: DataAccessor): Endpoint[Unit] =
|
||||
put("pet" :: jsonBody[Pet]) { (body: Pet) =>
|
||||
da.Pet_updatePet(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def updatePetWithForm(da: DataAccessor): Endpoint[Unit] =
|
||||
post("pet" :: long :: string :: string) { (petId: Long, name: String, status: String) =>
|
||||
da.Pet_updatePetWithForm(petId, name, status)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a ApiResponse
|
||||
*/
|
||||
private def uploadFile(da: DataAccessor): Endpoint[ApiResponse] =
|
||||
post("pet" :: long :: "uploadImage" :: string :: fileUpload("file")) { (petId: Long, additionalMetadata: String, file: FileUpload) =>
|
||||
Ok(da.Pet_uploadFile(petId, additionalMetadata, file))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
|
||||
implicit private def fileUploadToFile(fileUpload: FileUpload) : File = {
|
||||
fileUpload match {
|
||||
case upload: InMemoryFileUpload =>
|
||||
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
|
||||
case upload: OnDiskFileUpload =>
|
||||
upload.content
|
||||
case _ => null
|
||||
}
|
||||
}
|
||||
|
||||
private def bytesToFile(input: Array[Byte]): java.io.File = {
|
||||
val file = File.createTempFile("tmpPetApi", null)
|
||||
val output = new FileOutputStream(file)
|
||||
output.write(input)
|
||||
file
|
||||
}
|
||||
|
||||
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
|
||||
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package io.swagger.apis
|
||||
|
||||
import java.io._
|
||||
import java.util.Date
|
||||
import io.swagger._
|
||||
import io.swagger.models._
|
||||
import io.swagger.models.Order
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import com.twitter.concurrent.AsyncStream
|
||||
import com.twitter.finagle.Service
|
||||
import com.twitter.finagle.Http
|
||||
import com.twitter.finagle.http.{Request, Response}
|
||||
import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload}
|
||||
import com.twitter.util.Future
|
||||
import com.twitter.io.Buf
|
||||
import io.finch._, items._
|
||||
import java.io.File
|
||||
|
||||
object StoreApi {
|
||||
/**
|
||||
* Compiles all service endpoints.
|
||||
* @return Bundled compilation of all service endpoints.
|
||||
*/
|
||||
def endpoints(da: DataAccessor) =
|
||||
deleteOrder(da) :+:
|
||||
getInventory(da) :+:
|
||||
getOrderById(da) :+:
|
||||
placeOrder(da)
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def deleteOrder(da: DataAccessor): Endpoint[Unit] =
|
||||
delete("store" :: "order" :: string ) { (orderId: String) =>
|
||||
da.Store_deleteOrder(orderId)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Map[String, Int]
|
||||
*/
|
||||
private def getInventory(da: DataAccessor): Endpoint[Map[String, Int]] =
|
||||
get("store" :: "inventory" ) {
|
||||
Ok(da.Store_getInventory())
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Order
|
||||
*/
|
||||
private def getOrderById(da: DataAccessor): Endpoint[Order] =
|
||||
get("store" :: "order" :: long ) { (orderId: Long) =>
|
||||
Ok(da.Store_getOrderById(orderId))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Order
|
||||
*/
|
||||
private def placeOrder(da: DataAccessor): Endpoint[Order] =
|
||||
post("store" :: "order" :: jsonBody[Order]) { (body: Order) =>
|
||||
Ok(da.Store_placeOrder(body))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
|
||||
implicit private def fileUploadToFile(fileUpload: FileUpload) : File = {
|
||||
fileUpload match {
|
||||
case upload: InMemoryFileUpload =>
|
||||
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
|
||||
case upload: OnDiskFileUpload =>
|
||||
upload.content
|
||||
case _ => null
|
||||
}
|
||||
}
|
||||
|
||||
private def bytesToFile(input: Array[Byte]): java.io.File = {
|
||||
val file = File.createTempFile("tmpStoreApi", null)
|
||||
val output = new FileOutputStream(file)
|
||||
output.write(input)
|
||||
file
|
||||
}
|
||||
|
||||
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
|
||||
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package io.swagger.apis
|
||||
|
||||
import java.io._
|
||||
import java.util.Date
|
||||
import io.swagger._
|
||||
import io.swagger.models._
|
||||
import scala.collection.immutable.Seq
|
||||
import io.swagger.models.User
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import com.twitter.concurrent.AsyncStream
|
||||
import com.twitter.finagle.Service
|
||||
import com.twitter.finagle.Http
|
||||
import com.twitter.finagle.http.{Request, Response}
|
||||
import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload}
|
||||
import com.twitter.util.Future
|
||||
import com.twitter.io.Buf
|
||||
import io.finch._, items._
|
||||
import java.io.File
|
||||
|
||||
object UserApi {
|
||||
/**
|
||||
* Compiles all service endpoints.
|
||||
* @return Bundled compilation of all service endpoints.
|
||||
*/
|
||||
def endpoints(da: DataAccessor) =
|
||||
createUser(da) :+:
|
||||
createUsersWithArrayInput(da) :+:
|
||||
createUsersWithListInput(da) :+:
|
||||
deleteUser(da) :+:
|
||||
getUserByName(da) :+:
|
||||
loginUser(da) :+:
|
||||
logoutUser(da) :+:
|
||||
updateUser(da)
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def createUser(da: DataAccessor): Endpoint[Unit] =
|
||||
post("user" :: jsonBody[User]) { (body: User) =>
|
||||
da.User_createUser(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def createUsersWithArrayInput(da: DataAccessor): Endpoint[Unit] =
|
||||
post("user" :: "createWithArray" :: jsonBody[Seq[User]]) { (body: Seq[User]) =>
|
||||
da.User_createUsersWithArrayInput(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def createUsersWithListInput(da: DataAccessor): Endpoint[Unit] =
|
||||
post("user" :: "createWithList" :: jsonBody[Seq[User]]) { (body: Seq[User]) =>
|
||||
da.User_createUsersWithListInput(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def deleteUser(da: DataAccessor): Endpoint[Unit] =
|
||||
delete("user" :: string ) { (username: String) =>
|
||||
da.User_deleteUser(username)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a User
|
||||
*/
|
||||
private def getUserByName(da: DataAccessor): Endpoint[User] =
|
||||
get("user" :: string ) { (username: String) =>
|
||||
Ok(da.User_getUserByName(username))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a String
|
||||
*/
|
||||
private def loginUser(da: DataAccessor): Endpoint[String] =
|
||||
get("user" :: "login" :: string :: string) { (username: String, password: String) =>
|
||||
Ok(da.User_loginUser(username, password))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def logoutUser(da: DataAccessor): Endpoint[Unit] =
|
||||
get("user" :: "logout" ) {
|
||||
da.User_logoutUser()
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def updateUser(da: DataAccessor): Endpoint[Unit] =
|
||||
put("user" :: string :: jsonBody[User]) { (username: String, body: User) =>
|
||||
da.User_updateUser(username, body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
|
||||
implicit private def fileUploadToFile(fileUpload: FileUpload) : File = {
|
||||
fileUpload match {
|
||||
case upload: InMemoryFileUpload =>
|
||||
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
|
||||
case upload: OnDiskFileUpload =>
|
||||
upload.content
|
||||
case _ => null
|
||||
}
|
||||
}
|
||||
|
||||
private def bytesToFile(input: Array[Byte]): java.io.File = {
|
||||
val file = File.createTempFile("tmpUserApi", null)
|
||||
val output = new FileOutputStream(file)
|
||||
output.write(input)
|
||||
file
|
||||
}
|
||||
|
||||
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
|
||||
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package io.swagger.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger._
|
||||
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
* @param code
|
||||
* @param _type
|
||||
* @param message
|
||||
*/
|
||||
case class ApiResponse(code: Option[Int],
|
||||
_type: Option[String],
|
||||
message: Option[String]
|
||||
)
|
||||
|
||||
object ApiResponse {
|
||||
/**
|
||||
* Creates the codec for converting ApiResponse from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[ApiResponse] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[ApiResponse] = deriveEncoder
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.swagger.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger._
|
||||
|
||||
/**
|
||||
* A category for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
case class Category(id: Option[Long],
|
||||
name: Option[String]
|
||||
)
|
||||
|
||||
object Category {
|
||||
/**
|
||||
* Creates the codec for converting Category from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[Category] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[Category] = deriveEncoder
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.swagger.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger._
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* An order for a pets from the pet store
|
||||
* @param id
|
||||
* @param petId
|
||||
* @param quantity
|
||||
* @param shipDate
|
||||
* @param status Order Status
|
||||
* @param complete
|
||||
*/
|
||||
case class Order(id: Option[Long],
|
||||
petId: Option[Long],
|
||||
quantity: Option[Int],
|
||||
shipDate: Option[LocalDateTime],
|
||||
status: Option[String],
|
||||
complete: Option[Boolean]
|
||||
)
|
||||
|
||||
object Order {
|
||||
/**
|
||||
* Creates the codec for converting Order from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[Order] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[Order] = deriveEncoder
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.swagger.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger._
|
||||
import io.swagger.models.Category
|
||||
import io.swagger.models.Tag
|
||||
import scala.collection.immutable.Seq
|
||||
|
||||
/**
|
||||
* A pet for sale in the pet store
|
||||
* @param id
|
||||
* @param category
|
||||
* @param name
|
||||
* @param photoUrls
|
||||
* @param tags
|
||||
* @param status pet status in the store
|
||||
*/
|
||||
case class Pet(id: Option[Long],
|
||||
category: Option[Category],
|
||||
name: String,
|
||||
photoUrls: Seq[String],
|
||||
tags: Option[Seq[Tag]],
|
||||
status: Option[String]
|
||||
)
|
||||
|
||||
object Pet {
|
||||
/**
|
||||
* Creates the codec for converting Pet from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[Pet] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[Pet] = deriveEncoder
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.swagger.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger._
|
||||
|
||||
/**
|
||||
* A tag for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
case class Tag(id: Option[Long],
|
||||
name: Option[String]
|
||||
)
|
||||
|
||||
object Tag {
|
||||
/**
|
||||
* Creates the codec for converting Tag from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[Tag] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[Tag] = deriveEncoder
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.swagger.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger._
|
||||
|
||||
/**
|
||||
* A User who is purchasing from the pet store
|
||||
* @param id
|
||||
* @param username
|
||||
* @param firstName
|
||||
* @param lastName
|
||||
* @param email
|
||||
* @param password
|
||||
* @param phone
|
||||
* @param userStatus User Status
|
||||
*/
|
||||
case class User(id: Option[Long],
|
||||
username: Option[String],
|
||||
firstName: Option[String],
|
||||
lastName: Option[String],
|
||||
email: Option[String],
|
||||
password: Option[String],
|
||||
phone: Option[String],
|
||||
userStatus: Option[Int]
|
||||
)
|
||||
|
||||
object User {
|
||||
/**
|
||||
* Creates the codec for converting User from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[User] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[User] = deriveEncoder
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package io.swagger.petstore.apis
|
||||
|
||||
import java.io._
|
||||
import java.util.Date
|
||||
import io.swagger.petstore._
|
||||
import io.swagger.petstore.models._
|
||||
import io.swagger.petstore.models.Pet
|
||||
import java.io.File
|
||||
import io.swagger.petstore.models.ApiResponse
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import com.twitter.concurrent.AsyncStream
|
||||
import com.twitter.finagle.Service
|
||||
import com.twitter.finagle.Http
|
||||
import com.twitter.finagle.http.{ Request, Response }
|
||||
import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload }
|
||||
import com.twitter.util.Future
|
||||
import com.twitter.io.Buf
|
||||
import io.finch._, items._
|
||||
import java.io.File
|
||||
|
||||
object PetApi {
|
||||
/**
|
||||
* Compiles all service endpoints.
|
||||
* @return Bundled compilation of all service endpoints.
|
||||
*/
|
||||
def endpoints(da: DataAccessor) =
|
||||
addPet(da) :+:
|
||||
deletePet(da) :+:
|
||||
findPetsByStatus(da) :+:
|
||||
findPetsByTags(da) :+:
|
||||
getPetById(da) :+:
|
||||
updatePet(da) :+:
|
||||
updatePetWithForm(da) :+:
|
||||
uploadFile(da)
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def addPet(da: DataAccessor): Endpoint[Unit] =
|
||||
post("pet" :: jsonBody[Pet]) { (body: Pet) =>
|
||||
da.Pet_addPet(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def deletePet(da: DataAccessor): Endpoint[Unit] =
|
||||
delete("pet" :: long :: string) { (petId: Long, apiKey: String) =>
|
||||
da.Pet_deletePet(petId, apiKey)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Seq[Pet]
|
||||
*/
|
||||
private def findPetsByStatus(da: DataAccessor): Endpoint[Seq[Pet]] =
|
||||
get("pet" :: "findByStatus" :: params("status")) { (status: Seq[String]) =>
|
||||
Ok(da.Pet_findPetsByStatus(status))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Seq[Pet]
|
||||
*/
|
||||
private def findPetsByTags(da: DataAccessor): Endpoint[Seq[Pet]] =
|
||||
get("pet" :: "findByTags" :: params("tags")) { (tags: Seq[String]) =>
|
||||
Ok(da.Pet_findPetsByTags(tags))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Pet
|
||||
*/
|
||||
private def getPetById(da: DataAccessor): Endpoint[Pet] =
|
||||
get("pet" :: long) { (petId: Long) =>
|
||||
Ok(da.Pet_getPetById(petId))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def updatePet(da: DataAccessor): Endpoint[Unit] =
|
||||
put("pet" :: jsonBody[Pet]) { (body: Pet) =>
|
||||
da.Pet_updatePet(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def updatePetWithForm(da: DataAccessor): Endpoint[Unit] =
|
||||
post("pet" :: long :: string :: string) { (petId: Long, name: String, status: String) =>
|
||||
da.Pet_updatePetWithForm(petId, name, status)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a ApiResponse
|
||||
*/
|
||||
private def uploadFile(da: DataAccessor): Endpoint[ApiResponse] =
|
||||
post("pet" :: long :: "uploadImage" :: string :: fileUpload("file")) { (petId: Long, additionalMetadata: String, file: FileUpload) =>
|
||||
Ok(da.Pet_uploadFile(petId, additionalMetadata, file))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
implicit private def fileUploadToFile(fileUpload: FileUpload): File = {
|
||||
fileUpload match {
|
||||
case upload: InMemoryFileUpload =>
|
||||
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
|
||||
case upload: OnDiskFileUpload =>
|
||||
upload.content
|
||||
case _ => null
|
||||
}
|
||||
}
|
||||
|
||||
private def bytesToFile(input: Array[Byte]): java.io.File = {
|
||||
val file = File.createTempFile("tmpPetApi", null)
|
||||
val output = new FileOutputStream(file)
|
||||
output.write(input)
|
||||
file
|
||||
}
|
||||
|
||||
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
|
||||
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package io.swagger.petstore.apis
|
||||
|
||||
import java.io._
|
||||
import java.util.Date
|
||||
import io.swagger.petstore._
|
||||
import io.swagger.petstore.models._
|
||||
import io.swagger.petstore.models.Order
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import com.twitter.concurrent.AsyncStream
|
||||
import com.twitter.finagle.Service
|
||||
import com.twitter.finagle.Http
|
||||
import com.twitter.finagle.http.{ Request, Response }
|
||||
import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload }
|
||||
import com.twitter.util.Future
|
||||
import com.twitter.io.Buf
|
||||
import io.finch._, items._
|
||||
import java.io.File
|
||||
|
||||
object StoreApi {
|
||||
/**
|
||||
* Compiles all service endpoints.
|
||||
* @return Bundled compilation of all service endpoints.
|
||||
*/
|
||||
def endpoints(da: DataAccessor) =
|
||||
deleteOrder(da) :+:
|
||||
getInventory(da) :+:
|
||||
getOrderById(da) :+:
|
||||
placeOrder(da)
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def deleteOrder(da: DataAccessor): Endpoint[Unit] =
|
||||
delete("store" :: "order" :: string) { (orderId: String) =>
|
||||
da.Store_deleteOrder(orderId)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Map[String, Int]
|
||||
*/
|
||||
private def getInventory(da: DataAccessor): Endpoint[Map[String, Int]] =
|
||||
get("store" :: "inventory") {
|
||||
Ok(da.Store_getInventory())
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Order
|
||||
*/
|
||||
private def getOrderById(da: DataAccessor): Endpoint[Order] =
|
||||
get("store" :: "order" :: long) { (orderId: Long) =>
|
||||
Ok(da.Store_getOrderById(orderId))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Order
|
||||
*/
|
||||
private def placeOrder(da: DataAccessor): Endpoint[Order] =
|
||||
post("store" :: "order" :: jsonBody[Order]) { (body: Order) =>
|
||||
Ok(da.Store_placeOrder(body))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
implicit private def fileUploadToFile(fileUpload: FileUpload): File = {
|
||||
fileUpload match {
|
||||
case upload: InMemoryFileUpload =>
|
||||
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
|
||||
case upload: OnDiskFileUpload =>
|
||||
upload.content
|
||||
case _ => null
|
||||
}
|
||||
}
|
||||
|
||||
private def bytesToFile(input: Array[Byte]): java.io.File = {
|
||||
val file = File.createTempFile("tmpStoreApi", null)
|
||||
val output = new FileOutputStream(file)
|
||||
output.write(input)
|
||||
file
|
||||
}
|
||||
|
||||
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
|
||||
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
package io.swagger.petstore.apis
|
||||
|
||||
import java.io._
|
||||
import java.util.Date
|
||||
import io.swagger.petstore._
|
||||
import io.swagger.petstore.models._
|
||||
import io.swagger.petstore.models.User
|
||||
import scala.collection.immutable.Seq
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import com.twitter.concurrent.AsyncStream
|
||||
import com.twitter.finagle.Service
|
||||
import com.twitter.finagle.Http
|
||||
import com.twitter.finagle.http.{ Request, Response }
|
||||
import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload }
|
||||
import com.twitter.util.Future
|
||||
import com.twitter.io.Buf
|
||||
import io.finch._, items._
|
||||
import java.io.File
|
||||
|
||||
object UserApi {
|
||||
/**
|
||||
* Compiles all service endpoints.
|
||||
* @return Bundled compilation of all service endpoints.
|
||||
*/
|
||||
def endpoints(da: DataAccessor) =
|
||||
createUser(da) :+:
|
||||
createUsersWithArrayInput(da) :+:
|
||||
createUsersWithListInput(da) :+:
|
||||
deleteUser(da) :+:
|
||||
getUserByName(da) :+:
|
||||
loginUser(da) :+:
|
||||
logoutUser(da) :+:
|
||||
updateUser(da)
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def createUser(da: DataAccessor): Endpoint[Unit] =
|
||||
post("user" :: jsonBody[User]) { (body: User) =>
|
||||
da.User_createUser(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def createUsersWithArrayInput(da: DataAccessor): Endpoint[Unit] =
|
||||
post("user" :: "createWithArray" :: jsonBody[Seq[User]]) { (body: Seq[User]) =>
|
||||
da.User_createUsersWithArrayInput(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def createUsersWithListInput(da: DataAccessor): Endpoint[Unit] =
|
||||
post("user" :: "createWithList" :: jsonBody[Seq[User]]) { (body: Seq[User]) =>
|
||||
da.User_createUsersWithListInput(body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def deleteUser(da: DataAccessor): Endpoint[Unit] =
|
||||
delete("user" :: string) { (username: String) =>
|
||||
da.User_deleteUser(username)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a User
|
||||
*/
|
||||
private def getUserByName(da: DataAccessor): Endpoint[User] =
|
||||
get("user" :: string) { (username: String) =>
|
||||
Ok(da.User_getUserByName(username))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a String
|
||||
*/
|
||||
private def loginUser(da: DataAccessor): Endpoint[String] =
|
||||
get("user" :: "login" :: string :: string) { (username: String, password: String) =>
|
||||
Ok(da.User_loginUser(username, password))
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def logoutUser(da: DataAccessor): Endpoint[Unit] =
|
||||
get("user" :: "logout") {
|
||||
da.User_logoutUser()
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return And endpoint representing a Unit
|
||||
*/
|
||||
private def updateUser(da: DataAccessor): Endpoint[Unit] =
|
||||
put("user" :: string :: jsonBody[User]) { (username: String, body: User) =>
|
||||
da.User_updateUser(username, body)
|
||||
NoContent[Unit]
|
||||
} handle {
|
||||
case e: Exception => BadRequest(e)
|
||||
}
|
||||
|
||||
implicit private def fileUploadToFile(fileUpload: FileUpload): File = {
|
||||
fileUpload match {
|
||||
case upload: InMemoryFileUpload =>
|
||||
bytesToFile(Buf.ByteArray.Owned.extract(upload.content))
|
||||
case upload: OnDiskFileUpload =>
|
||||
upload.content
|
||||
case _ => null
|
||||
}
|
||||
}
|
||||
|
||||
private def bytesToFile(input: Array[Byte]): java.io.File = {
|
||||
val file = File.createTempFile("tmpUserApi", null)
|
||||
val output = new FileOutputStream(file)
|
||||
output.write(input)
|
||||
file
|
||||
}
|
||||
|
||||
// This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere.
|
||||
implicit def seqList[A](input: Seq[A]): List[A] = input.toList
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package io.swagger.petstore.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger.petstore._
|
||||
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
* @param code
|
||||
* @param _type
|
||||
* @param message
|
||||
*/
|
||||
case class ApiResponse(
|
||||
code: Option[Int],
|
||||
_type: Option[String],
|
||||
message: Option[String]
|
||||
)
|
||||
|
||||
object ApiResponse {
|
||||
/**
|
||||
* Creates the codec for converting ApiResponse from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[ApiResponse] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[ApiResponse] = deriveEncoder
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.swagger.petstore.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger.petstore._
|
||||
|
||||
/**
|
||||
* A category for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
case class Category(
|
||||
id: Option[Long],
|
||||
name: Option[String]
|
||||
)
|
||||
|
||||
object Category {
|
||||
/**
|
||||
* Creates the codec for converting Category from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[Category] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[Category] = deriveEncoder
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package io.swagger.petstore.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger.petstore._
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* An order for a pets from the pet store
|
||||
* @param id
|
||||
* @param petId
|
||||
* @param quantity
|
||||
* @param shipDate
|
||||
* @param status Order Status
|
||||
* @param complete
|
||||
*/
|
||||
case class Order(
|
||||
id: Option[Long],
|
||||
petId: Option[Long],
|
||||
quantity: Option[Int],
|
||||
shipDate: Option[LocalDateTime],
|
||||
status: Option[String],
|
||||
complete: Option[Boolean]
|
||||
)
|
||||
|
||||
object Order {
|
||||
/**
|
||||
* Creates the codec for converting Order from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[Order] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[Order] = deriveEncoder
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package io.swagger.petstore.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger.petstore._
|
||||
import io.swagger.petstore.models.Category
|
||||
import io.swagger.petstore.models.Tag
|
||||
import scala.collection.immutable.Seq
|
||||
|
||||
/**
|
||||
* A pet for sale in the pet store
|
||||
* @param id
|
||||
* @param category
|
||||
* @param name
|
||||
* @param photoUrls
|
||||
* @param tags
|
||||
* @param status pet status in the store
|
||||
*/
|
||||
case class Pet(
|
||||
id: Option[Long],
|
||||
category: Option[Category],
|
||||
name: String,
|
||||
photoUrls: Seq[String],
|
||||
tags: Option[Seq[Tag]],
|
||||
status: Option[String]
|
||||
)
|
||||
|
||||
object Pet {
|
||||
/**
|
||||
* Creates the codec for converting Pet from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[Pet] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[Pet] = deriveEncoder
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.swagger.petstore.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger.petstore._
|
||||
|
||||
/**
|
||||
* A tag for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
case class Tag(
|
||||
id: Option[Long],
|
||||
name: Option[String]
|
||||
)
|
||||
|
||||
object Tag {
|
||||
/**
|
||||
* Creates the codec for converting Tag from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[Tag] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[Tag] = deriveEncoder
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package io.swagger.petstore.models
|
||||
|
||||
import io.circe._
|
||||
import io.finch.circe._
|
||||
import io.circe.generic.semiauto._
|
||||
import io.circe.java8.time._
|
||||
import io.swagger.petstore._
|
||||
|
||||
/**
|
||||
* A User who is purchasing from the pet store
|
||||
* @param id
|
||||
* @param username
|
||||
* @param firstName
|
||||
* @param lastName
|
||||
* @param email
|
||||
* @param password
|
||||
* @param phone
|
||||
* @param userStatus User Status
|
||||
*/
|
||||
case class User(
|
||||
id: Option[Long],
|
||||
username: Option[String],
|
||||
firstName: Option[String],
|
||||
lastName: Option[String],
|
||||
email: Option[String],
|
||||
password: Option[String],
|
||||
phone: Option[String],
|
||||
userStatus: Option[Int]
|
||||
)
|
||||
|
||||
object User {
|
||||
/**
|
||||
* Creates the codec for converting User from and to JSON.
|
||||
*/
|
||||
implicit val decoder: Decoder[User] = deriveDecoder
|
||||
implicit val encoder: ObjectEncoder[User] = deriveEncoder
|
||||
}
|
||||
Reference in New Issue
Block a user