/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1 * User agent: apibuilder app.apibuilder.io/cerium/termsteelversionapi/0.0.1/play_2_x_scala_3_json */ package cerium.termsteelversionapi.v0.models { /** * An attribute represents a key/value pair that is optionally used to provide * additional instructions / data to the code generator. An example could be an * attribute to specify the root import path for a go client.. */ final case class Attribute( name: String, value: String ) /** * @param code Machine readable code for this specific error message * @param message Description of the error */ final case class Error( code: String, message: String ) /** * Represents a source file * * @param name The recommended name for the file. * @param dir The recommended directory path for the file where appropriate. * @param contents The actual source code. */ final case class File( name: String, dir: _root_.scala.Option[String] = None, contents: String, flags: _root_.scala.Option[Seq[cerium.termsteelversionapi.v0.models.FileFlag]] = None ) /** * The generator metadata. * * @param language A comma separate list of the programming language(s) that this generator * produces * @param attributes The list of attributes that this code generator can use. You can find the full * list of available attributes and their descriptions at * http://apibuilder.io/doc/attributes */ final case class Generator( key: String, name: String, language: _root_.scala.Option[String] = None, description: _root_.scala.Option[String] = None, attributes: Seq[String] = Nil ) final case class Healthcheck( status: String ) /** * The result of invoking a generator. * * @param source The actual source code. * @param files A collection of source files */ final case class Invocation( @deprecated("Use files instead") source: String, files: Seq[cerium.termsteelversionapi.v0.models.File] ) /** * The invocation form is the payload send to the code generators when requesting * generation of client code. */ final case class InvocationForm( service: io.apibuilder.spec.v0.models.Service, attributes: Seq[cerium.termsteelversionapi.v0.models.Attribute] = Nil, userAgent: _root_.scala.Option[String] = None, importedServices: _root_.scala.Option[Seq[io.apibuilder.spec.v0.models.Service]] = None ) /** * Allows generator authors to flag files with special characteristics. It is up to * the client (i.e. the cli) to decide how to interpret them. */ sealed trait FileFlag extends _root_.scala.Product with _root_.scala.Serializable object FileFlag { /** * Indicates files that an end user starts from but should edit. Not intended to be * the final product (see: * https://stackoverflow.com/questions/235018/what-is-scaffolding-is-it-a-term-for-a-particular-platform). * Consider not overwriting these files when code is re-generated. */ case object Scaffolding extends FileFlag { override def toString = "scaffolding" } /** * 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 FileFlag /** * 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[FileFlag] = scala.List(Scaffolding) private val byName: Map[String, FileFlag] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): FileFlag = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[FileFlag] = byName.get(value.toLowerCase) } } package cerium.termsteelversionapi.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 cerium.termsteelversionapi.v0.models.json._ import io.apibuilder.common.v0.models.json._ import io.apibuilder.spec.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 jsonReadsTermsteelversionapiFileFlag: play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.FileFlag] = new play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.FileFlag] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[cerium.termsteelversionapi.v0.models.FileFlag] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(cerium.termsteelversionapi.v0.models.FileFlag(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(cerium.termsteelversionapi.v0.models.FileFlag(v)) case _: play.api.libs.json.JsError => (js \ "file_flag").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(cerium.termsteelversionapi.v0.models.FileFlag(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesTermsteelversionapiFileFlag(obj: cerium.termsteelversionapi.v0.models.FileFlag) = { play.api.libs.json.JsString(obj.toString) } def jsObjectFileFlag(obj: cerium.termsteelversionapi.v0.models.FileFlag) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesTermsteelversionapiFileFlag: play.api.libs.json.Writes[FileFlag] = { (obj: cerium.termsteelversionapi.v0.models.FileFlag) => { cerium.termsteelversionapi.v0.models.json.jsonWritesTermsteelversionapiFileFlag(obj) } } implicit def jsonReadsTermsteelversionapiAttribute: play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.Attribute] = { for { name <- (__ \ "name").read[String] value <- (__ \ "value").read[String] } yield Attribute(name, value) } def jsObjectAttribute(obj: cerium.termsteelversionapi.v0.models.Attribute): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "name" -> play.api.libs.json.JsString(obj.name), "value" -> play.api.libs.json.JsString(obj.value) ) } implicit def jsonWritesTermsteelversionapiAttribute: play.api.libs.json.Writes[Attribute] = { (obj: cerium.termsteelversionapi.v0.models.Attribute) => { cerium.termsteelversionapi.v0.models.json.jsObjectAttribute(obj) } } implicit def jsonReadsTermsteelversionapiError: play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.Error] = { for { code <- (__ \ "code").read[String] message <- (__ \ "message").read[String] } yield Error(code, message) } def jsObjectError(obj: cerium.termsteelversionapi.v0.models.Error): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "code" -> play.api.libs.json.JsString(obj.code), "message" -> play.api.libs.json.JsString(obj.message) ) } implicit def jsonWritesTermsteelversionapiError: play.api.libs.json.Writes[Error] = { (obj: cerium.termsteelversionapi.v0.models.Error) => { cerium.termsteelversionapi.v0.models.json.jsObjectError(obj) } } implicit def jsonReadsTermsteelversionapiFile: play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.File] = { for { name <- (__ \ "name").read[String] dir <- (__ \ "dir").readNullable[String] contents <- (__ \ "contents").read[String] flags <- (__ \ "flags").readNullable[Seq[cerium.termsteelversionapi.v0.models.FileFlag]] } yield File(name, dir, contents, flags) } def jsObjectFile(obj: cerium.termsteelversionapi.v0.models.File): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "name" -> play.api.libs.json.JsString(obj.name), "contents" -> play.api.libs.json.JsString(obj.contents) ) ++ (obj.dir match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("dir" -> play.api.libs.json.JsString(x)) }) ++ (obj.flags match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("flags" -> play.api.libs.json.Json.toJson(x)) }) } implicit def jsonWritesTermsteelversionapiFile: play.api.libs.json.Writes[File] = { (obj: cerium.termsteelversionapi.v0.models.File) => { cerium.termsteelversionapi.v0.models.json.jsObjectFile(obj) } } implicit def jsonReadsTermsteelversionapiGenerator: play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.Generator] = { for { key <- (__ \ "key").read[String] name <- (__ \ "name").read[String] language <- (__ \ "language").readNullable[String] description <- (__ \ "description").readNullable[String] attributes <- (__ \ "attributes").read[Seq[String]] } yield Generator(key, name, language, description, attributes) } def jsObjectGenerator(obj: cerium.termsteelversionapi.v0.models.Generator): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "key" -> play.api.libs.json.JsString(obj.key), "name" -> play.api.libs.json.JsString(obj.name), "attributes" -> play.api.libs.json.Json.toJson(obj.attributes) ) ++ (obj.language match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("language" -> play.api.libs.json.JsString(x)) }) ++ (obj.description match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("description" -> play.api.libs.json.JsString(x)) }) } implicit def jsonWritesTermsteelversionapiGenerator: play.api.libs.json.Writes[Generator] = { (obj: cerium.termsteelversionapi.v0.models.Generator) => { cerium.termsteelversionapi.v0.models.json.jsObjectGenerator(obj) } } implicit def jsonReadsTermsteelversionapiHealthcheck: play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.Healthcheck] = { (__ \ "status").read[String].map { x => Healthcheck(status = x) } } def jsObjectHealthcheck(obj: cerium.termsteelversionapi.v0.models.Healthcheck): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "status" -> play.api.libs.json.JsString(obj.status) ) } implicit def jsonWritesTermsteelversionapiHealthcheck: play.api.libs.json.Writes[Healthcheck] = { (obj: cerium.termsteelversionapi.v0.models.Healthcheck) => { cerium.termsteelversionapi.v0.models.json.jsObjectHealthcheck(obj) } } implicit def jsonReadsTermsteelversionapiInvocation: play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.Invocation] = { for { source <- (__ \ "source").read[String] files <- (__ \ "files").read[Seq[cerium.termsteelversionapi.v0.models.File]] } yield Invocation(source, files) } def jsObjectInvocation(obj: cerium.termsteelversionapi.v0.models.Invocation): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "source" -> play.api.libs.json.JsString(obj.source), "files" -> play.api.libs.json.Json.toJson(obj.files) ) } implicit def jsonWritesTermsteelversionapiInvocation: play.api.libs.json.Writes[Invocation] = { (obj: cerium.termsteelversionapi.v0.models.Invocation) => { cerium.termsteelversionapi.v0.models.json.jsObjectInvocation(obj) } } implicit def jsonReadsTermsteelversionapiInvocationForm: play.api.libs.json.Reads[cerium.termsteelversionapi.v0.models.InvocationForm] = { for { service <- (__ \ "service").read[io.apibuilder.spec.v0.models.Service] attributes <- (__ \ "attributes").read[Seq[cerium.termsteelversionapi.v0.models.Attribute]] userAgent <- (__ \ "user_agent").readNullable[String] importedServices <- (__ \ "imported_services").readNullable[Seq[io.apibuilder.spec.v0.models.Service]] } yield InvocationForm(service, attributes, userAgent, importedServices) } def jsObjectInvocationForm(obj: cerium.termsteelversionapi.v0.models.InvocationForm): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "service" -> io.apibuilder.spec.v0.models.json.jsObjectService(obj.service), "attributes" -> play.api.libs.json.Json.toJson(obj.attributes) ) ++ (obj.userAgent match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("user_agent" -> play.api.libs.json.JsString(x)) }) ++ (obj.importedServices match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("imported_services" -> play.api.libs.json.Json.toJson(x)) }) } implicit def jsonWritesTermsteelversionapiInvocationForm: play.api.libs.json.Writes[InvocationForm] = { (obj: cerium.termsteelversionapi.v0.models.InvocationForm) => { cerium.termsteelversionapi.v0.models.json.jsObjectInvocationForm(obj) } } } } package cerium.termsteelversionapi.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 cerium.termsteelversionapi.v0.models._ val fileFlagConverter: ApibuilderTypeConverter[cerium.termsteelversionapi.v0.models.FileFlag] = new ApibuilderTypeConverter[cerium.termsteelversionapi.v0.models.FileFlag] { override def convert(value: String): cerium.termsteelversionapi.v0.models.FileFlag = cerium.termsteelversionapi.v0.models.FileFlag(value) override def convert(value: cerium.termsteelversionapi.v0.models.FileFlag): String = value.toString override def example: cerium.termsteelversionapi.v0.models.FileFlag = cerium.termsteelversionapi.v0.models.FileFlag.Scaffolding override def validValues: Seq[cerium.termsteelversionapi.v0.models.FileFlag] = cerium.termsteelversionapi.v0.models.FileFlag.all } implicit def pathBindableFileFlag(implicit stringBinder: QueryStringBindable[String]): PathBindable[cerium.termsteelversionapi.v0.models.FileFlag] = ApibuilderPathBindable(fileFlagConverter) implicit def queryStringBindableFileFlag(implicit stringBinder: QueryStringBindable[String]): QueryStringBindable[cerium.termsteelversionapi.v0.models.FileFlag] = ApibuilderQueryStringBindable(fileFlagConverter) } 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) } } } }