/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/michal/playground-api/0.0.1-dev/play_2_x_scala_3_standalone_json */ package io.github.mkows.playground.api.v0.models { sealed trait ItemState extends _root_.scala.Product with _root_.scala.Serializable { def itemStateType: ItemStateType } /** * Defines the valid type values for the type ItemState */ sealed trait ItemStateType extends _root_.scala.Product with _root_.scala.Serializable object ItemStateType { case object ItemStateProgress extends ItemStateType { override def toString = "item_state_progress" } case object ItemStateFailedCause extends ItemStateType { override def toString = "item_state_failed_cause" } final case class UNDEFINED(override val toString: String) extends ItemStateType val all: scala.List[ItemStateType] = scala.List(ItemStateProgress, ItemStateFailedCause) private val byName: Map[String, ItemStateType] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): ItemStateType = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[ItemStateType] = byName.get(value.toLowerCase) } final case class Error( code: Int, message: String, details: _root_.scala.Option[String] = None ) final case class Healthcheck( status: String, createdAt: _root_.org.joda.time.DateTime ) /** * Provides future compatibility in clients - in the future, when a type is added * to the union ItemState, it will need to be handled in the client code. This * implementation will deserialize these future types as an instance of this class. * * @param description Information about the type that we received that is undefined in this version of * the client. */ final case class ItemStateUndefinedType( description: String ) extends ItemState { override val itemStateType: ItemStateType = ItemStateType.UNDEFINED(description) } sealed trait ItemStateFailedCause extends ItemState object ItemStateFailedCause { case object ErrorCause1 extends ItemStateFailedCause { override def toString = "ErrorCause1" override val itemStateType: ItemStateType = ItemStateType.ItemStateFailedCause } case object ErrorCause2 extends ItemStateFailedCause { override def toString = "ErrorCause2" override val itemStateType: ItemStateType = ItemStateType.ItemStateFailedCause } case object ErrorCause3 extends ItemStateFailedCause { override def toString = "ErrorCause3" override val itemStateType: ItemStateType = ItemStateType.ItemStateFailedCause } /** * 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 ItemStateFailedCause { override val itemStateType: ItemStateType = ItemStateType.ItemStateFailedCause } /** * 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[ItemStateFailedCause] = scala.List(ErrorCause1, ErrorCause2, ErrorCause3) private val byName: Map[String, ItemStateFailedCause] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): ItemStateFailedCause = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[ItemStateFailedCause] = byName.get(value.toLowerCase) } sealed trait ItemStateProgress extends ItemState object ItemStateProgress { case object Init extends ItemStateProgress { override def toString = "Init" override val itemStateType: ItemStateType = ItemStateType.ItemStateProgress } case object Pending extends ItemStateProgress { override def toString = "Pending" override val itemStateType: ItemStateType = ItemStateType.ItemStateProgress } case object Completed extends ItemStateProgress { override def toString = "Completed" override val itemStateType: ItemStateType = ItemStateType.ItemStateProgress } /** * 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 ItemStateProgress { override val itemStateType: ItemStateType = ItemStateType.ItemStateProgress } /** * 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[ItemStateProgress] = scala.List(Init, Pending, Completed) private val byName: Map[String, ItemStateProgress] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): ItemStateProgress = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[ItemStateProgress] = byName.get(value.toLowerCase) } } package io.github.mkows.playground.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 io.github.mkows.playground.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 jsonReadsPlaygroundApiItemStateFailedCause: play.api.libs.json.Reads[io.github.mkows.playground.api.v0.models.ItemStateFailedCause] = new play.api.libs.json.Reads[io.github.mkows.playground.api.v0.models.ItemStateFailedCause] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[io.github.mkows.playground.api.v0.models.ItemStateFailedCause] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(io.github.mkows.playground.api.v0.models.ItemStateFailedCause(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(io.github.mkows.playground.api.v0.models.ItemStateFailedCause(v)) case _: play.api.libs.json.JsError => (js \ "item_state_failed_cause").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(io.github.mkows.playground.api.v0.models.ItemStateFailedCause(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesPlaygroundApiItemStateFailedCause(obj: io.github.mkows.playground.api.v0.models.ItemStateFailedCause) = { play.api.libs.json.JsString(obj.toString) } def jsObjectItemStateFailedCause(obj: io.github.mkows.playground.api.v0.models.ItemStateFailedCause) = { play.api.libs.json.Json.obj("type" -> "item_state_failed_cause", "value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesPlaygroundApiItemStateFailedCause: play.api.libs.json.Writes[ItemStateFailedCause] = { (obj: io.github.mkows.playground.api.v0.models.ItemStateFailedCause) => { io.github.mkows.playground.api.v0.models.json.jsObjectItemStateFailedCause(obj) } } implicit val jsonReadsPlaygroundApiItemStateProgress: play.api.libs.json.Reads[io.github.mkows.playground.api.v0.models.ItemStateProgress] = new play.api.libs.json.Reads[io.github.mkows.playground.api.v0.models.ItemStateProgress] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[io.github.mkows.playground.api.v0.models.ItemStateProgress] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(io.github.mkows.playground.api.v0.models.ItemStateProgress(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(io.github.mkows.playground.api.v0.models.ItemStateProgress(v)) case _: play.api.libs.json.JsError => (js \ "item_state_progress").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(io.github.mkows.playground.api.v0.models.ItemStateProgress(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesPlaygroundApiItemStateProgress(obj: io.github.mkows.playground.api.v0.models.ItemStateProgress) = { play.api.libs.json.JsString(obj.toString) } def jsObjectItemStateProgress(obj: io.github.mkows.playground.api.v0.models.ItemStateProgress) = { play.api.libs.json.Json.obj("type" -> "item_state_progress", "value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesPlaygroundApiItemStateProgress: play.api.libs.json.Writes[ItemStateProgress] = { (obj: io.github.mkows.playground.api.v0.models.ItemStateProgress) => { io.github.mkows.playground.api.v0.models.json.jsObjectItemStateProgress(obj) } } implicit def jsonReadsPlaygroundApiError: play.api.libs.json.Reads[io.github.mkows.playground.api.v0.models.Error] = { for { code <- (__ \ "code").read[Int] message <- (__ \ "message").read[String] details <- (__ \ "details").readNullable[String] } yield Error(code, message, details) } def jsObjectError(obj: io.github.mkows.playground.api.v0.models.Error): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "code" -> play.api.libs.json.JsNumber(obj.code), "message" -> play.api.libs.json.JsString(obj.message) ) ++ (obj.details match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("details" -> play.api.libs.json.JsString(x)) }) } implicit def jsonWritesPlaygroundApiError: play.api.libs.json.Writes[Error] = { (obj: io.github.mkows.playground.api.v0.models.Error) => { io.github.mkows.playground.api.v0.models.json.jsObjectError(obj) } } implicit def jsonReadsPlaygroundApiHealthcheck: play.api.libs.json.Reads[io.github.mkows.playground.api.v0.models.Healthcheck] = { for { status <- (__ \ "status").read[String] createdAt <- (__ \ "created_at").read[_root_.org.joda.time.DateTime] } yield Healthcheck(status, createdAt) } def jsObjectHealthcheck(obj: io.github.mkows.playground.api.v0.models.Healthcheck): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "status" -> play.api.libs.json.JsString(obj.status), "created_at" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.createdAt)) ) } implicit def jsonWritesPlaygroundApiHealthcheck: play.api.libs.json.Writes[Healthcheck] = { (obj: io.github.mkows.playground.api.v0.models.Healthcheck) => { io.github.mkows.playground.api.v0.models.json.jsObjectHealthcheck(obj) } } implicit def jsonReadsPlaygroundApiItemState[T <: io.github.mkows.playground.api.v0.models.ItemState]: play.api.libs.json.Reads[T] = (js: play.api.libs.json.JsValue) => { def readDiscriminator(discriminator: String) = { discriminator match { case "item_state_progress" => io.github.mkows.playground.api.v0.models.json.jsonReadsPlaygroundApiItemStateProgress.reads(js) case "item_state_failed_cause" => io.github.mkows.playground.api.v0.models.json.jsonReadsPlaygroundApiItemStateFailedCause.reads(js) case other => play.api.libs.json.JsSuccess(io.github.mkows.playground.api.v0.models.ItemStateUndefinedType(other)) } } (js \ "type").validate[String] match { case e: play.api.libs.json.JsError => e case s: play.api.libs.json.JsSuccess[String] => readDiscriminator(s.value).map(_.asInstanceOf[T]) } } implicit def jsonReadsPlaygroundApiItemStateSeq[T <: io.github.mkows.playground.api.v0.models.ItemState]: play.api.libs.json.Reads[Seq[T]] = { case a: play.api.libs.json.JsArray => { val all: Seq[play.api.libs.json.JsResult[io.github.mkows.playground.api.v0.models.ItemState]] = a.value.map(jsonReadsPlaygroundApiItemState.reads).toSeq all.collect { case e: play.api.libs.json.JsError => e }.toList match { case Nil => play.api.libs.json.JsSuccess(all.collect { case play.api.libs.json.JsSuccess(v, _) => v.asInstanceOf[T] }) case errors => play.api.libs.json.JsError(play.api.libs.json.JsError.merge(errors.flatMap(_.errors), Nil)) } } case other => play.api.libs.json.JsError(s"Expected array but found [" + other.getClass.getName + "]") } def jsObjectItemState(obj: io.github.mkows.playground.api.v0.models.ItemState): play.api.libs.json.JsObject = { obj match { case x: io.github.mkows.playground.api.v0.models.ItemStateProgress => io.github.mkows.playground.api.v0.models.json.jsObjectItemStateProgress(x) case x: io.github.mkows.playground.api.v0.models.ItemStateFailedCause => io.github.mkows.playground.api.v0.models.json.jsObjectItemStateFailedCause(x) case other => { sys.error(s"The type[${other.getClass.getName}] has no JSON writer") } } } implicit def jsonWritesPlaygroundApiItemState[T <: io.github.mkows.playground.api.v0.models.ItemState]: play.api.libs.json.Writes[T] = { (obj: io.github.mkows.playground.api.v0.models.ItemState) => { io.github.mkows.playground.api.v0.models.json.jsObjectItemState(obj) } } } }