/** * Generated by API Builder - https://www.apibuilder.io * Service version: 2.0.1 * User agent: apibuilder app.apibuilder.io/chio/provided_test_app3/2.0.1/play_2_x_json */ package io.chio.provided.test.app3.v2.models { /** * A generic error providing a message and some basic meta data. * * @param id A guid for identifying the error e.g. in log files. * @param timestamp Timestamp of the when the error occurred. * @param source An optional source on which the error occurred. * @param `type` An optional type for categorizing e.g. `validation` or `invalid_state`. * @param message The actual message of the error. */ final case class GenericError( id: _root_.java.util.UUID, timestamp: _root_.org.joda.time.DateTime, source: _root_.scala.Option[String] = None, `type`: _root_.scala.Option[String] = None, message: String ) /** * Response model indicating the health of a service. * * @param health The current health of the service. Normally this is `healthy`, otherwise an * simple error message can be shown. */ final case class Healthcheck( health: String ) } package io.chio.provided.test.app3.v2.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.chio.provided.test.app3.v2.models.json._ private[v2] implicit val jsonReadsUUID: play.api.libs.json.Reads[_root_.java.util.UUID] = __.read[String].map { str => _root_.java.util.UUID.fromString(str) } private[v2] 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[v2] 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[v2] 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[v2] 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[v2] 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 def jsonReadsProvidedTestApp3GenericError: play.api.libs.json.Reads[io.chio.provided.test.app3.v2.models.GenericError] = { for { id <- (__ \ "id").read[_root_.java.util.UUID] timestamp <- (__ \ "timestamp").read[_root_.org.joda.time.DateTime] source <- (__ \ "source").readNullable[String] `type` <- (__ \ "type").readNullable[String] message <- (__ \ "message").read[String] } yield GenericError(id, timestamp, source, `type`, message) } def jsObjectGenericError(obj: io.chio.provided.test.app3.v2.models.GenericError): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "id" -> play.api.libs.json.JsString(obj.id.toString), "timestamp" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.timestamp)), "message" -> play.api.libs.json.JsString(obj.message) ) ++ (obj.source match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("source" -> play.api.libs.json.JsString(x)) }) ++ (obj.`type` match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("type" -> play.api.libs.json.JsString(x)) }) } implicit def jsonWritesProvidedTestApp3GenericError: play.api.libs.json.Writes[GenericError] = { (obj: io.chio.provided.test.app3.v2.models.GenericError) => { io.chio.provided.test.app3.v2.models.json.jsObjectGenericError(obj) } } implicit def jsonReadsProvidedTestApp3Healthcheck: play.api.libs.json.Reads[io.chio.provided.test.app3.v2.models.Healthcheck] = { (__ \ "health").read[String].map { x => Healthcheck(health = x) } } def jsObjectHealthcheck(obj: io.chio.provided.test.app3.v2.models.Healthcheck): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "health" -> play.api.libs.json.JsString(obj.health) ) } implicit def jsonWritesProvidedTestApp3Healthcheck: play.api.libs.json.Writes[Healthcheck] = { (obj: io.chio.provided.test.app3.v2.models.Healthcheck) => { io.chio.provided.test.app3.v2.models.json.jsObjectHealthcheck(obj) } } } } package io.chio.provided.test.app3.v2 { object Bindables { import play.api.mvc.{PathBindable, QueryStringBindable} // import models directly for backwards compatibility with prior versions of the generator import Core._ 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) } 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) } } } }