/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1 * User agent: apibuilder app.apibuilder.io/nccloud/common/0.0.1/http4s_0_22 */ package de.nccloud.common.v0.models { /** * Represents a link to a resource. */ sealed trait Link extends _root_.scala.Product with _root_.scala.Serializable /** * Basic audit information for a resource. */ final case class Audit( createdAt: _root_.java.time.Instant, createdBy: _root_.java.util.UUID, updatedAt: _root_.java.time.Instant, updatedBy: _root_.java.util.UUID ) /** * Links to further information about the occurred error. * * @param about A link that leads to further details about this particular occurrence of the * problem. * @param `type` A link that identifies the type of the error that this particular error is an * instance of. */ final case class ErrorLinks( about: _root_.scala.Option[de.nccloud.common.v0.models.Link] = None, `type`: _root_.scala.Option[de.nccloud.common.v0.models.Link] = None ) /** * Reference to the primary source of an error. * * @param source The source of the problem in the form specified by `type`. */ final case class ErrorSource( `type`: de.nccloud.common.v0.models.ErrorSourceType, source: String ) /** * An error returned on failed API requests. * * @param code An app specific error code. * @param title A short human readable summary of the problem. * @param detail A human readable explanation of the problem. * @param meta Non-standard meta-information about the error. */ final case class GenericError( links: _root_.scala.Option[de.nccloud.common.v0.models.ErrorLinks] = None, code: String, title: String, detail: String, source: _root_.scala.Option[de.nccloud.common.v0.models.ErrorSource] = None, meta: _root_.scala.Option[Map[String, _root_.io.circe.Json]] = None ) /** * Indicating the health of a service. * * @param message An optional message giving more detailed information about the current health. */ final case class HealthCheck( status: de.nccloud.common.v0.models.HealthStatus, message: _root_.scala.Option[String] = None ) /** * Represents a link with some meta information. * * @param href An URI-reference pointing to the links target. * @param title A human-readable label for the link. * @param `type` Optional media type of the link's target. */ final case class LinkObject( href: String, title: _root_.scala.Option[String] = None, `type`: _root_.scala.Option[String] = None ) extends Link /** * Paging information returned from a paged request. * * @param totalResults Total number of results that can potentially be returned. * @param totalPages Total number of pages that can potentially be returned. */ final case class PageResponse( offset: Int, limit: Int, sort: Seq[de.nccloud.common.v0.models.Sort], totalResults: Long, totalPages: Long ) /** * Form containing paging information. * * @param offset Offset of the current page. The pages are 0-indexed, meaning the first page * starts at 0. * @param limit The number of results to be returned by the api. * @param sort Defines multiple properties for the results to be sorted by. The order of the * definition defines the priority. If omitted, the service will use an * implementation dependent default sort. */ final case class PagingForm( offset: Int = 0, limit: Int = 25, sort: _root_.scala.Option[Seq[de.nccloud.common.v0.models.Sort]] = None ) /** * Information about a deployed service. * * @param uri URI under which this service is deployed. * @param title A human-readable title of the service. * @param description A human-readable description of the service. */ final case class ServiceInfo( name: String, version: String, uri: String, title: _root_.scala.Option[String] = None, description: _root_.scala.Option[String] = None ) /** * Single property to sort by. * * @param property The property by which the results should be sorted. * @param direction The direction in which the results should be sorted. */ final case class Sort( property: String, direction: de.nccloud.common.v0.models.SortDirection ) /** * Provides future compatibility in clients - in the future, when a type is added * to the union Link, 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 LinkUndefinedType( description: String ) extends Link /** * Wrapper class to support the union types containing the datatype[string] */ final case class LinkString( value: String ) extends Link /** * Type of an error source. */ sealed trait ErrorSourceType extends _root_.scala.Product with _root_.scala.Serializable object ErrorSourceType { /** * Indicating a [JSON pointer](https://tools.ietf.org/html/rfc6901) to the value * that has caused the error. */ case object Pointer extends ErrorSourceType { override def toString = "pointer" } /** * Indicating an URI query parameter causing the error. */ case object Parameter extends ErrorSourceType { override def toString = "parameter" } /** * Indicating a request header causing the error. */ case object Header extends ErrorSourceType { override def toString = "header" } /** * 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 ErrorSourceType /** * 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[ErrorSourceType] = scala.List(Pointer, Parameter, Header) private val byName: Map[String, ErrorSourceType] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): ErrorSourceType = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[ErrorSourceType] = byName.get(value.toLowerCase) } /** * The status of a service. */ sealed trait HealthStatus extends _root_.scala.Product with _root_.scala.Serializable object HealthStatus { /** * The service is running and healthy. */ case object Running extends HealthStatus { override def toString = "running" } /** * The service is not yet running. */ case object Starting extends HealthStatus { override def toString = "starting" } /** * The service has encountered errors and is not running property. */ case object Unhealthy extends HealthStatus { override def toString = "unhealthy" } /** * 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 HealthStatus /** * 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[HealthStatus] = scala.List(Running, Starting, Unhealthy) private val byName: Map[String, HealthStatus] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): HealthStatus = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[HealthStatus] = byName.get(value.toLowerCase) } /** * The direction in which to sort by a property. */ sealed trait SortDirection extends _root_.scala.Product with _root_.scala.Serializable object SortDirection { /** * Sort ascending. */ case object Asc extends SortDirection { override def toString = "asc" } /** * Sort descending. */ case object Desc extends SortDirection { override def toString = "desc" } /** * 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 SortDirection /** * 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[SortDirection] = scala.List(Asc, Desc) private val byName: Map[String, SortDirection] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): SortDirection = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[SortDirection] = byName.get(value.toLowerCase) } } package de.nccloud.common.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 de.nccloud.common.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 val jsonDecoderCommonErrorSourceType: Decoder[de.nccloud.common.v0.models.ErrorSourceType] = Decoder.decodeString.map(de.nccloud.common.v0.models.ErrorSourceType(_)) implicit val jsonEncoderCommonErrorSourceType: Encoder[de.nccloud.common.v0.models.ErrorSourceType] = Encoder.encodeString.contramap[de.nccloud.common.v0.models.ErrorSourceType](_.toString) implicit val jsonDecoderCommonHealthStatus: Decoder[de.nccloud.common.v0.models.HealthStatus] = Decoder.decodeString.map(de.nccloud.common.v0.models.HealthStatus(_)) implicit val jsonEncoderCommonHealthStatus: Encoder[de.nccloud.common.v0.models.HealthStatus] = Encoder.encodeString.contramap[de.nccloud.common.v0.models.HealthStatus](_.toString) implicit val jsonDecoderCommonSortDirection: Decoder[de.nccloud.common.v0.models.SortDirection] = Decoder.decodeString.map(de.nccloud.common.v0.models.SortDirection(_)) implicit val jsonEncoderCommonSortDirection: Encoder[de.nccloud.common.v0.models.SortDirection] = Encoder.encodeString.contramap[de.nccloud.common.v0.models.SortDirection](_.toString) implicit def decodeCommonAudit: Decoder[Audit] = Decoder.instance { c => for { createdAt <- c.downField("created_at").as[_root_.java.time.Instant] createdBy <- c.downField("created_by").as[_root_.java.util.UUID] updatedAt <- c.downField("updated_at").as[_root_.java.time.Instant] updatedBy <- c.downField("updated_by").as[_root_.java.util.UUID] } yield { Audit( createdAt = createdAt, createdBy = createdBy, updatedAt = updatedAt, updatedBy = updatedBy ) } } implicit def encodeCommonAudit: Encoder[Audit] = Encoder.instance { t => Json.fromFields(Seq( Some("created_at" -> t.createdAt.asJson), Some("created_by" -> t.createdBy.asJson), Some("updated_at" -> t.updatedAt.asJson), Some("updated_by" -> t.updatedBy.asJson) ).flatten) } implicit def decodeCommonErrorLinks: Decoder[ErrorLinks] = Decoder.instance { c => for { about <- c.downField("about").as[Option[de.nccloud.common.v0.models.Link]] __type__ <- c.downField("type").as[Option[de.nccloud.common.v0.models.Link]] } yield { ErrorLinks( about = about, `type` = __type__ ) } } implicit def encodeCommonErrorLinks: Encoder[ErrorLinks] = Encoder.instance { t => Json.fromFields(Seq( t.about.map(t => "about" -> t.asJson), t.`type`.map(t => "type" -> t.asJson) ).flatten) } implicit def decodeCommonErrorSource: Decoder[ErrorSource] = Decoder.instance { c => for { __type__ <- c.downField("type").as[de.nccloud.common.v0.models.ErrorSourceType] source <- c.downField("source").as[String] } yield { ErrorSource( `type` = __type__, source = source ) } } implicit def encodeCommonErrorSource: Encoder[ErrorSource] = Encoder.instance { t => Json.fromFields(Seq( Some("type" -> t.`type`.asJson), Some("source" -> t.source.asJson) ).flatten) } implicit def decodeCommonGenericError: Decoder[GenericError] = Decoder.instance { c => for { links <- c.downField("links").as[Option[de.nccloud.common.v0.models.ErrorLinks]] code <- c.downField("code").as[String] title <- c.downField("title").as[String] detail <- c.downField("detail").as[String] source <- c.downField("source").as[Option[de.nccloud.common.v0.models.ErrorSource]] meta <- c.downField("meta").as[Option[Map[String, _root_.io.circe.Json]]] } yield { GenericError( links = links, code = code, title = title, detail = detail, source = source, meta = meta ) } } implicit def encodeCommonGenericError: Encoder[GenericError] = Encoder.instance { t => Json.fromFields(Seq( t.links.map(t => "links" -> t.asJson), Some("code" -> t.code.asJson), Some("title" -> t.title.asJson), Some("detail" -> t.detail.asJson), t.source.map(t => "source" -> t.asJson), t.meta.map(t => "meta" -> t.asJson) ).flatten) } implicit def decodeCommonHealthCheck: Decoder[HealthCheck] = Decoder.instance { c => for { status <- c.downField("status").as[de.nccloud.common.v0.models.HealthStatus] message <- c.downField("message").as[Option[String]] } yield { HealthCheck( status = status, message = message ) } } implicit def encodeCommonHealthCheck: Encoder[HealthCheck] = Encoder.instance { t => Json.fromFields(Seq( Some("status" -> t.status.asJson), t.message.map(t => "message" -> t.asJson) ).flatten) } implicit def decodeCommonLinkObject: Decoder[LinkObject] = Decoder.instance { c => for { href <- c.downField("href").as[String] title <- c.downField("title").as[Option[String]] __type__ <- c.downField("type").as[Option[String]] } yield { LinkObject( href = href, title = title, `type` = __type__ ) } } implicit def encodeCommonLinkObject: Encoder[LinkObject] = Encoder.instance { t => Json.fromFields(Seq( Some("href" -> t.href.asJson), t.title.map(t => "title" -> t.asJson), t.`type`.map(t => "type" -> t.asJson) ).flatten) } implicit def decodeCommonPageResponse: Decoder[PageResponse] = Decoder.instance { c => for { offset <- c.downField("offset").as[Int] limit <- c.downField("limit").as[Int] sort <- c.downField("sort").as[Seq[de.nccloud.common.v0.models.Sort]] totalResults <- c.downField("total_results").as[Long] totalPages <- c.downField("total_pages").as[Long] } yield { PageResponse( offset = offset, limit = limit, sort = sort, totalResults = totalResults, totalPages = totalPages ) } } implicit def encodeCommonPageResponse: Encoder[PageResponse] = Encoder.instance { t => Json.fromFields(Seq( Some("offset" -> t.offset.asJson), Some("limit" -> t.limit.asJson), Some("sort" -> t.sort.asJson), Some("total_results" -> t.totalResults.asJson), Some("total_pages" -> t.totalPages.asJson) ).flatten) } implicit def decodeCommonPagingForm: Decoder[PagingForm] = Decoder.instance { c => for { offset <- c.downField("offset").as[Int] limit <- c.downField("limit").as[Int] sort <- c.downField("sort").as[Option[Seq[de.nccloud.common.v0.models.Sort]]] } yield { PagingForm( offset = offset, limit = limit, sort = sort ) } } implicit def encodeCommonPagingForm: Encoder[PagingForm] = Encoder.instance { t => Json.fromFields(Seq( Some("offset" -> t.offset.asJson), Some("limit" -> t.limit.asJson), t.sort.map(t => "sort" -> t.asJson) ).flatten) } implicit def decodeCommonServiceInfo: Decoder[ServiceInfo] = Decoder.instance { c => for { name <- c.downField("name").as[String] version <- c.downField("version").as[String] uri <- c.downField("uri").as[String] title <- c.downField("title").as[Option[String]] description <- c.downField("description").as[Option[String]] } yield { ServiceInfo( name = name, version = version, uri = uri, title = title, description = description ) } } implicit def encodeCommonServiceInfo: Encoder[ServiceInfo] = Encoder.instance { t => Json.fromFields(Seq( Some("name" -> t.name.asJson), Some("version" -> t.version.asJson), Some("uri" -> t.uri.asJson), t.title.map(t => "title" -> t.asJson), t.description.map(t => "description" -> t.asJson) ).flatten) } implicit def decodeCommonSort: Decoder[Sort] = Decoder.instance { c => for { property <- c.downField("property").as[String] direction <- c.downField("direction").as[de.nccloud.common.v0.models.SortDirection] } yield { Sort( property = property, direction = direction ) } } implicit def encodeCommonSort: Encoder[Sort] = Encoder.instance { t => Json.fromFields(Seq( Some("property" -> t.property.asJson), Some("direction" -> t.direction.asJson) ).flatten) } implicit def decodeCommonLinkString: Decoder[LinkString] = Decoder.instance { c => for { value <- c.downField("value").as[String] } yield { LinkString( value = value ) } } implicit def encodeCommonLinkString: Encoder[LinkString] = Encoder.instance { t => Json.fromFields(Seq( Some("value" -> t.value.asJson) ).flatten) } implicit def decodeCommonLink: Decoder[Link] = Decoder.instance { c => c.get[de.nccloud.common.v0.models.LinkString]("string") orElse c.get[de.nccloud.common.v0.models.LinkObject]("link_object") orElse Right(de.nccloud.common.v0.models.LinkUndefinedType(c.value.toString)) } implicit def encodeCommonLink: Encoder[Link] = Encoder.instance { case t: de.nccloud.common.v0.models.LinkString => Json.fromJsonObject(JsonObject.singleton("string", t.asJson)) case t: de.nccloud.common.v0.models.LinkObject => Json.fromJsonObject(JsonObject.singleton("link_object", t.asJson)) case other => sys.error(s"The type[${other.getClass.getName}] has no JSON encoder") } } }