/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.1.0-SNAPSHOT * User agent: apibuilder app.apibuilder.io/movio/apidoc-generator-attributes/0.1.0-SNAPSHOT/http4s_0_22 */ package movio.apidoc.generator.attributes.v0.models { /** * Additional validation options not currently in the standard apidoc spec * * @param regex Regex string to validate the field with. The field must be a `string` or * `[string]`. If the field is a `[string]` all elements in the array will be * validated * @param maximum This applies only to `[string]`, `[integer]` and `[long]`. The current apidoc * spec includes maximum however for an array this the maxium size of the array. * This validates the max length or number of each element of the array. The field * must be a `[string]`, `[integer]` or `[long]`. All elements in the array will be * validated as per standard apidoc specs * @param minimum This applies only to `[string]`, `[integer]` and `[long]`. The current apidoc * spec includes minimum however for an array this the minimum size of the array. * This validates the minimum length or number of each element of the array. The * field must be a `[string]`, `[integer]` or `[long]`. All elements in the array * will be validated as per standard apidoc specs */ final case class FieldValidation( regex: _root_.scala.Option[String] = None, maximum: _root_.scala.Option[Long] = None, minimum: _root_.scala.Option[Long] = None ) /** * Information needed for generating Kafka wrappers, consumers and producers. * * @param dataType This is the name of the model that this kafka wrapper encapsulated. Model name * is the same as defined in the models section * @param topic [scala] This is a scala snippet that returns a string with the topic name for * kafka. The generator creates a function on the kafka topic object `def * topic(tenant: String) = ` * @param messageGenerateKey [scala] This is a scala snippet that creates a string used as the message ID. * The message ID is used as the kafka message ID. The generator creates a function * on the case class `def generateKey(tenant: String) = ` */ final case class KafkaProps( dataType: String, topic: String, messageGenerateKey: String = "java.util.UUID.randomUUID().toString" ) /** * Additional code generation information for case class fields * * @param `class` The fully qualified Scala/Java class to use during implementation. Note that * this class must have a json formatter defined in the generator code. Currenly * only org.joda.time.LocalDate and org.joda.time.LocalDateTime are implemented. In * the future this maybe a defined list of supported classes * @param default Used as the default in a case class. * @param example Used in documentation and as a default implementation when creating example * implementation's of case classes */ final case class ScalaFieldProps( `class`: _root_.scala.Option[String] = None, default: _root_.scala.Option[String] = None, example: _root_.scala.Option[String] = None ) /** * Additional code generation information for case classes * * @param `extends` A list of Scala/Java classes that this model extends */ final case class ScalaModelProps( `extends`: _root_.scala.Option[Seq[String]] = None ) } package movio.apidoc.generator.attributes.v0.models { package object json { import io.circe.Decoder._ import io.circe.Encoder._ import scala.language.implicitConversions // See below - Make Scala 2.11 Either monadic import scala.util.Try import io.circe.{Json, JsonObject, Encoder, Decoder, DecodingFailure} import io.circe.syntax._ import movio.apidoc.generator.attributes.v0.models.json._ // Make Scala 2.11 Either monadic private[v0] implicit def eitherOps[A,B](e: Either[A,B]) = cats.implicits.catsSyntaxEither(e) private[v0] implicit val decodeUUID: Decoder[_root_.java.util.UUID] = Decoder.decodeString.emapTry(str => Try(_root_.java.util.UUID.fromString(str))) private[v0] implicit val encodeUUID: Encoder[_root_.java.util.UUID] = Encoder.encodeString.contramap[_root_.java.util.UUID](uuid => uuid.toString) private[v0] implicit val decodeInstant: Decoder[_root_.java.time.Instant] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.OffsetDateTime.parse(str).toInstant)) private[v0] implicit val encodeInstant: Encoder[_root_.java.time.Instant] = Encoder.encodeString.contramap[_root_.java.time.Instant](_.toString) private[v0] implicit val decodeLocalDate: Decoder[_root_.java.time.LocalDate] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.LocalDate.parse(str))) private[v0] implicit val encodeLocalDate: Encoder[_root_.java.time.LocalDate] = Encoder.encodeString.contramap[_root_.java.time.LocalDate](_.toString) implicit def decodeApidocGeneratorAttributesFieldValidation: Decoder[FieldValidation] = Decoder.instance { c => for { regex <- c.downField("regex").as[Option[String]] maximum <- c.downField("maximum").as[Option[Long]] minimum <- c.downField("minimum").as[Option[Long]] } yield { FieldValidation( regex = regex, maximum = maximum, minimum = minimum ) } } implicit def encodeApidocGeneratorAttributesFieldValidation: Encoder[FieldValidation] = Encoder.instance { t => Json.fromFields(Seq( t.regex.map(t => "regex" -> t.asJson), t.maximum.map(t => "maximum" -> t.asJson), t.minimum.map(t => "minimum" -> t.asJson) ).flatten) } implicit def decodeApidocGeneratorAttributesKafkaProps: Decoder[KafkaProps] = Decoder.instance { c => for { dataType <- c.downField("data_type").as[String] topic <- c.downField("topic").as[String] messageGenerateKey <- c.downField("message_generate_key").as[String] } yield { KafkaProps( dataType = dataType, topic = topic, messageGenerateKey = messageGenerateKey ) } } implicit def encodeApidocGeneratorAttributesKafkaProps: Encoder[KafkaProps] = Encoder.instance { t => Json.fromFields(Seq( Some("data_type" -> t.dataType.asJson), Some("topic" -> t.topic.asJson), Some("message_generate_key" -> t.messageGenerateKey.asJson) ).flatten) } implicit def decodeApidocGeneratorAttributesScalaFieldProps: Decoder[ScalaFieldProps] = Decoder.instance { c => for { __class__ <- c.downField("class").as[Option[String]] default <- c.downField("default").as[Option[String]] example <- c.downField("example").as[Option[String]] } yield { ScalaFieldProps( `class` = __class__, default = default, example = example ) } } implicit def encodeApidocGeneratorAttributesScalaFieldProps: Encoder[ScalaFieldProps] = Encoder.instance { t => Json.fromFields(Seq( t.`class`.map(t => "class" -> t.asJson), t.default.map(t => "default" -> t.asJson), t.example.map(t => "example" -> t.asJson) ).flatten) } implicit def decodeApidocGeneratorAttributesScalaModelProps: Decoder[ScalaModelProps] = Decoder.instance { c => for { __extends__ <- c.downField("extends").as[Option[Seq[String]]] } yield { ScalaModelProps( `extends` = __extends__ ) } } implicit def encodeApidocGeneratorAttributesScalaModelProps: Encoder[ScalaModelProps] = Encoder.instance { t => Json.fromFields(Seq( t.`extends`.map(t => "extends" -> t.asJson) ).flatten) } } }