Skip to content

Commit

Permalink
Schema for test case
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Mar 30, 2019
1 parent 95b96af commit e6966c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait SchemaForMagnoliaDerivation {
}

def dispatch[T](ctx: SealedTrait[SchemaFor, T]): SchemaFor[T] = {
throw new RuntimeException("Sealed trait hierarchies are not yet supported")
throw new RuntimeException(s"Sealed trait hierarchies are not yet supported for: ${ctx.typeName}")
}

implicit def schemaForCaseClass[T]: SchemaFor[T] = macro Magnolia.gen[T]
Expand Down
15 changes: 12 additions & 3 deletions core/src/test/scala/tapir/generic/SchemaForTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.concurrent.{Await, Future}

class SchemaForTest extends FlatSpec with Matchers {

it should "find schema for simple types" in {
"SchemaFor" should "find schema for simple types" in {
implicitly[SchemaFor[String]].schema shouldBe SString
implicitly[SchemaFor[String]].isOptional shouldBe false

Expand Down Expand Up @@ -55,9 +55,9 @@ class SchemaForTest extends FlatSpec with Matchers {
}

it should "find schema for a simple case class and use snake case naming transformation" in {
val expectedSnakCaseNaming = expectedDSchema.copy(fields = List(("some_field_name", SString)), required = List("some_field_name"))
val expectedSnakeCaseNaming = expectedDSchema.copy(fields = List(("some_field_name", SString)), required = List("some_field_name"))
implicit val customConf = Configuration.default.withSnakeCaseMemberNames
implicitly[SchemaFor[D]].schema shouldBe expectedSnakCaseNaming
implicitly[SchemaFor[D]].schema shouldBe expectedSnakeCaseNaming
}

it should "find schema for a simple case class and use kebab case naming transformation" in {
Expand Down Expand Up @@ -101,10 +101,19 @@ class SchemaForTest extends FlatSpec with Matchers {
val schemas = Await.result(eventualSchemas, 5 seconds)
schemas should contain only expected
}

it should "use custom schema for custom types" in {
implicit val scustom: SchemaFor[Custom] = SchemaFor[Custom](Schema.SString)
val schema = implicitly[SchemaFor[G]].schema
schema shouldBe SObject(SObjectInfo("G", "tapir.generic.G"), List(("f1", SInteger), ("f2", SString)), List("f1", "f2"))
}
}

case class A(f1: String, f2: Int, f3: Option[String])
case class B(g1: String, g2: A)
case class C(h1: List[String], h2: Option[Int])
case class D(someFieldName: String)
case class F(f1: List[F], f2: Int)

class Custom(c: String)
case class G(f1: Int, f2: Custom)

0 comments on commit e6966c2

Please sign in to comment.