/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/nicolai-moraru/joglog-api/0.0.1-dev/play_2_x_scala_3_json */ package nm.joglog.api.v0.models { /** * Time entry * * @param id Unique time id * @param distance Distance in meters * @param time Time in seconds * @param createdAt Creation date-time * @param updatedAt Last update date-time */ final case class Time( id: Int, distance: Int, time: Int, createdAt: _root_.org.joda.time.DateTime, updatedAt: _root_.org.joda.time.DateTime ) /** * Time entry * * @param distance Distance in meters * @param time Time in seconds */ final case class TimeMinimal( distance: Int, time: Int ) /** * Time patch entry */ final case class TimePatchEntry( op: .models.Operation, path: time.models.Path, value: Int ) /** * User * * @param id Unique user id * @param username Username * @param role User Role * @param createdAt Creation date-time * @param updatedAt Last update date-time */ final case class User( id: Int, username: String, role: .models.Role, createdAt: _root_.org.joda.time.DateTime, updatedAt: _root_.org.joda.time.DateTime ) /** * User * * @param username Username * @param password Password */ final case class UserMinimal( username: String, password: String ) /** * User patch entry */ final case class UserPatchEntry( op: .models.Operation, path: user.models.Path, value: nm.joglog.api.v0.models.StringOrInteger ) /** * Patch operation */ sealed trait PatchOperation extends _root_.scala.Product with _root_.scala.Serializable object PatchOperation { case object Test extends PatchOperation { override def toString = "test" } case object Replace extends PatchOperation { override def toString = "replace" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends PatchOperation /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[PatchOperation] = scala.List(Test, Replace) private val byName: Map[String, PatchOperation] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): PatchOperation = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[PatchOperation] = byName.get(value.toLowerCase) } /** * Integer for ID or string for any other */ sealed trait StringOrInteger extends _root_.scala.Product with _root_.scala.Serializable object StringOrInteger { case object String extends StringOrInteger { override def toString = "string" } case object Integer extends StringOrInteger { override def toString = "integer" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends StringOrInteger /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[StringOrInteger] = scala.List(String, Integer) private val byName: Map[String, StringOrInteger] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): StringOrInteger = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[StringOrInteger] = byName.get(value.toLowerCase) } /** * Time patch field path (id only for test) */ sealed trait TimePatchPath extends _root_.scala.Product with _root_.scala.Serializable object TimePatchPath { case object Distance extends TimePatchPath { override def toString = "distance" } case object Time extends TimePatchPath { override def toString = "time" } case object Id extends TimePatchPath { override def toString = "id" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends TimePatchPath /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[TimePatchPath] = scala.List(Distance, Time, Id) private val byName: Map[String, TimePatchPath] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): TimePatchPath = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[TimePatchPath] = byName.get(value.toLowerCase) } /** * User patch field path (id only for test) */ sealed trait UserPatchPath extends _root_.scala.Product with _root_.scala.Serializable object UserPatchPath { case object Username extends UserPatchPath { override def toString = "username" } case object Password extends UserPatchPath { override def toString = "password" } case object Role extends UserPatchPath { override def toString = "role" } case object Id extends UserPatchPath { override def toString = "id" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends UserPatchPath /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[UserPatchPath] = scala.List(Username, Password, Role, Id) private val byName: Map[String, UserPatchPath] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): UserPatchPath = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[UserPatchPath] = byName.get(value.toLowerCase) } /** * User Role */ sealed trait UserRole extends _root_.scala.Product with _root_.scala.Serializable object UserRole { /** * Regular user */ case object User extends UserRole { override def toString = "user" } /** * User manager */ case object Manager extends UserRole { override def toString = "manager" } /** * The God himself */ case object Admin extends UserRole { override def toString = "admin" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends UserRole /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[UserRole] = scala.List(User, Manager, Admin) private val byName: Map[String, UserRole] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): UserRole = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[UserRole] = byName.get(value.toLowerCase) } } package nm.joglog.api.v0.models { package object json { import play.api.libs.json.__ import play.api.libs.json.JsString import play.api.libs.json.Writes import play.api.libs.functional.syntax._ import nm.joglog.api.v0.models.json._ private[v0] implicit val jsonReadsUUID: play.api.libs.json.Reads[_root_.java.util.UUID] = __.read[String].map { str => _root_.java.util.UUID.fromString(str) } private[v0] implicit val jsonWritesUUID: play.api.libs.json.Writes[_root_.java.util.UUID] = (x: _root_.java.util.UUID) => play.api.libs.json.JsString(x.toString) private[v0] implicit val jsonReadsJodaDateTime: play.api.libs.json.Reads[_root_.org.joda.time.DateTime] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseDateTime(str) } private[v0] implicit val jsonWritesJodaDateTime: play.api.libs.json.Writes[_root_.org.joda.time.DateTime] = (x: _root_.org.joda.time.DateTime) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(x)) } private[v0] implicit val jsonReadsJodaLocalDate: play.api.libs.json.Reads[_root_.org.joda.time.LocalDate] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseLocalDate(str) } private[v0] implicit val jsonWritesJodaLocalDate: play.api.libs.json.Writes[_root_.org.joda.time.LocalDate] = (x: _root_.org.joda.time.LocalDate) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.date.print(x)) } implicit val jsonReadsJoglogApiPatchOperation: play.api.libs.json.Reads[nm.joglog.api.v0.models.PatchOperation] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.PatchOperation] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.PatchOperation] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.PatchOperation(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.PatchOperation(v)) case _: play.api.libs.json.JsError => (js \ "patch.operation").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.PatchOperation(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiPatchOperation(obj: nm.joglog.api.v0.models.PatchOperation) = { play.api.libs.json.JsString(obj.toString) } def jsObjectPatchOperation(obj: nm.joglog.api.v0.models.PatchOperation) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiPatchOperation: play.api.libs.json.Writes[PatchOperation] = { (obj: nm.joglog.api.v0.models.PatchOperation) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiPatchOperation(obj) } } implicit val jsonReadsJoglogApiStringOrInteger: play.api.libs.json.Reads[nm.joglog.api.v0.models.StringOrInteger] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.StringOrInteger] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.StringOrInteger] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.StringOrInteger(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.StringOrInteger(v)) case _: play.api.libs.json.JsError => (js \ "stringOrInteger").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.StringOrInteger(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiStringOrInteger(obj: nm.joglog.api.v0.models.StringOrInteger) = { play.api.libs.json.JsString(obj.toString) } def jsObjectStringOrInteger(obj: nm.joglog.api.v0.models.StringOrInteger) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiStringOrInteger: play.api.libs.json.Writes[StringOrInteger] = { (obj: nm.joglog.api.v0.models.StringOrInteger) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiStringOrInteger(obj) } } implicit val jsonReadsJoglogApiTimePatchPath: play.api.libs.json.Reads[nm.joglog.api.v0.models.TimePatchPath] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.TimePatchPath] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.TimePatchPath] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.TimePatchPath(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.TimePatchPath(v)) case _: play.api.libs.json.JsError => (js \ "time.patch.path").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.TimePatchPath(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiTimePatchPath(obj: nm.joglog.api.v0.models.TimePatchPath) = { play.api.libs.json.JsString(obj.toString) } def jsObjectTimePatchPath(obj: nm.joglog.api.v0.models.TimePatchPath) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiTimePatchPath: play.api.libs.json.Writes[TimePatchPath] = { (obj: nm.joglog.api.v0.models.TimePatchPath) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiTimePatchPath(obj) } } implicit val jsonReadsJoglogApiUserPatchPath: play.api.libs.json.Reads[nm.joglog.api.v0.models.UserPatchPath] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.UserPatchPath] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.UserPatchPath] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserPatchPath(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserPatchPath(v)) case _: play.api.libs.json.JsError => (js \ "user.patch.path").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserPatchPath(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiUserPatchPath(obj: nm.joglog.api.v0.models.UserPatchPath) = { play.api.libs.json.JsString(obj.toString) } def jsObjectUserPatchPath(obj: nm.joglog.api.v0.models.UserPatchPath) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiUserPatchPath: play.api.libs.json.Writes[UserPatchPath] = { (obj: nm.joglog.api.v0.models.UserPatchPath) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiUserPatchPath(obj) } } implicit val jsonReadsJoglogApiUserRole: play.api.libs.json.Reads[nm.joglog.api.v0.models.UserRole] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.UserRole] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.UserRole] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserRole(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserRole(v)) case _: play.api.libs.json.JsError => (js \ "user.role").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserRole(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiUserRole(obj: nm.joglog.api.v0.models.UserRole) = { play.api.libs.json.JsString(obj.toString) } def jsObjectUserRole(obj: nm.joglog.api.v0.models.UserRole) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiUserRole: play.api.libs.json.Writes[UserRole] = { (obj: nm.joglog.api.v0.models.UserRole) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiUserRole(obj) } } implicit def jsonReadsJoglogApiTime: play.api.libs.json.Reads[nm.joglog.api.v0.models.Time] = { for { id <- (__ \ "id").read[Int] distance <- (__ \ "distance").read[Int] time <- (__ \ "time").read[Int] createdAt <- (__ \ "createdAt").read[_root_.org.joda.time.DateTime] updatedAt <- (__ \ "updatedAt").read[_root_.org.joda.time.DateTime] } yield Time(id, distance, time, createdAt, updatedAt) } def jsObjectTime(obj: nm.joglog.api.v0.models.Time): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "id" -> play.api.libs.json.JsNumber(obj.id), "distance" -> play.api.libs.json.JsNumber(obj.distance), "time" -> play.api.libs.json.JsNumber(obj.time), "createdAt" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.createdAt)), "updatedAt" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.updatedAt)) ) } implicit def jsonWritesJoglogApiTime: play.api.libs.json.Writes[Time] = { (obj: nm.joglog.api.v0.models.Time) => { nm.joglog.api.v0.models.json.jsObjectTime(obj) } } implicit def jsonReadsJoglogApiTimeMinimal: play.api.libs.json.Reads[nm.joglog.api.v0.models.TimeMinimal] = { for { distance <- (__ \ "distance").read[Int] time <- (__ \ "time").read[Int] } yield TimeMinimal(distance, time) } def jsObjectTimeMinimal(obj: nm.joglog.api.v0.models.TimeMinimal): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "distance" -> play.api.libs.json.JsNumber(obj.distance), "time" -> play.api.libs.json.JsNumber(obj.time) ) } implicit def jsonWritesJoglogApiTimeMinimal: play.api.libs.json.Writes[TimeMinimal] = { (obj: nm.joglog.api.v0.models.TimeMinimal) => { nm.joglog.api.v0.models.json.jsObjectTimeMinimal(obj) } } implicit def jsonReadsJoglogApiTimePatchEntry: play.api.libs.json.Reads[nm.joglog.api.v0.models.TimePatchEntry] = { for { op <- (__ \ "op").read[.models.Operation] path <- (__ \ "path").read[time.models.Path] value <- (__ \ "value").read[Int] } yield TimePatchEntry(op, path, value) } def jsObjectTimePatchEntry(obj: nm.joglog.api.v0.models.TimePatchEntry): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "op" -> play.api.libs.json.JsString(obj.op.toString), "path" -> play.api.libs.json.JsString(obj.path.toString), "value" -> play.api.libs.json.JsNumber(obj.value) ) } implicit def jsonWritesJoglogApiTimePatchEntry: play.api.libs.json.Writes[TimePatchEntry] = { (obj: nm.joglog.api.v0.models.TimePatchEntry) => { nm.joglog.api.v0.models.json.jsObjectTimePatchEntry(obj) } } implicit def jsonReadsJoglogApiUser: play.api.libs.json.Reads[nm.joglog.api.v0.models.User] = { for { id <- (__ \ "id").read[Int] username <- (__ \ "username").read[String] role <- (__ \ "role").read[.models.Role] createdAt <- (__ \ "createdAt").read[_root_.org.joda.time.DateTime] updatedAt <- (__ \ "updatedAt").read[_root_.org.joda.time.DateTime] } yield User(id, username, role, createdAt, updatedAt) } def jsObjectUser(obj: nm.joglog.api.v0.models.User): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "id" -> play.api.libs.json.JsNumber(obj.id), "username" -> play.api.libs.json.JsString(obj.username), "role" -> play.api.libs.json.JsString(obj.role.toString), "createdAt" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.createdAt)), "updatedAt" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.updatedAt)) ) } implicit def jsonWritesJoglogApiUser: play.api.libs.json.Writes[User] = { (obj: nm.joglog.api.v0.models.User) => { nm.joglog.api.v0.models.json.jsObjectUser(obj) } } implicit def jsonReadsJoglogApiUserMinimal: play.api.libs.json.Reads[nm.joglog.api.v0.models.UserMinimal] = { for { username <- (__ \ "username").read[String] password <- (__ \ "password").read[String] } yield UserMinimal(username, password) } def jsObjectUserMinimal(obj: nm.joglog.api.v0.models.UserMinimal): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "username" -> play.api.libs.json.JsString(obj.username), "password" -> play.api.libs.json.JsString(obj.password) ) } implicit def jsonWritesJoglogApiUserMinimal: play.api.libs.json.Writes[UserMinimal] = { (obj: nm.joglog.api.v0.models.UserMinimal) => { nm.joglog.api.v0.models.json.jsObjectUserMinimal(obj) } } implicit def jsonReadsJoglogApiUserPatchEntry: play.api.libs.json.Reads[nm.joglog.api.v0.models.UserPatchEntry] = { for { op <- (__ \ "op").read[.models.Operation] path <- (__ \ "path").read[user.models.Path] value <- (__ \ "value").read[nm.joglog.api.v0.models.StringOrInteger] } yield UserPatchEntry(op, path, value) } def jsObjectUserPatchEntry(obj: nm.joglog.api.v0.models.UserPatchEntry): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "op" -> play.api.libs.json.JsString(obj.op.toString), "path" -> play.api.libs.json.JsString(obj.path.toString), "value" -> play.api.libs.json.JsString(obj.value.toString) ) } implicit def jsonWritesJoglogApiUserPatchEntry: play.api.libs.json.Writes[UserPatchEntry] = { (obj: nm.joglog.api.v0.models.UserPatchEntry) => { nm.joglog.api.v0.models.json.jsObjectUserPatchEntry(obj) } } } } package nm.joglog.api.v0 { object Bindables { import play.api.mvc.{PathBindable, QueryStringBindable} // import models directly for backwards compatibility with prior versions of the generator import Core._ import Models._ object Core { implicit def pathBindableDateTimeIso8601(implicit stringBinder: QueryStringBindable[String]): PathBindable[_root_.org.joda.time.DateTime] = ApibuilderPathBindable(ApibuilderTypes.dateTimeIso8601) implicit def queryStringBindableDateTimeIso8601(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[_root_.org.joda.time.DateTime] = ApibuilderQueryStringBindable(ApibuilderTypes.dateTimeIso8601) implicit def pathBindableDateIso8601(implicit stringBinder: QueryStringBindable[String]): PathBindable[_root_.org.joda.time.LocalDate] = ApibuilderPathBindable(ApibuilderTypes.dateIso8601) implicit def queryStringBindableDateIso8601(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[_root_.org.joda.time.LocalDate] = ApibuilderQueryStringBindable(ApibuilderTypes.dateIso8601) } object Models { import nm.joglog.api.v0.models._ val patchOperationConverter: ApibuilderTypeConverter[nm.joglog.api.v0.models.PatchOperation] = new ApibuilderTypeConverter[nm.joglog.api.v0.models.PatchOperation] { override def convert(value: String): nm.joglog.api.v0.models.PatchOperation = nm.joglog.api.v0.models.PatchOperation(value) override def convert(value: nm.joglog.api.v0.models.PatchOperation): String = value.toString override def example: nm.joglog.api.v0.models.PatchOperation = nm.joglog.api.v0.models.PatchOperation.Test override def validValues: Seq[nm.joglog.api.v0.models.PatchOperation] = nm.joglog.api.v0.models.PatchOperation.all } implicit def pathBindablePatchOperation(implicit stringBinder: QueryStringBindable[String]): PathBindable[nm.joglog.api.v0.models.PatchOperation] = ApibuilderPathBindable(patchOperationConverter) implicit def queryStringBindablePatchOperation(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[nm.joglog.api.v0.models.PatchOperation] = ApibuilderQueryStringBindable(patchOperationConverter) val stringOrIntegerConverter: ApibuilderTypeConverter[nm.joglog.api.v0.models.StringOrInteger] = new ApibuilderTypeConverter[nm.joglog.api.v0.models.StringOrInteger] { override def convert(value: String): nm.joglog.api.v0.models.StringOrInteger = nm.joglog.api.v0.models.StringOrInteger(value) override def convert(value: nm.joglog.api.v0.models.StringOrInteger): String = value.toString override def example: nm.joglog.api.v0.models.StringOrInteger = nm.joglog.api.v0.models.StringOrInteger.String override def validValues: Seq[nm.joglog.api.v0.models.StringOrInteger] = nm.joglog.api.v0.models.StringOrInteger.all } implicit def pathBindableStringOrInteger(implicit stringBinder: QueryStringBindable[String]): PathBindable[nm.joglog.api.v0.models.StringOrInteger] = ApibuilderPathBindable(stringOrIntegerConverter) implicit def queryStringBindableStringOrInteger(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[nm.joglog.api.v0.models.StringOrInteger] = ApibuilderQueryStringBindable(stringOrIntegerConverter) val timePatchPathConverter: ApibuilderTypeConverter[nm.joglog.api.v0.models.TimePatchPath] = new ApibuilderTypeConverter[nm.joglog.api.v0.models.TimePatchPath] { override def convert(value: String): nm.joglog.api.v0.models.TimePatchPath = nm.joglog.api.v0.models.TimePatchPath(value) override def convert(value: nm.joglog.api.v0.models.TimePatchPath): String = value.toString override def example: nm.joglog.api.v0.models.TimePatchPath = nm.joglog.api.v0.models.TimePatchPath.Distance override def validValues: Seq[nm.joglog.api.v0.models.TimePatchPath] = nm.joglog.api.v0.models.TimePatchPath.all } implicit def pathBindableTimePatchPath(implicit stringBinder: QueryStringBindable[String]): PathBindable[nm.joglog.api.v0.models.TimePatchPath] = ApibuilderPathBindable(timePatchPathConverter) implicit def queryStringBindableTimePatchPath(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[nm.joglog.api.v0.models.TimePatchPath] = ApibuilderQueryStringBindable(timePatchPathConverter) val userPatchPathConverter: ApibuilderTypeConverter[nm.joglog.api.v0.models.UserPatchPath] = new ApibuilderTypeConverter[nm.joglog.api.v0.models.UserPatchPath] { override def convert(value: String): nm.joglog.api.v0.models.UserPatchPath = nm.joglog.api.v0.models.UserPatchPath(value) override def convert(value: nm.joglog.api.v0.models.UserPatchPath): String = value.toString override def example: nm.joglog.api.v0.models.UserPatchPath = nm.joglog.api.v0.models.UserPatchPath.Username override def validValues: Seq[nm.joglog.api.v0.models.UserPatchPath] = nm.joglog.api.v0.models.UserPatchPath.all } implicit def pathBindableUserPatchPath(implicit stringBinder: QueryStringBindable[String]): PathBindable[nm.joglog.api.v0.models.UserPatchPath] = ApibuilderPathBindable(userPatchPathConverter) implicit def queryStringBindableUserPatchPath(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[nm.joglog.api.v0.models.UserPatchPath] = ApibuilderQueryStringBindable(userPatchPathConverter) val userRoleConverter: ApibuilderTypeConverter[nm.joglog.api.v0.models.UserRole] = new ApibuilderTypeConverter[nm.joglog.api.v0.models.UserRole] { override def convert(value: String): nm.joglog.api.v0.models.UserRole = nm.joglog.api.v0.models.UserRole(value) override def convert(value: nm.joglog.api.v0.models.UserRole): String = value.toString override def example: nm.joglog.api.v0.models.UserRole = nm.joglog.api.v0.models.UserRole.User override def validValues: Seq[nm.joglog.api.v0.models.UserRole] = nm.joglog.api.v0.models.UserRole.all } implicit def pathBindableUserRole(implicit stringBinder: QueryStringBindable[String]): PathBindable[nm.joglog.api.v0.models.UserRole] = ApibuilderPathBindable(userRoleConverter) implicit def queryStringBindableUserRole(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[nm.joglog.api.v0.models.UserRole] = ApibuilderQueryStringBindable(userRoleConverter) } trait ApibuilderTypeConverter[T] { def convert(value: String): T def convert(value: T): String def example: T def validValues: Seq[T] = Nil def errorMessage(key: String, value: String, ex: java.lang.Exception): String = { val base = s"Invalid value '$value' for parameter '$key'. " validValues.toList match { case Nil => base + "Ex: " + convert(example) case values => base + ". Valid values are: " + values.mkString("'", "', '", "'") } } } object ApibuilderTypes { val dateTimeIso8601: ApibuilderTypeConverter[_root_.org.joda.time.DateTime] = new ApibuilderTypeConverter[_root_.org.joda.time.DateTime] { override def convert(value: String): _root_.org.joda.time.DateTime = _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseDateTime(value) override def convert(value: _root_.org.joda.time.DateTime): String = _root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(value) override def example: _root_.org.joda.time.DateTime = _root_.org.joda.time.DateTime.now } val dateIso8601: ApibuilderTypeConverter[_root_.org.joda.time.LocalDate] = new ApibuilderTypeConverter[_root_.org.joda.time.LocalDate] { override def convert(value: String): _root_.org.joda.time.LocalDate = _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseLocalDate(value) override def convert(value: _root_.org.joda.time.LocalDate): String = _root_.org.joda.time.format.ISODateTimeFormat.date.print(value) override def example: _root_.org.joda.time.LocalDate = _root_.org.joda.time.LocalDate.now } } final case class ApibuilderQueryStringBindable[T]( converters: ApibuilderTypeConverter[T] ) extends QueryStringBindable[T] { override def bind(key: String, params: Map[String, Seq[String]]): _root_.scala.Option[_root_.scala.Either[String, T]] = { params.getOrElse(key, Nil).headOption.map { v => try { Right( converters.convert(v) ) } catch { case ex: java.lang.Exception => Left( converters.errorMessage(key, v, ex) ) } } } override def unbind(key: String, value: T): String = { s"$key=${converters.convert(value)}" } } final case class ApibuilderPathBindable[T]( converters: ApibuilderTypeConverter[T] ) extends PathBindable[T] { override def bind(key: String, value: String): _root_.scala.Either[String, T] = { try { Right( converters.convert(value) ) } catch { case ex: java.lang.Exception => Left( converters.errorMessage(key, value, ex) ) } } override def unbind(key: String, value: T): String = { converters.convert(value) } } } }