io.circe.generic.semiauto.deriveEncoder Scala Examples
The following examples show how to use io.circe.generic.semiauto.deriveEncoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: UnsupportedRedirect.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class UnsupportedRedirect( supported: List[String], actual: Option[String] = None ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { val supportedMsg = supported.mkString("[", ", ", "]") actual match { case Some(act) => s"Unsupported redirect scheme - supported: $supportedMsg actual: $act" case None => s"Unsupported redirect scheme - supported: $supportedMsg" } } } object UnsupportedRedirect { implicit val encoder: Encoder[UnsupportedRedirect] = deriveEncoder }
Example 2
Source File: UninstallNonExistentAppForPackage.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class UninstallNonExistentAppForPackage( packageName: String, appId: AppId ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = s"Package [$packageName] with id [$appId] is not installed" } object UninstallNonExistentAppForPackage { implicit val encoder: Encoder[UninstallNonExistentAppForPackage] = deriveEncoder }
Example 3
Source File: JsonDecodingError.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class JsonDecodingError( typeName : String, decodingErrorMessage: String, decodeInput : String ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = s"Unable to decode the JSON value as a ${typeName}" } object JsonDecodingError { implicit val encoder: Encoder[JsonDecodingError] = deriveEncoder }
Example 4
Source File: MarathonBadGateway.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder import io.netty.handler.codec.http.HttpResponseStatus final case class MarathonBadGateway( marathonStatus: HttpResponseStatus, override val status: HttpResponseStatus = HttpResponseStatus.BAD_GATEWAY ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Received response status code ${marathonStatus.code} from Marathon" } } object MarathonBadGateway { implicit val encoder: Encoder[MarathonBadGateway] = deriveEncoder }
Example 5
Source File: MarathonGenericError.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.netty.handler.codec.http.HttpResponseStatus import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class MarathonGenericError( marathonStatus: HttpResponseStatus, override val status: HttpResponseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Received response status code ${marathonStatus.code} from Marathon" } } object MarathonGenericError { implicit val encoder: Encoder[MarathonGenericError] = deriveEncoder }
Example 6
Source File: Forbidden.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder import io.netty.handler.codec.http.HttpResponseStatus final case class Forbidden( serviceName: String, destination : Option[String] = None, override val status: HttpResponseStatus = HttpResponseStatus.FORBIDDEN ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Unable to complete request due to Forbidden response from service " + s"[$serviceName]$destinationMessage" } private def destinationMessage:String = { destination match { case Some(endpoint) => s" while accessing$endpoint" case None => "" } } } object Forbidden { implicit val encoder: Encoder[Forbidden] = deriveEncoder }
Example 7
Source File: EndpointUriConnection.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.lemonlabs.uri.Uri import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder import io.netty.handler.codec.http.HttpResponseStatus final case class EndpointUriConnection( destination: Uri, cause: String ) extends CosmosError { override val status: HttpResponseStatus = HttpResponseStatus.BAD_GATEWAY override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Could not access data at URI ${destination}" } } object EndpointUriConnection { implicit val encoder: Encoder[EndpointUriConnection] = deriveEncoder }
Example 8
Source File: IncompleteUninstall.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder import io.netty.handler.codec.http.HttpResponseStatus final case class IncompleteUninstall( packageName: String, override val status: HttpResponseStatus = HttpResponseStatus.SERVICE_UNAVAILABLE ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Incomplete uninstall of package [$packageName] due to Mesos unavailability" } } object IncompleteUninstall { implicit val encoder: Encoder[IncompleteUninstall] = deriveEncoder }
Example 9
Source File: UnsupportedContentEncoding.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class UnsupportedContentEncoding( supported: List[String], actual: Option[String] = None ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { val acceptMsg = supported.mkString("[", ", ", "]") actual match { case Some(mt) => s"Unsupported Content-Encoding: $mt Accept-Encoding: $acceptMsg" case None => s"Unspecified Content-Encoding Accept-Encoding: $acceptMsg" } } } object UnsupportedContentEncoding { implicit val encoder: Encoder[UnsupportedContentEncoding] = deriveEncoder }
Example 10
Source File: ServiceMarathonTemplateNotFound.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.universe import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class ServiceMarathonTemplateNotFound( packageName: String, packageVersion: universe.v3.model.Version ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Package: [$packageName] version: [$packageVersion] does not have a Marathon " + "template defined and can not be rendered" } } object ServiceMarathonTemplateNotFound { implicit val encoder: Encoder[ServiceMarathonTemplateNotFound] = deriveEncoder }
Example 11
Source File: JsonParsingError.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class JsonParsingError( underlyingType : String, parsingErrorMessage: String, parsingInput: String ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = "Unable to parse the string as a JSON value" } object JsonParsingError { implicit val encoder: Encoder[JsonParsingError] = deriveEncoder }
Example 12
Source File: InstallResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v2.model import com.mesosphere.cosmos.rpc import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class InstallResponse( packageName: String, packageVersion: universe.v3.model.Version, appId: Option[AppId] = None, postInstallNotes: Option[String] = None, cli: Option[universe.v3.model.Cli] = None ) object InstallResponse { implicit val encodeV2InstallResponse: Encoder[rpc.v2.model.InstallResponse] = { deriveEncoder[rpc.v2.model.InstallResponse] } implicit val decodeV2InstallResponse: Decoder[InstallResponse] = deriveDecoder[InstallResponse] }
Example 13
Source File: DescribeResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v2.model import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class DescribeResponse( packagingVersion: universe.v3.model.PackagingVersion, name: String, version: universe.v3.model.Version, maintainer: String, description: String, tags: List[universe.v3.model.Tag] = Nil, selected: Boolean = false, scm: Option[String] = None, website: Option[String] = None, framework: Boolean = false, preInstallNotes: Option[String] = None, postInstallNotes: Option[String] = None, postUninstallNotes: Option[String] = None, licenses: Option[List[universe.v3.model.License]] = None, minDcosReleaseVersion: Option[universe.v3.model.DcosReleaseVersion] = None, marathon: Option[universe.v3.model.Marathon] = None, resource: Option[universe.v3.model.V3Resource] = None, config: Option[JsonObject] = None, command: Option[universe.v3.model.Command] = None ) object DescribeResponse { implicit val encodeV2DescribeResponse: Encoder[DescribeResponse] = { deriveEncoder[DescribeResponse] } implicit val decodeV2DescribeResponse: Decoder[DescribeResponse] = { deriveDecoder[DescribeResponse] } }
Example 14
Source File: UninstallRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class UninstallRequest( packageName: String, appId: Option[thirdparty.marathon.model.AppId], all: Option[Boolean], managerId: Option[String], packageVersion: Option[universe.v3.model.Version] ) object UninstallRequest { implicit val encodeUninstallRequest: Encoder[UninstallRequest] = deriveEncoder[UninstallRequest] implicit val decodeUninstallRequest: Decoder[UninstallRequest] = deriveDecoder[UninstallRequest] implicit val packageUninstallDecoder: MediaTypedRequestDecoder[UninstallRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.UninstallRequest)) }
Example 15
Source File: ServiceUpdateRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedEncoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ServiceUpdateRequest( appId: AppId, packageVersion: Option[universe.v3.model.Version], options: Option[JsonObject], replace: Boolean, managerId: Option[String], packageName: Option[String], currentPackageVersion: Option[universe.v3.model.Version] ) object ServiceUpdateRequest { implicit val encode: Encoder[ServiceUpdateRequest] = deriveEncoder implicit val decode: Decoder[ServiceUpdateRequest] = deriveDecoder implicit val mediaTypedEncoder: MediaTypedEncoder[ServiceUpdateRequest] = MediaTypedEncoder(MediaTypes.ServiceUpdateRequest) implicit val mediaTypedRequestDecoder: MediaTypedRequestDecoder[ServiceUpdateRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.ServiceUpdateRequest)) }
Example 16
Source File: ErrorResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.error.CosmosError import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ErrorResponse( `type`: String, message: String, data: Option[JsonObject] = None ) object ErrorResponse { implicit val encode: Encoder[ErrorResponse] = deriveEncoder implicit val decode: Decoder[ErrorResponse] = deriveDecoder def apply(error: CosmosError) : ErrorResponse = { ErrorResponse( error.getClass.getSimpleName, error.message, error.data ) } }
Example 17
Source File: ServiceUpdateResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.DispatchingMediaTypedEncoder import com.mesosphere.cosmos.finch.MediaTypedEncoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ServiceUpdateResponse( `package`: universe.v4.model.PackageDefinition, resolvedOptions: JsonObject, marathonDeploymentId: String ) object ServiceUpdateResponse { implicit val encode: Encoder[ServiceUpdateResponse] = deriveEncoder implicit val decode: Decoder[ServiceUpdateResponse] = deriveDecoder implicit val mediaTypedEncoder: MediaTypedEncoder[ServiceUpdateResponse] = MediaTypedEncoder(MediaTypes.ServiceUpdateResponse) implicit val dispatchingMediaTypedEncoder: DispatchingMediaTypedEncoder[ServiceUpdateResponse] = DispatchingMediaTypedEncoder(MediaTypes.ServiceUpdateResponse) }
Example 18
Source File: ListVersionsRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ListVersionsRequest( packageName: String, includePackageVersions: Boolean ) object ListVersionsRequest { implicit val encodeListVersionsRequest: Encoder[ListVersionsRequest] = deriveEncoder[ListVersionsRequest] implicit val decodeListVersionsRequest: Decoder[ListVersionsRequest] = deriveDecoder[ListVersionsRequest] implicit val packageListVersionsDecoder: MediaTypedRequestDecoder[ListVersionsRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.ListVersionsRequest)) }
Example 19
Source File: ServiceDescribeRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedEncoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ServiceDescribeRequest( appId: AppId, managerId: Option[String], packageName: Option[String], packageVersion: Option[universe.v3.model.Version] ) object ServiceDescribeRequest { implicit val encode: Encoder[ServiceDescribeRequest] = deriveEncoder implicit val decode: Decoder[ServiceDescribeRequest] = deriveDecoder implicit val mediaTypedEncoder: MediaTypedEncoder[ServiceDescribeRequest] = MediaTypedEncoder(MediaTypes.ServiceDescribeRequest) implicit val mediaTypedRequestDecoder: MediaTypedRequestDecoder[ServiceDescribeRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.ServiceDescribeRequest)) }
Example 20
Source File: MultipleFrameworkIds.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.universe import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class MultipleFrameworkIds( packageName: String, packageVersion: Option[universe.v2.model.PackageDetailsVersion], frameworkName: String, ids: List[String] ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { packageVersion match { case Some(ver) => s"Uninstalled package [$packageName] version [$ver]\n" + s"Unable to shutdown [$packageName] service framework with name [$frameworkName] " + s"because there are multiple framework ids matching this name: [${ids.mkString(", ")}]" case None => s"Uninstalled package [$packageName]\n" + s"Unable to shutdown [$packageName] service framework with name [$frameworkName] " + s"because there are multiple framework ids matching this name: [${ids.mkString(", ")}]" } } } object MultipleFrameworkIds { implicit val encoder: Encoder[MultipleFrameworkIds] = deriveEncoder }
Example 21
Source File: Event.scala From cuttle with Apache License 2.0 | 5 votes |
package com.criteo.cuttle.events import java.time.Instant import com.criteo.cuttle.Auth.User import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.java8.time._ sealed trait Event { def created: Instant } case class JobSuccessForced(created: Instant, createdBy: User, jobId: String, intervalStart: Instant, intervalEnd: Instant) extends Event object JobSuccessForced { implicit val encoder: Encoder[JobSuccessForced] = deriveEncoder implicit val decoder: Decoder[JobSuccessForced] = deriveDecoder } object Event { implicit val encoder: Encoder[Event] = deriveEncoder implicit val decoder: Decoder[Event] = deriveDecoder }
Example 22
Source File: PackageDetails.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.universe.v2.model import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class PackageDetails( packagingVersion: PackagingVersion, name: String, version: PackageDetailsVersion, maintainer: String, description: String, tags: List[String] = Nil, selected: Option[Boolean] = None, scm: Option[String] = None, website: Option[String] = None, framework: Option[Boolean] = None, preInstallNotes: Option[String] = None, postInstallNotes: Option[String] = None, postUninstallNotes: Option[String] = None, licenses: Option[List[License]] = None ) object PackageDetails { implicit val encodeV2PackageDetails: Encoder[PackageDetails] = deriveEncoder[PackageDetails] implicit val decodeV2PackageDetails: Decoder[PackageDetails] = deriveDecoder[PackageDetails] }
Example 23
Source File: PackageFiles.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.universe.v2.model import io.lemonlabs.uri.Uri import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder import com.mesosphere.cosmos.circe.Encoders.encodeUri import com.mesosphere.cosmos.circe.Decoders.decodeUri case class PackageFiles( revision: String, sourceUri: Uri, packageJson: PackageDetails, marathonJsonMustache: String, commandJson: Option[Command] = None, configJson: Option[JsonObject] = None, resourceJson: Option[Resource] = None ) object PackageFiles { implicit val encodeV2PackageFiles: Encoder[PackageFiles] = deriveEncoder[PackageFiles] implicit val decodeV2PackageFiles: Decoder[PackageFiles] = deriveDecoder[PackageFiles] }
Example 24
Source File: PackageCoordinate.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.universe.v1.model import fastparse.all._ import com.mesosphere.cosmos.circe.Decoders.decode import com.mesosphere.error.ResultOps import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder import io.circe.syntax._ import java.nio.charset.StandardCharsets import org.apache.commons.codec.binary.Base32 import scala.util.Try final case class PackageCoordinate(name: String, version: universe.v3.model.Version) { override def toString(): String = { PackageCoordinate.toString(this) } } object PackageCoordinate { private[this] val base32 = new Base32() implicit val encodePackageCoordinate: Encoder[PackageCoordinate] = deriveEncoder[PackageCoordinate] implicit val decodePackageCoordinate: Decoder[PackageCoordinate] = deriveDecoder[PackageCoordinate] def parse(string: String): Option[PackageCoordinate] = { parser.parse(string).fold( (_, _, _) => None, (pc, _) => Some(pc) ) } val parser: Parser[PackageCoordinate] = { CharIn('a' to 'z', '0' to '9').rep(1).!.flatMap { string => Try { val coordinate = new String( base32.decode(string.toUpperCase), StandardCharsets.UTF_8 ) decode[PackageCoordinate](coordinate).getOrThrow } fold ( _ => Fail, pc => PassWith(pc) ) } } def toString(pc: PackageCoordinate): String = { base32.encodeAsString( pc.asJson.noSpaces.getBytes(StandardCharsets.UTF_8) ).toLowerCase.replace("=", "") } }
Example 25
Source File: RepositoryUriConnection.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.rpc import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class RepositoryUriConnection( repository: rpc.v1.model.PackageRepository, cause: String ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Could not access data at URI for repository [${repository.name}]: ${repository.uri}" } } object RepositoryUriConnection { implicit val encoder: Encoder[RepositoryUriConnection] = deriveEncoder }
Example 26
Source File: CustomPackageManagerError.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class CustomPackageManagerError( managerId: String, statusCode: Int, responseContent: String ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = s"Custom manager [$managerId] returned error code [$statusCode] and response [$responseContent]" } object CustomPackageManagerError { implicit val encoder: Encoder[CustomPackageManagerError] = deriveEncoder }
Example 27
Source File: EndpointUriSyntax.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.lemonlabs.uri.Uri import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class EndpointUriSyntax( destination: Uri, cause: String ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"URI for [${destination}] has invalid syntax" } } object EndpointUriSyntax { implicit val encoder: Encoder[EndpointUriSyntax] = deriveEncoder }
Example 28
Source File: RepositoryAddIndexOutOfBounds.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class RepositoryAddIndexOutOfBounds(attempted: Int, max: Int) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { val suggestion = if (max == 0) "can be at most 0" else s"must be between 0 and $max inclusive." s"Index ($attempted) is out of range. Index value " + suggestion } } object RepositoryAddIndexOutOfBounds { implicit val encoder: Encoder[RepositoryAddIndexOutOfBounds] = deriveEncoder }
Example 29
Source File: ServiceUnavailable.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.netty.handler.codec.http.HttpResponseStatus import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class ServiceUnavailable( serviceName: String, override val status: HttpResponseStatus = HttpResponseStatus.SERVICE_UNAVAILABLE ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Unable to complete request due to service [$serviceName] unavailability" } } object ServiceUnavailable { implicit val encoder: Encoder[ServiceUnavailable] = deriveEncoder }
Example 30
Source File: ListVersionsResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.DispatchingMediaTypedEncoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.universe.v2.model.{PackageDetailsVersion, ReleaseVersion} import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ListVersionsResponse( results: Map[PackageDetailsVersion, ReleaseVersion] ) object ListVersionsResponse { implicit val encodeListVersionsResponse: Encoder[ListVersionsResponse] = deriveEncoder[ListVersionsResponse] implicit val decodeListVersionsResponse: Decoder[ListVersionsResponse] = deriveDecoder[ListVersionsResponse] implicit val packageListVersionsEncoder: DispatchingMediaTypedEncoder[ListVersionsResponse] = DispatchingMediaTypedEncoder(MediaTypes.ListVersionsResponse) }
Example 31
Source File: TimeoutError.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.twitter.util.Duration import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder import com.mesosphere.cosmos.circe.Encoders._ final case class TimeoutError( operation: String, destination: String, timeout: Duration ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = s"$operation timed out on $destination" + s" after ${timeout.inSeconds} seconds" } object TimeoutError { implicit val encoder: Encoder[TimeoutError] = deriveEncoder }
Example 32
Source File: UniverseClientHttpError.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import com.mesosphere.cosmos.rpc import io.netty.handler.codec.http.HttpResponseStatus import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder import org.jboss.netty.handler.codec.http.HttpMethod final case class UniverseClientHttpError( packageRepository: rpc.v1.model.PackageRepository, method: HttpMethod, clientStatus: HttpResponseStatus, override val status: HttpResponseStatus ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { "Unexpected upstream http error " + s"while fetching repository '${packageRepository.name}'" + s" at ${packageRepository.uri.toString}: " + s"${method.getName} ${clientStatus.code}" } } object UniverseClientHttpError { implicit val encoder: Encoder[UniverseClientHttpError] = deriveEncoder }
Example 33
Source File: GenericHttpError.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.lemonlabs.uri.Uri import io.netty.handler.codec.http.HttpResponseStatus import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder import org.jboss.netty.handler.codec.http.HttpMethod final case class GenericHttpError( method: HttpMethod = HttpMethod.GET, uri: Uri, clientStatus: HttpResponseStatus, override val status: HttpResponseStatus = HttpResponseStatus.BAD_REQUEST ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Unexpected upstream http error: ${method.getName} ${uri.toString} ${clientStatus.code}" } } object GenericHttpError { implicit val encoder: Encoder[GenericHttpError] = deriveEncoder }
Example 34
Source File: VersionUpgradeNotSupportedInOpen.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.universe import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class VersionUpgradeNotSupportedInOpen( requested: Option[universe.v3.model.Version], actual: universe.v3.model.Version ) extends CosmosError { override def message: String = s"Version Upgrades are an Enterprise DC/OS feature only" override def data: Option[JsonObject] = CosmosError.deriveData(this) } object VersionUpgradeNotSupportedInOpen { implicit val encoder: Encoder[VersionUpgradeNotSupportedInOpen] = deriveEncoder }
Example 35
Source File: RepositoryUriSyntax.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.rpc import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class RepositoryUriSyntax( repository: rpc.v1.model.PackageRepository, cause: String ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"URI for repository [${repository.name}] has invalid syntax: ${repository.uri}" } } object RepositoryUriSyntax { implicit val encoder: Encoder[RepositoryUriSyntax] = deriveEncoder }
Example 36
Source File: Unauthorized.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.cosmos.circe.Encoders._ import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder import io.netty.handler.codec.http.HttpResponseStatus final case class Unauthorized( serviceName: String, realm: Option[String], override val status: HttpResponseStatus = HttpResponseStatus.UNAUTHORIZED ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override val message: String = { s"Unable to complete request due to Unauthorized response from service [$serviceName]" } override def exception: CosmosException = { CosmosException( this, realm.map(r => Map("WWW-Authenticate" -> r)).getOrElse(Map.empty), None ) } } object Unauthorized { implicit val encoder: Encoder[Unauthorized] = deriveEncoder }
Example 37
Source File: UnsupportedContentType.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.http.MediaType import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class UnsupportedContentType( supported: List[MediaType], actual: Option[String] = None ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { val acceptMsg = supported.map(_.show).mkString("[", ", ", "]") actual match { case Some(mt) => s"Unsupported Content-Type: $mt Accept: $acceptMsg" case None => s"Unspecified Content-Type Accept: $acceptMsg" } } } object UnsupportedContentType { def forMediaType( supported: List[MediaType], actual: Option[MediaType] ): UnsupportedContentType = { new UnsupportedContentType(supported, actual.map(_.show)) } implicit val encoder: Encoder[UnsupportedContentType] = deriveEncoder }
Example 38
Source File: VersionNotFound.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.error import com.mesosphere.universe import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveEncoder final case class VersionNotFound( packageName: String, packageVersion: universe.v3.model.Version ) extends CosmosError { override def data: Option[JsonObject] = CosmosError.deriveData(this) override def message: String = { s"Version [$packageVersion] of package [$packageName] not found" } } object VersionNotFound { implicit val encoder: Encoder[VersionNotFound] = deriveEncoder }
Example 39
Source File: PromoteChatMember.scala From canoe with MIT License | 5 votes |
package canoe.methods.chats import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.{ChatId, InputFile} import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} final case class PromoteChatMember(chatId: ChatId, userId: Int, canChangeInfo: Option[Boolean] = None, canPostMessages: Option[Boolean] = None, canEditMessages: Option[Boolean] = None, canDeleteMessages: Option[Boolean] = None, canInviteUsers: Option[Boolean] = None, canRestrictMembers: Option[Boolean] = None, canPinMessages: Option[Boolean] = None, canPromoteMembers: Option[Boolean] = None) object PromoteChatMember { implicit val method: Method[PromoteChatMember, Boolean] = new Method[PromoteChatMember, Boolean] { def name: String = "promoteChatMember" def encoder: Encoder[PromoteChatMember] = deriveEncoder[PromoteChatMember].snakeCase def decoder: Decoder[Boolean] = Decoder.decodeBoolean def attachments(request: PromoteChatMember): List[(String, InputFile)] = Nil } }
Example 40
Source File: HeroFragmentQuery.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object HeroFragmentQuery { object HeroFragmentQuery extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query HeroFragmentQuery { hero { ...CharacterInfo } human(id: "Lea") { ...CharacterInfo } } fragment CharacterInfo on Character { name }""" case class Variables() object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(hero: Hero, human: Option[Human]) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Hero(name: Option[String]) extends CharacterInfo object Hero { implicit val jsonDecoder: Decoder[Hero] = deriveDecoder[Hero] implicit val jsonEncoder: Encoder[Hero] = deriveEncoder[Hero] } case class Human(name: Option[String]) extends CharacterInfo object Human { implicit val jsonDecoder: Decoder[Human] = deriveDecoder[Human] implicit val jsonEncoder: Encoder[Human] = deriveEncoder[Human] } } }
Example 41
Source File: ContractId.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.values import cats.Eq import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import org.adridadou.openlaw.oracles.CryptoService import org.adridadou.openlaw.parser.template.variableTypes.{ EthereumAddress, EthereumData } @SerialVersionUID(7843732947346776640L) final case class ContractId(id: String) { def stopContract(cryptoService: CryptoService): EthereumData = executionId("_stop_contract", cryptoService) def data: EthereumData = EthereumData(id) def resumeContract(cryptoService: CryptoService): EthereumData = executionId("_resume_contract", cryptoService) def executionId(command: String, crypto: CryptoService): EthereumData = EthereumData(id + EthereumData(crypto.sha256("_" + command)).toString) override def toString(): String = id } @SerialVersionUID(7843732947346776640L) object ContractId { def apply(data: Array[Byte]): ContractId = ContractId(EthereumAddress.bytes2hex(data)) implicit val contractIdEnc: Encoder[ContractId] = deriveEncoder implicit val contractIdDec: Decoder[ContractId] = deriveDecoder implicit val contractEq: Eq[ContractId] = Eq.fromUniversalEquals }
Example 42
Source File: TemplateId.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.values import cats.Eq import io.circe.{Decoder, Encoder, HCursor, Json, KeyDecoder, KeyEncoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import cats.implicits._ import org.adridadou.openlaw.parser.template.variableTypes.EthereumAddress final case class TemplateId(id: String = "") extends Comparable[TemplateId] { override def toString: String = id override def compareTo(o: TemplateId): Int = id.compareTo(o.id) } object TemplateId { def apply(data: Array[Byte]): TemplateId = TemplateId(EthereumAddress.bytes2hex(data)) implicit val templateIdEnc: Encoder[TemplateId] = deriveEncoder implicit val templateIdDec: Decoder[TemplateId] = deriveDecoder implicit val eq: Eq[TemplateId] = Eq.by(_.id) } final case class TemplateIdentifier(title: TemplateTitle, version: Int) final case class TemplateTitle(originalTitle: String, title: String) { override def toString: String = title override def equals(obj: Any): Boolean = obj match { case other: TemplateTitle => this === other case _ => false } override def hashCode(): Int = this.title.hashCode } object TemplateTitle { def apply(): TemplateTitle = TemplateTitle("") def apply(title: String): TemplateTitle = TemplateTitle(originalTitle = title, title = title.toLowerCase()) implicit val eq: Eq[TemplateTitle] = (x: TemplateTitle, y: TemplateTitle) => x.title === y.title implicit val templateTitleEnc: Encoder[TemplateTitle] = (a: TemplateTitle) => Json.fromString(a.originalTitle) implicit val templateTitleDec: Decoder[TemplateTitle] = (c: HCursor) => (for { title <- c.downField("title").as[String] } yield TemplateTitle(title)) match { case Right(title) => Right(title) case Left(_) => c.as[String].map(TemplateTitle(_)) } implicit val templateTitleKeyEnc: KeyEncoder[TemplateTitle] = (key: TemplateTitle) => key.title implicit val templateTitleKeyDec: KeyDecoder[TemplateTitle] = (key: String) => Some(TemplateTitle(key)) }
Example 43
Source File: LinkType.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.parser.template.variableTypes import cats.implicits._ import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.parser.decode import org.adridadou.openlaw.{OpenlawNativeValue, OpenlawString, OpenlawValue} import org.adridadou.openlaw.parser.template.formatters.Formatter import org.adridadou.openlaw.parser.template._ import org.adridadou.openlaw.parser.template.expressions.Expression import org.adridadou.openlaw.result.{Failure, FailureException, Result, Success} object LinkInfo { implicit val linkInfoEnc: Encoder[LinkInfo] = deriveEncoder implicit val linkInfoDec: Decoder[LinkInfo] = deriveDecoder } final case class LinkInfo(label: String, url: String) extends OpenlawNativeValue case object LinkType extends VariableType(name = "Link") with NoShowInFormButRender { override def cast( value: String, executionResult: TemplateExecutionResult ): Result[LinkInfo] = decode[LinkInfo](value).leftMap(FailureException(_)) override def internalFormat(value: OpenlawValue): Result[String] = VariableType.convert[OpenlawString](value) override def defaultFormatter: Formatter = new LinkFormatter override def getTypeClass: Class[LinkInfo] = classOf[LinkInfo] override def construct( constructorParams: Parameter, executionResult: TemplateExecutionResult ): Result[Option[LinkInfo]] = constructorParams match { case Parameters(seq) => val map = seq.toMap for { label <- map.get("label").traverse(getOneValueConstant) url <- map.get("url").traverse(getOneValueConstant) } yield (label, url) mapN { LinkInfo(_, _) } case _ => Failure("""Link requires parameters, not a unique value or a list""") } def thisType: VariableType = LinkType private def getOneValueConstant(value: Parameter): Result[String] = value match { case OneValueParameter(StringConstant(v)) => Success(v) case _ => Failure("""Link requires "label" argument.""") } } class LinkFormatter extends Formatter { override def format( expression: Expression, value: OpenlawValue, executionResult: TemplateExecutionResult ): Result[List[AgreementElement]] = VariableType.convert[LinkInfo](value) map { case LinkInfo(labelValue, urlValue) => List(Link(labelValue, urlValue)) } override def missingValueFormat( expression: Expression ): List[AgreementElement] = List(FreeText(Text(s"[[$expression]]"))) override def stringFormat( expression: Expression, value: OpenlawValue, executionResult: TemplateExecutionResult ): Result[String] = VariableType.convert[LinkInfo](value) map { case LinkInfo(labelValue, urlValue) => s"$labelValue[$urlValue]" } }
Example 44
Source File: SectionType.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.parser.template.variableTypes import cats.implicits._ import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.parser.decode import org.adridadou.openlaw.{OpenlawNativeValue, OpenlawString, OpenlawValue} import org.adridadou.openlaw.parser.template.formatters.Formatter import org.adridadou.openlaw.parser.template._ import org.adridadou.openlaw.parser.template.expressions.Expression import org.adridadou.openlaw.result.{Failure, FailureException, Result, Success} final case class SectionInfo( name: Option[String], numbering: String, value: String ) extends OpenlawNativeValue case object SectionType extends VariableType(name = "Section") with NoShowInFormButRender { private implicit val enc: Encoder[SectionInfo] = deriveEncoder private implicit val dec: Decoder[SectionInfo] = deriveDecoder override def cast( value: String, executionResult: TemplateExecutionResult ): Result[SectionInfo] = decode[SectionInfo](value).leftMap(FailureException(_)) override def internalFormat(value: OpenlawValue): Result[String] = value match { case SectionInfo(_, _, value) => Success(value) case value => VariableType.convert[OpenlawString](value) } override def defaultFormatter: Formatter = new SectionFormatter override def getTypeClass: Class[SectionInfo] = classOf[SectionInfo] override def construct( constructorParams: Parameter, executionResult: TemplateExecutionResult ): Result[Option[SectionInfo]] = constructorParams match { case Parameters(seq) => val map = seq.toMap (for { numbering <- map.get("numbering") reference <- map.get("reference value") } yield for { numberingValue <- getOneValueConstant(numbering) referenceValue <- getOneValueConstant(reference) } yield SectionInfo(None, numberingValue, referenceValue)).sequence case _ => Failure("""Section requires parameters, not a unique value or a list""") } def thisType: VariableType = SectionType private def getOneValueConstant(value: Parameter): Result[String] = value match { case OneValueParameter(StringConstant(v)) => Success(v) case _ => Failure("""Section requires "numbering" argument.""") } } class SectionFormatter extends Formatter { override def format( expression: Expression, value: OpenlawValue, executionResult: TemplateExecutionResult ): Result[List[AgreementElement]] = VariableType.convert[SectionInfo](value) map { case SectionInfo(_, _, referenceValue) => List(FreeText(Text(referenceValue))) } override def missingValueFormat( expression: Expression ): List[AgreementElement] = List(FreeText(Text(s"[[$expression]]"))) override def stringFormat( expression: Expression, value: OpenlawValue, executionResult: TemplateExecutionResult ): Result[String] = VariableType.convert[SectionInfo](value) map { case SectionInfo(_, _, referenceValue) => referenceValue } override def missingValueString( expression: Expression ): String = ??? }
Example 45
Source File: VariableAliasing.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.parser.template import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import org.adridadou.openlaw.OpenlawValue import org.adridadou.openlaw.parser.template.variableTypes.VariableType import org.adridadou.openlaw.parser.template.expressions.Expression import org.adridadou.openlaw.result.{Result, Success} object VariableAliasing { implicit val variableAliasingEnc: Encoder[VariableAliasing] = deriveEncoder implicit val variableAliasingDec: Decoder[VariableAliasing] = deriveDecoder } final case class VariableAliasing(name: VariableName, expr: Expression) extends Expression with TemplatePart { def validate(executionResult: TemplateExecutionResult): Result[Unit] = if (name.isAnonymous) { Success.unit } else { expr.validate(executionResult) } override def expressionType( executionResult: TemplateExecutionResult ): Result[VariableType] = expr.expressionType(executionResult) override def evaluate( executionResult: TemplateExecutionResult ): Result[Option[OpenlawValue]] = expr.evaluate(executionResult) override def variables( executionResult: TemplateExecutionResult ): Result[List[VariableName]] = expr.variables(executionResult) override def missingInput( executionResult: TemplateExecutionResult ): Result[List[VariableName]] = expr.missingInput(executionResult) }
Example 46
Source File: Json.scala From scala-steward with Apache License 2.0 | 5 votes |
package org.scalasteward.core.bitbucketserver.http4s import cats.data.NonEmptyList import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} import org.http4s.Uri import org.scalasteward.core.git.Sha1 import org.scalasteward.core.vcs.data.PullRequestState object Json { case class Page[A](values: List[A]) case class Repo(id: Int, name: String, forkable: Boolean, project: Project, links: Links) case class Project(key: String) type Links = Map[String, NonEmptyList[Link]] case class Link(href: Uri, name: Option[String]) case class PR(title: String, state: PullRequestState, links: Links) case class NewPR( title: String, description: String, state: PullRequestState, open: Boolean, closed: Boolean, fromRef: Ref, toRef: Ref, locked: Boolean, reviewers: List[Reviewer] ) case class Ref(id: String, repository: Repository) case class Repository(slug: String, project: Project) case class Condition(reviewers: List[DefaultReviewer]) case class DefaultReviewer(name: String) case class Reviewer(user: User) case class User(name: String) case class Branches(values: NonEmptyList[Branch]) case class Branch(id: String, latestCommit: Sha1) implicit def pageDecode[A: Decoder]: Decoder[Page[A]] = deriveDecoder implicit val repoDecode: Decoder[Repo] = deriveDecoder implicit val projectDecode: Decoder[Project] = deriveDecoder implicit val linkDecoder: Decoder[Link] = deriveDecoder implicit val uriDecoder: Decoder[Uri] = Decoder.decodeString.map(Uri.unsafeFromString) implicit val prDecoder: Decoder[PR] = deriveDecoder implicit val reviewerDecoder: Decoder[Reviewer] = deriveDecoder implicit val userDecoder: Decoder[User] = deriveDecoder implicit val defaultReviewerDecoder: Decoder[DefaultReviewer] = deriveDecoder implicit val conditionDecoder: Decoder[Condition] = deriveDecoder implicit val branchDecoder: Decoder[Branch] = deriveDecoder implicit val branchesDecoder: Decoder[Branches] = deriveDecoder implicit val encodeNewPR: Encoder[NewPR] = deriveEncoder implicit val encodeRef: Encoder[Ref] = deriveEncoder implicit val encodeRepository: Encoder[Repository] = deriveEncoder implicit val encodeProject: Encoder[Project] = deriveEncoder implicit val encodeReviewer: Encoder[Reviewer] = deriveEncoder implicit val encodeUser: Encoder[User] = deriveEncoder }
Example 47
Source File: CommandsEndpoints.scala From endpoints4s with MIT License | 5 votes |
package cqrs.commands import java.time.Instant import java.util.UUID import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} //#endpoints import endpoints4s.algebra.Endpoints import endpoints4s.algebra.circe.JsonEntitiesFromCodecs trait CommandsEndpoints extends Endpoints with JsonEntitiesFromCodecs { //#microservice-endpoint-description case class AddRecord(meterId: UUID, date: Instant, value: BigDecimal) extends UpdateCommand object Command { implicit val decoder: Decoder[Command] = deriveDecoder implicit val encoder: Encoder[Command] = deriveEncoder } case class StoredEvent(timestamp: Long, event: Event) object StoredEvent { implicit val decoder: Decoder[StoredEvent] = deriveDecoder implicit val encoder: Encoder[StoredEvent] = deriveEncoder } sealed trait Event case class MeterCreated(id: UUID, label: String) extends Event case class RecordAdded(id: UUID, date: Instant, value: BigDecimal) extends Event object Event { implicit val decoder: Decoder[Event] = deriveDecoder implicit val encoder: Encoder[Event] = deriveEncoder }
Example 48
Source File: QueriesEndpoints.scala From endpoints4s with MIT License | 5 votes |
package cqrs.queries import java.util.UUID import endpoints4s.algebra.{BuiltInErrors, MuxEndpoints, MuxRequest, circe} import io.circe.{Decoder, Encoder, Json} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} // TODO Enrich with failure information //#mux-responses sealed trait QueryResp case class MaybeResource(value: Option[Meter]) extends QueryResp case class ResourceList(value: List[Meter]) extends QueryResp //#mux-responses object QueryResp { implicit val queryDecoder: Decoder[QueryResp] = deriveDecoder implicit val queryEncoder: Encoder[QueryResp] = deriveEncoder }
Example 49
Source File: EpisodeEnumTypes.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } object types { sealed trait Episode object Episode { case object NEWHOPE extends Episode case object EMPIRE extends Episode case object JEDI extends Episode implicit val jsonDecoder: Decoder[Episode] = Decoder.decodeString.emap({ case "NEWHOPE" => Right(NEWHOPE) case "EMPIRE" => Right(EMPIRE) case "JEDI" => Right(JEDI) case other => Left("invalid enum value: " + other) }) implicit val jsonEncoder: Encoder[Episode] = Encoder.encodeString.contramap({ case NEWHOPE => "NEWHOPE" case EMPIRE => "EMPIRE" case JEDI => "JEDI" }) } }
Example 50
Source File: SetGameScore.scala From canoe with MIT License | 5 votes |
package canoe.methods.games import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.messages.TelegramMessage import canoe.models.{ChatId, InputFile} import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} def inlined(inlineMessageId: String, userId: Int, score: Long, force: Option[Boolean] = None, disableEditMessage: Option[Boolean] = None): SetGameScore = new SetGameScore(userId, score, force, disableEditMessage, inlineMessageId = Some(inlineMessageId)) implicit val method: Method[SetGameScore, Either[Boolean, TelegramMessage]] = new Method[SetGameScore, Either[Boolean, TelegramMessage]] { def name: String = "setGameScore" def encoder: Encoder[SetGameScore] = deriveEncoder[SetGameScore].snakeCase def decoder: Decoder[Either[Boolean, TelegramMessage]] = Decoder.decodeBoolean.either(TelegramMessage.telegramMessageDecoder) def attachments(request: SetGameScore): List[(String, InputFile)] = Nil } }
Example 51
Source File: EditMessageMedia.scala From canoe with MIT License | 5 votes |
package canoe.methods.messages import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.messages.TelegramMessage import canoe.models.{ChatId, InlineKeyboardMarkup, InputFile, InputMedia} import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} def inlined(inlineMessageId: String, media: InputMedia, replyMarkup: Option[InlineKeyboardMarkup] = None): EditMessageMedia = new EditMessageMedia(None, None, Some(inlineMessageId), media, replyMarkup) implicit val method: Method[EditMessageMedia, Either[Boolean, TelegramMessage]] = new Method[EditMessageMedia, Either[Boolean, TelegramMessage]] { import io.circe.generic.auto._ def name: String = "editMessageMedia" def encoder: Encoder[EditMessageMedia] = deriveEncoder[EditMessageMedia].snakeCase def decoder: Decoder[Either[Boolean, TelegramMessage]] = Decoder.decodeBoolean.either(TelegramMessage.telegramMessageDecoder) def attachments(request: EditMessageMedia): List[(String, InputFile)] = request.media.files } }
Example 52
Source File: EditMessageLiveLocation.scala From canoe with MIT License | 5 votes |
package canoe.methods.messages import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.messages.TelegramMessage import canoe.models.{ChatId, InlineKeyboardMarkup, InputFile} import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} def inlined(inlineMessageId: Int, lat: Double, long: Double, replyMarkup: Option[InlineKeyboardMarkup] = None): EditMessageLiveLocation = new EditMessageLiveLocation(None, None, Some(inlineMessageId), lat, long, replyMarkup) implicit val method: Method[EditMessageLiveLocation, Either[Boolean, TelegramMessage]] = new Method[EditMessageLiveLocation, Either[Boolean, TelegramMessage]] { import io.circe.generic.auto._ def name: String = "editMessageLiveLocation" def encoder: Encoder[EditMessageLiveLocation] = deriveEncoder[EditMessageLiveLocation].snakeCase def decoder: Decoder[Either[Boolean, TelegramMessage]] = Decoder.decodeBoolean.either(TelegramMessage.telegramMessageDecoder) def attachments(request: EditMessageLiveLocation): List[(String, InputFile)] = Nil } }
Example 53
Source File: EditMessageText.scala From canoe with MIT License | 5 votes |
package canoe.methods.messages import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.ParseMode.ParseMode import canoe.models.messages.TelegramMessage import canoe.models.{ChatId, InputFile, ReplyMarkup} import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} def inlined(inlineMessageId: String, text: String, parseMode: Option[ParseMode] = None, disableWebPagePreview: Option[Boolean] = None, replyMarkup: Option[ReplyMarkup] = None): EditMessageText = new EditMessageText(None, None, Some(inlineMessageId), text, parseMode, disableWebPagePreview, replyMarkup) implicit val method: Method[EditMessageText, Either[Boolean, TelegramMessage]] = new Method[EditMessageText, Either[Boolean, TelegramMessage]] { import io.circe.generic.auto._ def name: String = "editMessageText" def encoder: Encoder[EditMessageText] = deriveEncoder[EditMessageText].snakeCase def decoder: Decoder[Either[Boolean, TelegramMessage]] = Decoder.decodeBoolean.either(TelegramMessage.telegramMessageDecoder) def attachments(request: EditMessageText): List[(String, InputFile)] = Nil } }
Example 54
Source File: EditMessageCaption.scala From canoe with MIT License | 5 votes |
package canoe.methods.messages import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.ParseMode.ParseMode import canoe.models.messages.TelegramMessage import canoe.models.{ChatId, InputFile, ReplyMarkup} import io.circe.generic.auto._ import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} def inlined(inlineMessageId: String, caption: Option[String], parseMode: Option[ParseMode] = None, replyMarkup: Option[ReplyMarkup] = None): EditMessageCaption = new EditMessageCaption(None, None, Some(inlineMessageId), caption, parseMode, replyMarkup) implicit val method: Method[EditMessageCaption, Either[Boolean, TelegramMessage]] = new Method[EditMessageCaption, Either[Boolean, TelegramMessage]] { def name: String = "editMessageCaption" def encoder: Encoder[EditMessageCaption] = deriveEncoder[EditMessageCaption].snakeCase def decoder: Decoder[Either[Boolean, TelegramMessage]] = Decoder.decodeBoolean.either(TelegramMessage.telegramMessageDecoder) def attachments(request: EditMessageCaption): List[(String, InputFile)] = Nil } }
Example 55
Source File: SendMediaGroup.scala From canoe with MIT License | 5 votes |
package canoe.methods.messages import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.messages.TelegramMessage import canoe.models.{ChatId, InputFile, InputMedia} import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} final case class SendMediaGroup(chatId: ChatId, media: List[InputMedia], disableNotification: Option[Boolean] = None, replyToMessageId: Option[Int] = None) object SendMediaGroup { import io.circe.generic.auto._ implicit val method: Method[SendMediaGroup, List[TelegramMessage]] = new Method[SendMediaGroup, List[TelegramMessage]] { def name: String = "sendMediaGroup" def encoder: Encoder[SendMediaGroup] = deriveEncoder[SendMediaGroup] .contramap[SendMediaGroup]( s => s.copy(media = s.media.filter(_.media match { case InputFile.Upload(_, _) => false case InputFile.Existing(_) => true })) ) .snakeCase def decoder: Decoder[List[TelegramMessage]] = Decoder.decodeList(TelegramMessage.telegramMessageDecoder) def attachments(request: SendMediaGroup): List[(String, InputFile)] = request.media.flatMap(_.files) } }
Example 56
Source File: AnswerInlineQuery.scala From canoe with MIT License | 5 votes |
package canoe.methods.queries import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.{InlineQueryResult, InputFile} import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} final case class AnswerInlineQuery(inlineQueryId: String, results: Seq[InlineQueryResult], cacheTime: Option[Int] = None, isPersonal: Option[Boolean] = None, nextOffset: Option[String] = None, switchPmText: Option[String] = None, switchPmParameter: Option[String] = None) object AnswerInlineQuery { import io.circe.generic.auto._ implicit val method: Method[AnswerInlineQuery, Boolean] = new Method[AnswerInlineQuery, Boolean] { def name: String = "answerInlineQuery" def encoder: Encoder[AnswerInlineQuery] = deriveEncoder[AnswerInlineQuery].snakeCase def decoder: Decoder[Boolean] = Decoder.decodeBoolean def attachments(request: AnswerInlineQuery): List[(String, InputFile)] = Nil } }
Example 57
Source File: AddStickerToSet.scala From canoe with MIT License | 5 votes |
package canoe.methods.stickers import canoe.marshalling.codecs._ import canoe.methods.Method import canoe.models.{InputFile, MaskPosition} import io.circe.generic.semiauto.deriveEncoder import io.circe.{Decoder, Encoder} import cats.instances.option._ import cats.syntax.all._ def animated(userId: Int, name: String, sticker: InputFile, emojis: String, maskPosition: Option[MaskPosition] ): AddStickerToSet = new AddStickerToSet(userId, name, None, Some(sticker), emojis, maskPosition) import io.circe.generic.auto._ implicit val method: Method[AddStickerToSet, Boolean] = new Method[AddStickerToSet, Boolean] { def name: String = "addStickerToSet" def encoder: Encoder[AddStickerToSet] = deriveEncoder[AddStickerToSet].snakeCase def decoder: Decoder[Boolean] = Decoder.decodeBoolean def attachments(request: AddStickerToSet): List[(String, InputFile)] = List(request.pngSticker.tupleLeft("png_sticker"), request.tgsSticker.tupleLeft("tgs_sticker")).flatten } }
Example 58
Source File: ServiceDescribeResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.DispatchingMediaTypedEncoder import com.mesosphere.cosmos.finch.MediaTypedEncoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ServiceDescribeResponse( `package`: universe.v4.model.PackageDefinition, upgradesTo: List[universe.v3.model.Version], downgradesTo: List[universe.v3.model.Version], resolvedOptions: Option[JsonObject], userProvidedOptions: Option[JsonObject] ) object ServiceDescribeResponse { implicit val encode: Encoder[ServiceDescribeResponse] = deriveEncoder implicit val decode: Decoder[ServiceDescribeResponse] = deriveDecoder implicit val mediaTypedEncoder: MediaTypedEncoder[ServiceDescribeResponse] = MediaTypedEncoder(MediaTypes.ServiceDescribeResponse) implicit val dispatchingMediaTypedEncoder: DispatchingMediaTypedEncoder[ServiceDescribeResponse] = DispatchingMediaTypedEncoder(MediaTypes.ServiceDescribeResponse) }
Example 59
Source File: ListRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ListRequest( packageName: Option[String] = None, appId: Option[AppId] = None ) object ListRequest { implicit val encodeListRequest: Encoder[ListRequest] = deriveEncoder[ListRequest] implicit val decodeListRequest: Decoder[ListRequest] = deriveDecoder[ListRequest] implicit val packageListDecoder: MediaTypedRequestDecoder[ListRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.ListRequest)) }
Example 60
Source File: SearchResult.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class SearchResult( name: String, currentVersion: universe.v3.model.Version, versions: Map[universe.v3.model.Version, universe.v3.model.ReleaseVersion], description: String, framework: Boolean, tags: List[universe.v3.model.Tag], selected: Option[Boolean] = None, images: Option[universe.v3.model.Images] = None ) object SearchResult { implicit val encodeSearchResult: Encoder[SearchResult] = deriveEncoder[SearchResult] implicit val decodeSearchResult: Decoder[SearchResult] = deriveDecoder[SearchResult] }
Example 61
Source File: InstallRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class InstallRequest( packageName: String, packageVersion: Option[PackageDetailsVersion], options: Option[JsonObject], appId: Option[AppId], managerId: Option[String] ) object InstallRequest { implicit val encodeInstallRequest: Encoder[InstallRequest] = deriveEncoder[InstallRequest] implicit val decodeInstallRequest: Decoder[InstallRequest] = deriveDecoder[InstallRequest] implicit val packageInstallDecoder: MediaTypedRequestDecoder[InstallRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.InstallRequest)) }
Example 62
Source File: RenderRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class RenderRequest( packageName: String, packageVersion: Option[PackageDetailsVersion] = None, options: Option[JsonObject] = None, appId: Option[AppId] = None ) object RenderRequest{ implicit val encodeRenderRequest: Encoder[RenderRequest] = deriveEncoder[RenderRequest] implicit val decodeRenderRequest: Decoder[RenderRequest] = deriveDecoder[RenderRequest] implicit val packageRenderDecoder: MediaTypedRequestDecoder[RenderRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.RenderRequest)) }
Example 63
Source File: UninstallResult.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class UninstallResult( packageName: String, appId: AppId, packageVersion: Option[PackageDetailsVersion], postUninstallNotes: Option[String] ) object UninstallResult { implicit val encodeUninstallResult: Encoder[UninstallResult] = deriveEncoder[UninstallResult] implicit val decodeUninstallResult: Decoder[UninstallResult] = deriveDecoder[UninstallResult] }
Example 64
Source File: InstalledPackageInformationPackageDetails.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class InstalledPackageInformationPackageDetails( packagingVersion: universe.v2.model.PackagingVersion, name: String, version: universe.v2.model.PackageDetailsVersion, maintainer: String, description: String, tags: List[String] = Nil, selected: Option[Boolean] = None, scm: Option[String] = None, website: Option[String] = None, framework: Option[Boolean] = None, preInstallNotes: Option[String] = None, postInstallNotes: Option[String] = None, postUninstallNotes: Option[String] = None, licenses: Option[List[universe.v2.model.License]] = None ) object InstalledPackageInformationPackageDetails { implicit val encodeInstalledPackageInformationPackageDetails: Encoder[InstalledPackageInformationPackageDetails] = { deriveEncoder[InstalledPackageInformationPackageDetails] } implicit val decodeInstalledPackageInformationPackageDetails: Decoder[InstalledPackageInformationPackageDetails] = { deriveDecoder[InstalledPackageInformationPackageDetails] } }
Example 65
Source File: DescribeRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class DescribeRequest( packageName: String, packageVersion: Option[PackageDetailsVersion] ) object DescribeRequest { implicit val encodeDescribeRequest: Encoder[DescribeRequest] = deriveEncoder[DescribeRequest] implicit val decodeDescribeRequest: Decoder[DescribeRequest] = deriveDecoder[DescribeRequest] implicit val packageDescribeDecoder: MediaTypedRequestDecoder[DescribeRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.DescribeRequest)) }
Example 66
Source File: InstallResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.DispatchingMediaTypedEncoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class InstallResponse( packageName: String, packageVersion: PackageDetailsVersion, appId: AppId ) object InstallResponse { implicit val encodeInstallResponse: Encoder[InstallResponse] = deriveEncoder[InstallResponse] implicit val decodeInstallResponse: Decoder[InstallResponse] = deriveDecoder[InstallResponse] implicit val packageInstallV1Encoder: DispatchingMediaTypedEncoder[InstallResponse] = DispatchingMediaTypedEncoder(MediaTypes.V1InstallResponse) }
Example 67
Source File: IssuesReportSerializer.scala From codacy-analysis-cli with GNU Affero General Public License v3.0 | 5 votes |
package com.codacy.analysis.core.serializer import java.nio.file.Path import com.codacy.analysis.core.model.IssuesAnalysis.FileResults import com.codacy.analysis.core.model.{Issue, IssuesAnalysis, Location, ToolResult, ToolResults} import com.codacy.plugins.api.results import io.circe.{Encoder, Printer} import io.circe.generic.semiauto.deriveEncoder import io.circe.syntax._ object IssuesReportSerializer { private[IssuesReportSerializer] implicit val levelEncoder: Encoder[results.Result.Level.Value] = Encoder.encodeEnumeration(results.Result.Level) private[IssuesReportSerializer] implicit val categoryEncoder: Encoder[results.Pattern.Category.Value] = Encoder.encodeEnumeration(results.Pattern.Category) private[IssuesReportSerializer] implicit val pathEncoder: Encoder[Path] = Encoder.encodeString.contramap(_.toString) private[IssuesReportSerializer] implicit val toolResultsEncoder: Encoder[ToolResults] = deriveEncoder private[IssuesReportSerializer] implicit val issuesAnalysisEncoder: Encoder[IssuesAnalysis] = deriveEncoder private[IssuesReportSerializer] implicit val issueResultEncoder: Encoder[Issue] = deriveEncoder private[IssuesReportSerializer] implicit val patternIdEncoder: Encoder[results.Pattern.Id] = deriveEncoder private[IssuesReportSerializer] implicit val issueMessageEncoder: Encoder[Issue.Message] = deriveEncoder private[IssuesReportSerializer] implicit val issueLocationEncoder: Encoder[Location] = deriveEncoder private[IssuesReportSerializer] implicit val resultEncoder: Encoder[ToolResult] = deriveEncoder private[IssuesReportSerializer] implicit val fileResultsEncoder: Encoder[FileResults] = deriveEncoder def toJsonString(toolResults: Set[ToolResults]): String = toolResults.asJson.printWith(Printer.noSpaces.copy(dropNullValues = true)) }
Example 68
Source File: TargetSettings.scala From scylla-migrator with Apache License 2.0 | 5 votes |
package com.scylladb.migrator.config import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } case class TargetSettings(host: String, port: Int, credentials: Option[Credentials], keyspace: String, table: String, connections: Option[Int]) object TargetSettings { implicit val encoder: Encoder[TargetSettings] = deriveEncoder[TargetSettings] implicit val decoder: Decoder[TargetSettings] = deriveDecoder[TargetSettings] }
Example 69
Source File: MigratorConfig.scala From scylla-migrator with Apache License 2.0 | 5 votes |
package com.scylladb.migrator.config import cats.implicits._ import com.datastax.spark.connector.rdd.partitioner.dht.{ BigIntToken, LongToken, Token } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import io.circe.syntax._ import io.circe.yaml.parser import io.circe.yaml.syntax._ import io.circe.{ Decoder, DecodingFailure, Encoder, Error, Json } case class MigratorConfig(source: SourceSettings, target: TargetSettings, renames: List[Rename], savepoints: Savepoints, skipTokenRanges: Set[(Token[_], Token[_])], validation: Validation) { def render: String = this.asJson.asYaml.spaces2 } object MigratorConfig { implicit val tokenEncoder: Encoder[Token[_]] = Encoder.instance { case LongToken(value) => Json.obj("type" := "long", "value" := value) case BigIntToken(value) => Json.obj("type" := "bigint", "value" := value) } implicit val tokenDecoder: Decoder[Token[_]] = Decoder.instance { cursor => for { tpe <- cursor.get[String]("type").right result <- tpe match { case "long" => cursor.get[Long]("value").right.map(LongToken(_)) case "bigint" => cursor.get[BigInt]("value").right.map(BigIntToken(_)) case otherwise => Left(DecodingFailure(s"Unknown token type '$otherwise'", Nil)) } } yield result } implicit val migratorConfigDecoder: Decoder[MigratorConfig] = deriveDecoder[MigratorConfig] implicit val migratorConfigEncoder: Encoder[MigratorConfig] = deriveEncoder[MigratorConfig] def loadFrom(path: String): MigratorConfig = { val configData = scala.io.Source.fromFile(path).mkString parser .parse(configData) .leftWiden[Error] .flatMap(_.as[MigratorConfig]) .valueOr(throw _) } }
Example 70
Source File: ColorBar.scala From evilplot with BSD 3-Clause "New" or "Revised" License | 5 votes |
package com.cibo.evilplot.colors import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} sealed trait ColorBar { val nColors: Int def getColor(z: Int): Color } // Use when one color is wanted but a ColorBar is needed. case class SingletonColorBar(color: Color) extends ColorBar { val nColors: Int = 1 def getColor(z: Int): Color = { require(z == 1) color } } // Map a sequence of colors to a continuous variable z. case class ScaledColorBar(colorSeq: Seq[Color], zMin: Double, zMax: Double) extends ColorBar { val nColors: Int = colorSeq.length private val zWidth = (zMax - zMin) / nColors.toFloat def getColor(i: Int): Color = colorSeq(i) def getColor(z: Double): Color = getColor(colorIndex(z)) def colorIndex(z: Double): Int = math.min(math.round(math.floor(math.max(z - zMin, 0.0) / zWidth)).toInt, nColors - 1) def colorValue(i: Int): Double = i * zWidth + zMin } object ColorBar { implicit val encoder: Encoder[ColorBar] = deriveEncoder[ColorBar] implicit val decoder: Decoder[ColorBar] = deriveDecoder[ColorBar] }
Example 71
Source File: EpisodeEnum.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object EpisodeEnum { object EpisodeEnum extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query EpisodeEnum { hero { name appearsIn } }""" case class Variables() object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(hero: Hero) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Hero(name: Option[String], appearsIn: Option[List[Option[Episode]]]) object Hero { implicit val jsonDecoder: Decoder[Hero] = deriveDecoder[Hero] implicit val jsonEncoder: Encoder[Hero] = deriveEncoder[Hero] } } }
Example 72
Source File: HeroNameQuery.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object HeroNameQuery { object HeroNameQuery extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query HeroNameQuery { hero { name } }""" case class Variables() object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(hero: Hero) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Hero(name: Option[String]) object Hero { implicit val jsonDecoder: Decoder[Hero] = deriveDecoder[Hero] implicit val jsonEncoder: Encoder[Hero] = deriveEncoder[Hero] } } }
Example 73
Source File: SearchQuery.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object SearchQuery { object SearchQuery extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query SearchQuery($$text: String!) { search(text: $$text) { __typename ... on Human { name secretBackstory } ... on Droid { name primaryFunction } ... on Starship { name } } }""" case class Variables(text: String) object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(search: List[Search]) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } sealed trait Search { def __typename: String def name: Option[String] } object Search { case class Human(__typename: String, name: Option[String], secretBackstory: Option[String]) extends Search object Human { implicit val jsonDecoder: Decoder[Human] = deriveDecoder[Human] implicit val jsonEncoder: Encoder[Human] = deriveEncoder[Human] } case class Droid(__typename: String, name: Option[String], primaryFunction: Option[String]) extends Search object Droid { implicit val jsonDecoder: Decoder[Droid] = deriveDecoder[Droid] implicit val jsonEncoder: Encoder[Droid] = deriveEncoder[Droid] } case class Starship(__typename: String, name: Option[String]) extends Search object Starship { implicit val jsonDecoder: Decoder[Starship] = deriveDecoder[Starship] implicit val jsonEncoder: Encoder[Starship] = deriveEncoder[Starship] } implicit val jsonDecoder: Decoder[Search] = for (typeDiscriminator <- Decoder[String].prepare(_.downField("__typename")); value <- typeDiscriminator match { case "Human" => Decoder[Human] case "Droid" => Decoder[Droid] case "Starship" => Decoder[Starship] case other => Decoder.failedWithMessage("invalid type: " + other) }) yield value } } }
Example 74
Source File: InputVariables.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object InputVariables { object InputVariables extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query InputVariables($$humanId: String!) { human(id: $$humanId) { name homePlanet } }""" case class Variables(humanId: String) object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(human: Option[Human]) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Human(name: Option[String], homePlanet: Option[String]) object Human { implicit val jsonDecoder: Decoder[Human] = deriveDecoder[Human] implicit val jsonEncoder: Encoder[Human] = deriveEncoder[Human] } } }
Example 75
Source File: HeroAndFriends.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object HeroAndFriends { object HeroAndFriends extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query HeroAndFriends { hero { name friends { name friends { name friends { name friends { name } } } } } }""" case class Variables() object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(hero: Hero) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Hero(name: Option[String], friends: Option[List[Option[Hero.Friends]]]) object Hero { implicit val jsonDecoder: Decoder[Hero] = deriveDecoder[Hero] implicit val jsonEncoder: Encoder[Hero] = deriveEncoder[Hero] case class Friends(name: Option[String], friends: Option[List[Option[Friends.Friends]]]) object Friends { implicit val jsonDecoder: Decoder[Friends] = deriveDecoder[Friends] implicit val jsonEncoder: Encoder[Friends] = deriveEncoder[Friends] case class Friends(name: Option[String], friends: Option[List[Option[Friends.Friends]]]) object Friends { implicit val jsonDecoder: Decoder[Friends] = deriveDecoder[Friends] implicit val jsonEncoder: Encoder[Friends] = deriveEncoder[Friends] case class Friends(name: Option[String], friends: Option[List[Option[Friends.Friends]]]) object Friends { implicit val jsonDecoder: Decoder[Friends] = deriveDecoder[Friends] implicit val jsonEncoder: Encoder[Friends] = deriveEncoder[Friends] case class Friends(name: Option[String]) object Friends { implicit val jsonDecoder: Decoder[Friends] = deriveDecoder[Friends] implicit val jsonEncoder: Encoder[Friends] = deriveEncoder[Friends] } } } } } } }