Branch: master
Clone or download
pepegar 🎉 use @deriveTraverse annotation in our ADTs (#27)
* 🎉 use @deriveTraverse annotation in our ADTs

This means that we don't need to derive the functor ourselves

* add law tests for MuF

* add law checks for avro schema

* add law checking for protobuf schema

* juggle with dependencies to avoid bincompat error in scalacheck

There is a binary incompatibility in scalacheck from 1.14.0 to
1.13.5.

* fix version of specs2 to 4.1.0

We need to stay there because otherwise there is a binary
compatibility error between 1.14.0 & 1.13.5

* adjustments after rebase

* avoid trailing comma

* only include scalacheck in test profile
Latest commit 270afc8 Dec 20, 2018

README.md

Build Status codecov.io Maven Central Latest version License Join the chat at https://gitter.im/higherkindness/skeuomorph GitHub Issues

Skeuomorph

Skeuomorph is a library for transforming different schemas in Scala. It provides schema definitions as non-recursive ADTs, and transformations & optimizations via recursion schemes.

This library is primarily intended to be used at mu, but it's completely independent from it, so anybody can use it.

Skeuomorph depends heavily on cats and droste.

Schemas

Currently skeuomorph supports 3 different schemas:

And provides conversions between them. This means that you can get a org.apache.avro.Schema value, and convert it to protobuf, for example. Or to a mu service description.

Installation

You can install skeuomorph as follows:

libraryDependencies += "io.higherkindness" %% "skeuomorph" % "0.0.3"

Examples

parsing an avro schema and then converting it to scala:

import org.apache.avro._
import higherkindness.skeuomorph.mu.Transform.transformAvro
import higherkindness.skeuomorph.mu.MuF
import higherkindness.skeuomorph.mu.print
import higherkindness.skeuomorph.avro.AvroF.fromAvro
import qq.droste._
import qq.droste.data._
import qq.droste.data.Mu._
import cats.implicits._


val definition = """
{
  "namespace": "example.avro",
  "type": "record",
  "name": "User",
  "fields": [
    {
      "name": "name",
      "type": "string"
    },
    {
      "name": "favorite_number",
      "type": [
        "int",
        "null"
      ]
    },
    {
      "name": "favorite_color",
      "type": [
        "string",
        "null"
      ]
    }
  ]
}
  """

val avroSchema: Schema = new Schema.Parser().parse(definition)

val parseAvro: Schema => Mu[MuF] =
  scheme.hylo(transformAvro[Mu[MuF]].algebra, fromAvro)
val printAsScala: Mu[MuF] => String = 
  print.schema.print _
(parseAvro >>> println)(avroSchema)
(printAsScala >>> println)(parseAvro(avroSchema))
Mu(TProduct(User,List(Field(name,Mu(TString())), Field(favorite_number,Mu(TCoproduct(NonEmptyList(Mu(TInt()), Mu(TNull()))))), Field(favorite_color,Mu(TCoproduct(NonEmptyList(Mu(TString()), Mu(TNull()))))))))
@message final case class User(name: String, favorite_number: Cop[Int :: Null:: TNil], favorite_color: Cop[String :: Null:: TNil])

Skeuomorph in the wild

If you wish to add your library here please consider a PR to include it in the list below.

Name Description
mu purely functional library for building RPC endpoint based services with support for RPC and HTTP/2

Copyright

Skeuomorph is designed and developed by 47 Degrees

Copyright (C) 2018 47 Degrees. http://47deg.com